diff options
author | unknown <tsmith@siva.hindu.god> | 2007-03-23 17:48:03 -0600 |
---|---|---|
committer | unknown <tsmith@siva.hindu.god> | 2007-03-23 17:48:03 -0600 |
commit | f48f4f1efb3ddb441dbb06f6f0d5c72c3cb7881f (patch) | |
tree | 9f87aa9e4a9ff0b87fbd824715ac574410c05162 /sql/spatial.h | |
parent | dea1ffda10aa23c5931ddf928959bd80b5ac6434 (diff) | |
parent | eee28a267d658376f349bb54c7481e05f10c0eda (diff) | |
download | mariadb-git-f48f4f1efb3ddb441dbb06f6f0d5c72c3cb7881f.tar.gz |
Merge siva.hindu.god:/home/tsmith/m/bk/maint/bmisc/50
into siva.hindu.god:/home/tsmith/m/bk/maint/bmisc/51
mysql-test/include/gis_generic.inc:
Auto merged
mysql-test/r/archive_gis.result:
Auto merged
BitKeeper/deleted/.del-bdb_gis.result:
Auto merged
mysql-test/r/ndb_gis.result:
Auto merged
sql/spatial.h:
Auto merged
mysql-test/r/gis.result:
Manual merge
mysql-test/r/innodb_gis.result:
Manual merge
mysql-test/t/gis.test:
Manual merge
Diffstat (limited to 'sql/spatial.h')
-rw-r--r-- | sql/spatial.h | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/sql/spatial.h b/sql/spatial.h index 0c0452b5abc..f806861290e 100644 --- a/sql/spatial.h +++ b/sql/spatial.h @@ -144,15 +144,46 @@ struct MBR return (xmin<x) && (xmax>x) && (ymin<y) && (ymax>y); } + /** + The dimension maps to an integer as: + - Polygon -> 2 + - Horizontal or vertical line -> 1 + - Point -> 0 + - Invalid MBR -> -1 + */ + int dimension() const + { + int d= 0; + + if (xmin > xmax) + return -1; + else if (xmin < xmax) + d++; + + if (ymin > ymax) + return -1; + else if (ymin < ymax) + d++; + + return d; + } + int overlaps(const MBR *mbr) { - int lb= mbr->inner_point(xmin, ymin); - int rb= mbr->inner_point(xmax, ymin); - int rt= mbr->inner_point(xmax, ymax); - int lt= mbr->inner_point(xmin, ymax); + /* + overlaps() requires that some point inside *this is also inside + *mbr, and that both geometries and their intersection are of the + same dimension. + */ + int d = dimension(); + + if (d != mbr->dimension() || d <= 0 || contains(mbr) || within(mbr)) + return 0; + + MBR intersection(max(xmin, mbr->xmin), max(ymin, mbr->ymin), + min(xmax, mbr->xmax), min(ymax, mbr->ymax)); - int a = lb+rb+rt+lt; - return (a>0) && (a<4) && (!within(mbr)); + return (d == intersection.dimension()); } }; |