** Does shape1 intersect shape2, returns MS_TRUE/MS_FALSE or -1 for an error. */
| 1029 | ** Does shape1 intersect shape2, returns MS_TRUE/MS_FALSE or -1 for an error. |
| 1030 | */ |
| 1031 | int msGEOSIntersects(shapeObj *shape1, shapeObj *shape2) |
| 1032 | { |
| 1033 | #ifdef USE_GEOS |
| 1034 | GEOSGeom g1, g2; |
| 1035 | int result; |
| 1036 | |
| 1037 | if(!shape1 || !shape2) |
| 1038 | return -1; |
| 1039 | |
| 1040 | if(!shape1->geometry) /* if no geometry for shape1 then build one */ |
| 1041 | shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); |
| 1042 | g1 = (GEOSGeom) shape1->geometry; |
| 1043 | if(!g1) return -1; |
| 1044 | |
| 1045 | if(!shape2->geometry) /* if no geometry for shape2 then build one */ |
| 1046 | shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); |
| 1047 | g2 = (GEOSGeom) shape2->geometry; |
| 1048 | if(!g2) return -1; |
| 1049 | |
| 1050 | result = GEOSIntersects(g1, g2); |
| 1051 | return ((result==2) ? -1 : result); |
| 1052 | #else |
| 1053 | if(!shape1 || !shape2) |
| 1054 | return -1; |
| 1055 | |
| 1056 | switch(shape1->type) { /* todo: deal with point shapes */ |
| 1057 | case(MS_SHAPE_LINE): |
| 1058 | switch(shape2->type) { |
| 1059 | case(MS_SHAPE_LINE): |
| 1060 | return msIntersectPolylines(shape1, shape2); |
| 1061 | case(MS_SHAPE_POLYGON): |
| 1062 | return msIntersectPolylinePolygon(shape1, shape2); |
| 1063 | } |
| 1064 | break; |
| 1065 | case(MS_SHAPE_POLYGON): |
| 1066 | switch(shape2->type) { |
| 1067 | case(MS_SHAPE_LINE): |
| 1068 | return msIntersectPolylinePolygon(shape2, shape1); |
| 1069 | case(MS_SHAPE_POLYGON): |
| 1070 | return msIntersectPolygons(shape1, shape2); |
| 1071 | } |
| 1072 | break; |
| 1073 | } |
| 1074 | |
| 1075 | return -1; |
| 1076 | #endif |
| 1077 | } |
| 1078 | |
| 1079 | /* |
| 1080 | ** Does shape1 touch shape2, returns MS_TRUE/MS_FALSE or -1 for an error. |
no test coverage detected