[geos-commits] r2430 - in trunk/source: headers/geos/operation
operation
svn_geos at osgeo.org
svn_geos at osgeo.org
Thu Apr 30 06:46:09 EDT 2009
Author: strk
Date: 2009-04-30 06:46:09 -0400 (Thu, 30 Apr 2009)
New Revision: 2430
Removed:
trunk/source/headers/geos/operation/EndpointInfo.h
Modified:
trunk/source/headers/geos/operation/IsSimpleOp.h
trunk/source/headers/geos/operation/Makefile.am
trunk/source/operation/IsSimpleOp.cpp
Log:
Port revision 1.9 of IsSimplOp : allow inspecting non-simple location coordinate.
Deleted: trunk/source/headers/geos/operation/EndpointInfo.h
===================================================================
--- trunk/source/headers/geos/operation/EndpointInfo.h 2009-04-30 10:43:16 UTC (rev 2429)
+++ trunk/source/headers/geos/operation/EndpointInfo.h 2009-04-30 10:46:09 UTC (rev 2430)
@@ -1,46 +0,0 @@
-/**********************************************************************
- * $Id$
- *
- * GEOS - Geometry Engine Open Source
- * http://geos.refractions.net
- *
- * Copyright (C) 2005-2006 Refractions Research Inc.
- * Copyright (C) 2001-2002 Vivid Solutions Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU Lesser General Public Licence as published
- * by the Free Software Foundation.
- * See the COPYING file for more information.
- *
- **********************************************************************/
-
-#ifndef GEOS_OPERATION_ENDPOINTINFO_H
-#define GEOS_OPERATION_ENDPOINTINFO_H
-
-#include <geos/geom/Coordinate.h> // for composition
-
-namespace geos {
-namespace operation { // geos.operation
-
-
-class EndpointInfo{
-public:
- geom::Coordinate pt;
- bool isClosed;
- int degree;
- EndpointInfo(const geom::Coordinate& newPt);
- void addEndpoint(bool newIsClosed);
-};
-
-} // namespace geos.operation
-} // namespace geos
-
-#endif
-
-/**********************************************************************
- * $Log$
- * Revision 1.1 2006/03/09 16:46:49 strk
- * geos::geom namespace definition, first pass at headers split
- *
- **********************************************************************/
-
Modified: trunk/source/headers/geos/operation/IsSimpleOp.h
===================================================================
--- trunk/source/headers/geos/operation/IsSimpleOp.h 2009-04-30 10:43:16 UTC (rev 2429)
+++ trunk/source/headers/geos/operation/IsSimpleOp.h 2009-04-30 10:46:09 UTC (rev 2430)
@@ -15,14 +15,17 @@
*
**********************************************************************
*
- * Last port: operation/IsSimpleOp.java rev. 1.18
+ * Last port: operation/IsSimpleOp.java rev. 1.19
*
**********************************************************************/
#ifndef GEOS_OPERATION_ISSIMPLEOP_H
#define GEOS_OPERATION_ISSIMPLEOP_H
+#include <geos/geom/Coordinate.h> // for dtor visibility by auto_ptr (compos)
+
#include <map>
+#include <memory> // for auto_ptr
// Forward declarations
namespace geos {
@@ -34,7 +37,6 @@
class MultiLineString;
class MultiPoint;
class Geometry;
- class Coordinate;
struct CoordinateLessThen;
}
namespace geomgraph {
@@ -90,20 +92,59 @@
/** \brief
* Creates a simplicity checker using the default
* SFS Mod-2 Boundary Node Rule
+ *
+ * @deprecated use IsSimpleOp(Geometry)
*/
IsSimpleOp();
/** \brief
+ * Creates a simplicity checker using the default
+ * SFS Mod-2 Boundary Node Rule
+ *
+ * @param geom The geometry to test.
+ * Will store a reference: keep it alive.
+ */
+ IsSimpleOp(const geom::Geometry& geom);
+
+ /** \brief
* Creates a simplicity checker using a given
* algorithm::BoundaryNodeRule
+ *
+ * @param geom the geometry to test
+ * @param boundaryNodeRule the rule to use.
*/
- IsSimpleOp(const algorithm::BoundaryNodeRule& boundaryNodeRule);
+ IsSimpleOp(const geom::Geometry& geom,
+ const algorithm::BoundaryNodeRule& boundaryNodeRule);
/**
+ * Tests whether the geometry is simple.
+ *
+ * @return true if the geometry is simple
+ */
+ bool isSimple();
+
+ /**
+ * Gets a coordinate for the location where the geometry
+ * fails to be simple.
+ * (i.e. where it has a non-boundary self-intersection).
+ * {@link #isSimple} must be called before this method is called.
+ *
+ * @return a coordinate for the location of the non-boundary
+ * self-intersection. Ownership retained.
+ * @return the null coordinate if the geometry is simple
+ */
+ const geom::Coordinate* getNonSimpleLocation() const
+ {
+ return nonSimpleLocation.get();
+ }
+
+ /**
* Reports whether a geom::LineString is simple.
*
* @param geom the lineal geometry to test
* @return true if the geometry is simple
+ *
+ * @deprecated use isSimple()
*/
bool isSimple(const geom::LineString *geom);
@@ -112,11 +153,15 @@
*
* @param geom the lineal geometry to test
* @return true if the geometry is simple
+ *
+ * @deprecated use isSimple()
*/
bool isSimple(const geom::MultiLineString *geom);
/**
* A MultiPoint is simple iff it has no repeated points
+ *
+ * @deprecated use isSimple()
*/
bool isSimple(const geom::MultiPoint *mp);
@@ -150,6 +195,12 @@
const geom::Coordinate *p, bool isClosed);
bool isClosedEndpointsInInterior;
+
+ bool isSimpleMultiPoint(const geom::MultiPoint& mp);
+
+ const geom::Geometry* geom;
+
+ std::auto_ptr<geom::Coordinate> nonSimpleLocation;
};
} // namespace geos.operation
Modified: trunk/source/headers/geos/operation/Makefile.am
===================================================================
--- trunk/source/headers/geos/operation/Makefile.am 2009-04-30 10:43:16 UTC (rev 2429)
+++ trunk/source/headers/geos/operation/Makefile.am 2009-04-30 10:46:09 UTC (rev 2430)
@@ -17,7 +17,6 @@
geosdir = $(includedir)/geos/operation
geos_HEADERS = \
- EndpointInfo.h \
GeometryGraphOperation.h \
IsSimpleOp.h
Modified: trunk/source/operation/IsSimpleOp.cpp
===================================================================
--- trunk/source/operation/IsSimpleOp.cpp 2009-04-30 10:43:16 UTC (rev 2429)
+++ trunk/source/operation/IsSimpleOp.cpp 2009-04-30 10:46:09 UTC (rev 2430)
@@ -15,12 +15,12 @@
*
**********************************************************************
*
- * Last port: operation/IsSimpleOp.java rev. 1.18
+ * Last port: operation/IsSimpleOp.java rev. 1.19
*
**********************************************************************/
#include <geos/operation/IsSimpleOp.h>
-#include <geos/operation/EndpointInfo.h>
+//#include <geos/operation/EndpointInfo.h>
#include <geos/algorithm/BoundaryNodeRule.h>
#include <geos/algorithm/LineIntersector.h>
#include <geos/geomgraph/GeometryGraph.h>
@@ -45,20 +45,86 @@
namespace geos {
namespace operation { // geos.operation
+// This is supposedly a private of IsSimpleOp...
+class EndpointInfo
+{
+public:
+
+ Coordinate pt;
+
+ bool isClosed;
+
+ int degree;
+
+ EndpointInfo(const geom::Coordinate& newPt);
+
+ const Coordinate& getCoordinate() const { return pt; }
+
+ void addEndpoint(bool newIsClosed)
+ {
+ degree++;
+ isClosed |= newIsClosed;
+ }
+};
+
+EndpointInfo::EndpointInfo(const Coordinate& newPt)
+{
+ pt=newPt;
+ isClosed=false;
+ degree=0;
+}
+
+// -----------------------------------------------------
+
+
+
/*public*/
IsSimpleOp::IsSimpleOp()
:
- isClosedEndpointsInInterior(true)
+ isClosedEndpointsInInterior(true),
+ geom(0),
+ nonSimpleLocation()
{}
/*public*/
-IsSimpleOp::IsSimpleOp(const algorithm::BoundaryNodeRule& boundaryNodeRule)
+IsSimpleOp::IsSimpleOp(const Geometry& g)
:
- isClosedEndpointsInInterior( ! boundaryNodeRule.isInBoundary(2) )
+ isClosedEndpointsInInterior(true),
+ geom(&g),
+ nonSimpleLocation()
{}
/*public*/
+IsSimpleOp::IsSimpleOp(const Geometry& g,
+ const BoundaryNodeRule& boundaryNodeRule)
+ :
+ isClosedEndpointsInInterior( ! boundaryNodeRule.isInBoundary(2) ),
+ geom(&g),
+ nonSimpleLocation()
+{}
+
+/*public*/
bool
+IsSimpleOp::isSimple()
+{
+ nonSimpleLocation.reset();
+
+ if ( dynamic_cast<const LineString*>(geom) )
+ return isSimpleLinearGeometry(geom);
+
+ if ( dynamic_cast<const MultiLineString*>(geom) )
+ return isSimpleLinearGeometry(geom);
+
+ const MultiPoint* mp = dynamic_cast<const MultiPoint*>(geom);
+ if ( mp ) return isSimpleMultiPoint(*mp);
+
+ // all other geometry types are simple by definition
+ return true;
+}
+
+
+/*public*/
+bool
IsSimpleOp::isSimple(const LineString *geom)
{
return isSimpleLinearGeometry(geom);
@@ -75,15 +141,24 @@
bool
IsSimpleOp::isSimple(const MultiPoint *mp)
{
- if (mp->isEmpty()) return true;
+ return isSimpleMultiPoint(*mp);
+}
+
+/*private*/
+bool
+IsSimpleOp::isSimpleMultiPoint(const MultiPoint& mp)
+{
+ if (mp.isEmpty()) return true;
set<const Coordinate*, CoordinateLessThen> points;
- for (std::size_t i=0, n=mp->getNumGeometries(); i<n; i++)
+ for (std::size_t i=0, n=mp.getNumGeometries(); i<n; ++i)
{
- assert(dynamic_cast<const Point*>(mp->getGeometryN(i)));
- const Point *pt=static_cast<const Point*>(mp->getGeometryN(i));
+ assert(dynamic_cast<const Point*>(mp.getGeometryN(i)));
+ const Point *pt=static_cast<const Point*>(mp.getGeometryN(i));
const Coordinate *p=pt->getCoordinate();
- if (points.find(p) != points.end()) {
+ if (points.find(p) != points.end())
+ {
+ nonSimpleLocation.reset(new Coordinate(*p));
return false;
}
points.insert(p);
@@ -102,7 +177,13 @@
// if no self-intersection, must be simple
if (!si->hasIntersection()) return true;
- if (si->hasProperIntersection()) return false;
+ if (si->hasProperIntersection())
+ {
+ nonSimpleLocation.reset(
+ new Coordinate(si->getProperIntersectionPoint())
+ );
+ return false;
+ }
if (hasNonEndpointIntersection(graph)) return false;
@@ -127,7 +208,12 @@
{
EdgeIntersection *ei=*eiIt;
if (!ei->isEndPoint(maxSegmentIndex))
+ {
+ nonSimpleLocation.reset(
+ new Coordinate(ei->getCoordinate())
+ );
return true;
+ }
}
}
return false;
@@ -158,6 +244,9 @@
EndpointInfo *ep=it->second;
delete ep;
}
+ nonSimpleLocation.reset(
+ new Coordinate( eiInfo->getCoordinate() )
+ );
return true;
}
}
@@ -190,20 +279,6 @@
eiInfo->addEndpoint(isClosed);
}
-EndpointInfo::EndpointInfo(const Coordinate& newPt)
-{
- pt=newPt;
- isClosed=false;
- degree=0;
-}
-
-void
-EndpointInfo::addEndpoint(bool newIsClosed)
-{
- degree++;
- isClosed|=newIsClosed;
-}
-
} // namespace geos::operation
} // namespace geos
More information about the geos-commits
mailing list