One last memory leak fix.
[geos.git] / source / geom / prep / PreparedPolygonContainsProperly.cpp
blobbc84f410146b1634eff8a4eef4e1320ba203ae3f
1 /**********************************************************************
2 * $Id$
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
7 * Copyright (C) 2001-2002 Vivid Solutions Inc.
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
14 **********************************************************************/
17 #include <geos/geom/Geometry.h>
18 #include <geos/geom/Polygon.h>
19 #include <geos/geom/MultiPolygon.h>
20 #include <geos/geom/prep/PreparedPolygon.h>
21 #include <geos/geom/prep/PreparedPolygonContainsProperly.h>
22 #include <geos/geom/prep/PreparedPolygonPredicate.h>
23 #include <geos/noding/SegmentString.h>
24 #include <geos/noding/SegmentStringUtil.h>
25 #include <geos/noding/FastSegmentSetIntersectionFinder.h>
27 namespace geos {
28 namespace geom { // geos.geom
29 namespace prep { // geos.geom.prep
31 // private:
35 // protected:
39 // public:
41 bool
42 PreparedPolygonContainsProperly::containsProperly( const geom::Geometry * geom)
44 // Do point-in-poly tests first, since they are cheaper and may result
45 // in a quick negative result.
46 // If a point of any test components does not lie in target, result is false
47 bool isAllInPrepGeomArea = isAllTestComponentsInTargetInterior( geom);
48 if ( !isAllInPrepGeomArea )
49 return false;
51 // If any segments intersect, result is false
52 noding::SegmentString::ConstVect lineSegStr;
53 noding::SegmentStringUtil::extractSegmentStrings( geom, lineSegStr);
54 bool segsIntersect = prepPoly->getIntersectionFinder()->intersects( &lineSegStr);
56 for ( size_t i = 0, ni = lineSegStr.size(); i < ni; i++ ) {
57 delete lineSegStr[ i ];
58 delete lineSegStr[ i ]->getCoordinates();
61 if (segsIntersect)
62 return false;
64 if ( geom->getGeometryTypeId() == geos::geom::GEOS_MULTIPOLYGON
65 || geom->getGeometryTypeId() == geos::geom::GEOS_POLYGON )
67 // TODO: generalize this to handle GeometryCollections
68 bool isTargetGeomInTestArea = isAnyTargetComponentInTestArea( geom, prepPoly->getRepresentativePoints());
69 if (isTargetGeomInTestArea)
70 return false;
73 return true;
76 } // namespace geos.geom.prep
77 } // namespace geos.geom
78 } // namespace geos
80 /**********************************************************************
81 * $Log$
83 **********************************************************************/