/src/geos/src/geom/prep/PreparedPolygonContainsProperly.cpp
Line | Count | Source (jump to first uncovered line) |
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/PreparedPolygonContainsProperly.java rev 1.5 (JTS-1.10) |
16 | | * (2007-12-12) |
17 | | * |
18 | | **********************************************************************/ |
19 | | |
20 | | |
21 | | #include <geos/geom/Geometry.h> |
22 | | #include <geos/geom/Polygon.h> |
23 | | #include <geos/geom/MultiPolygon.h> |
24 | | #include <geos/geom/prep/PreparedPolygon.h> |
25 | | #include <geos/geom/prep/PreparedPolygonContainsProperly.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 | | PreparedPolygonContainsProperly::containsProperly(const geom::Geometry* geom) |
47 | 0 | { |
48 | | // Do point-in-poly tests first, since they are cheaper and may result |
49 | | // in a quick negative result. |
50 | | // If a point of any test components does not lie in target, |
51 | | // result is false |
52 | 0 | bool isAllInPrepGeomArea = isAllTestComponentsInTargetInterior(geom); |
53 | 0 | if(!isAllInPrepGeomArea) { |
54 | 0 | return false; |
55 | 0 | } |
56 | | |
57 | | // If any segments intersect, result is false |
58 | 0 | noding::SegmentString::ConstVect lineSegStr; |
59 | 0 | noding::SegmentStringUtil::extractSegmentStrings(geom, lineSegStr); |
60 | 0 | bool segsIntersect = prepPoly->getIntersectionFinder()->intersects(&lineSegStr); |
61 | |
|
62 | 0 | for(std::size_t i = 0, ni = lineSegStr.size(); i < ni; i++) { |
63 | 0 | delete lineSegStr[ i ]; |
64 | 0 | } |
65 | |
|
66 | 0 | if(segsIntersect) { |
67 | 0 | return false; |
68 | 0 | } |
69 | | |
70 | | /* |
71 | | * Given that no segments intersect, if any vertex of the target |
72 | | * is contained in some test component. |
73 | | * the test is NOT properly contained. |
74 | | */ |
75 | 0 | if(geom->getGeometryTypeId() == geos::geom::GEOS_MULTIPOLYGON |
76 | 0 | || geom->getGeometryTypeId() == geos::geom::GEOS_POLYGON) { |
77 | | // TODO: generalize this to handle GeometryCollections |
78 | 0 | bool isTargetGeomInTestArea = isAnyTargetComponentInAreaTest(geom, prepPoly->getRepresentativePoints()); |
79 | 0 | if(isTargetGeomInTestArea) { |
80 | 0 | return false; |
81 | 0 | } |
82 | 0 | } |
83 | | |
84 | 0 | return true; |
85 | 0 | } |
86 | | |
87 | | } // namespace geos.geom.prep |
88 | | } // namespace geos.geom |
89 | | } // namespace geos |