/src/geos/src/geom/prep/PreparedPolygonIntersects.cpp
Line | Count | Source |
1 | | /********************************************************************** |
2 | | * |
3 | | * GEOS - Geometry Engine Open Source |
4 | | * http://geos.osgeo.org |
5 | | * |
6 | | * Copyright (C) 2001-2002 Vivid Solutions Inc. |
7 | | * |
8 | | * This is free software; you can redistribute and/or modify it under |
9 | | * the terms of the GNU Lesser General Public Licence as published |
10 | | * by the Free Software Foundation. |
11 | | * See the COPYING file for more information. |
12 | | * |
13 | | ********************************************************************** |
14 | | * |
15 | | * Last port: geom/prep/PreparedPolygonIntersects.java rev 1.6 (JTS-1.10) |
16 | | * (2007-12-12) |
17 | | * |
18 | | **********************************************************************/ |
19 | | |
20 | | |
21 | | #include <geos/geom/prep/PreparedPolygonIntersects.h> |
22 | | #include <geos/geom/prep/PreparedPolygon.h> |
23 | | #include <geos/geom/Geometry.h> |
24 | | #include <geos/geom/Polygon.h> |
25 | | #include <geos/geom/MultiPolygon.h> |
26 | | #include <geos/geom/prep/PreparedPolygonPredicate.h> |
27 | | #include <geos/noding/SegmentString.h> |
28 | | #include <geos/noding/SegmentStringUtil.h> |
29 | | #include <geos/noding/FastSegmentSetIntersectionFinder.h> |
30 | | |
31 | | namespace geos { |
32 | | namespace geom { // geos::geom |
33 | | namespace prep { // geos::geom::prep |
34 | | // |
35 | | // private: |
36 | | // |
37 | | |
38 | | // |
39 | | // protected: |
40 | | // |
41 | | |
42 | | // |
43 | | // public: |
44 | | // |
45 | | bool |
46 | | PreparedPolygonIntersects::intersects(const geom::Geometry* geom) |
47 | 0 | { |
48 | | // Do point-in-poly tests first, since they are cheaper and may result |
49 | | // in a quick positive result. |
50 | | // If a point of any test components lie in target, result is true |
51 | 0 | bool isInPrepGeomArea = isAnyTestComponentInTarget(geom); |
52 | 0 | if(isInPrepGeomArea) { |
53 | 0 | return true; |
54 | 0 | } |
55 | | |
56 | 0 | if(geom->isPuntal()) { |
57 | | // point-in-poly failed, no way there can be an intersection |
58 | | // (NOTE: isAnyTestComponentInTarget also checks for boundary) |
59 | 0 | return false; |
60 | 0 | } |
61 | | |
62 | | // If any segments intersect, result is true |
63 | 0 | noding::SegmentString::ConstVect lineSegStr; |
64 | 0 | noding::SegmentStringUtil::extractSegmentStrings(geom, lineSegStr); |
65 | 0 | bool segsIntersect = prepPoly->getIntersectionFinder()->intersects(&lineSegStr); |
66 | |
|
67 | 0 | for(std::size_t i = 0, ni = lineSegStr.size(); i < ni; i++) { |
68 | 0 | delete lineSegStr[ i ]; |
69 | 0 | } |
70 | |
|
71 | 0 | if(segsIntersect) { |
72 | 0 | return true; |
73 | 0 | } |
74 | | |
75 | | // If the test has dimension = 2 as well, it is necessary to |
76 | | // test for proper inclusion of the target. |
77 | | // Since no segments intersect, it is sufficient to test representative points. |
78 | 0 | if(geom->getDimension() == 2) { |
79 | | // TODO: generalize this to handle GeometryCollections |
80 | 0 | bool isPrepGeomInArea = isAnyTargetComponentInAreaTest(geom, prepPoly->getRepresentativePoints()); |
81 | 0 | if(isPrepGeomInArea) { |
82 | 0 | return true; |
83 | 0 | } |
84 | 0 | } |
85 | | |
86 | 0 | return false; |
87 | 0 | } |
88 | | |
89 | | } // geos::geom::prep |
90 | | } // geos::geom |
91 | | } // geos |