[geos-commits] r2194 - in trunk/source: geom/prep
headers/geos/geom/prep headers/geos/index
headers/geos/index/chain headers/geos/index/strtree
headers/geos/noding index/chain index/strtree
svn_geos at osgeo.org
svn_geos at osgeo.org
Tue Sep 23 19:01:00 EDT 2008
Author: mloskot
Date: 2008-09-23 19:01:00 -0400 (Tue, 23 Sep 2008)
New Revision: 2194
Modified:
trunk/source/geom/prep/AbstractPreparedPolygonContains.cpp
trunk/source/geom/prep/PreparedPolygon.cpp
trunk/source/geom/prep/PreparedPolygonContains.cpp
trunk/source/geom/prep/PreparedPolygonPredicate.cpp
trunk/source/headers/geos/geom/prep/PreparedPolygonContains.h
trunk/source/headers/geos/index/SpatialIndex.h
trunk/source/headers/geos/index/chain/MonotoneChain.h
trunk/source/headers/geos/index/strtree/ItemBoundable.h
trunk/source/headers/geos/noding/MCIndexSegmentSetMutualIntersector.h
trunk/source/headers/geos/noding/SegmentSetMutualIntersector.h
trunk/source/index/chain/MonotoneChain.cpp
trunk/source/index/chain/MonotoneChainBuilder.cpp
trunk/source/index/strtree/AbstractSTRtree.cpp
trunk/source/index/strtree/ItemBoundable.cpp
Log:
Moved some ctor/dctor bodies from headers to translation units. Improved source code readability. TODO: We need to run a beast like AStyle on all GEOS code because many places are very hard to read.
Modified: trunk/source/geom/prep/AbstractPreparedPolygonContains.cpp
===================================================================
--- trunk/source/geom/prep/AbstractPreparedPolygonContains.cpp 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/geom/prep/AbstractPreparedPolygonContains.cpp 2008-09-23 23:01:00 UTC (rev 2194)
@@ -13,7 +13,6 @@
*
**********************************************************************/
-
#include <geos/geom/prep/AbstractPreparedPolygonContains.h>
#include <geos/geom/prep/PreparedPolygon.h>
#include <geos/geom/Geometry.h>
@@ -24,6 +23,8 @@
#include <geos/noding/SegmentIntersectionDetector.h>
#include <geos/noding/FastSegmentSetIntersectionFinder.h>
#include <geos/algorithm/LineIntersector.h>
+// std
+#include <cstddef>
namespace geos {
namespace geom { // geos::geom
@@ -56,34 +57,37 @@
bool
-AbstractPreparedPolygonContains::isSingleShell( const geom::Geometry & geom)
+AbstractPreparedPolygonContains::isSingleShell(const geom::Geometry& geom)
{
// handles single-element MultiPolygons, as well as Polygons
- if ( geom.getNumGeometries() != 1)
+ if (geom.getNumGeometries() != 1)
+ {
return false;
+ }
- const geom::Polygon * poly = (Polygon *)geom.getGeometryN( 0);
+ const geom::Geometry* g = geom.getGeometryN(0);
+ const geom::Polygon* poly = static_cast<const Polygon*>(g);
- int numHoles = poly->getNumInteriorRing();
- return (numHoles == 0);
+ std::size_t numHoles = poly->getNumInteriorRing();
+ return (0 == numHoles);
}
void
-AbstractPreparedPolygonContains::findAndClassifyIntersections( const geom::Geometry * geom)
+AbstractPreparedPolygonContains::findAndClassifyIntersections(const geom::Geometry* geom)
{
noding::SegmentString::ConstVect lineSegStr;
- noding::SegmentStringUtil::extractSegmentStrings( geom, lineSegStr);
+ noding::SegmentStringUtil::extractSegmentStrings(geom, lineSegStr);
- algorithm::LineIntersector * li;
+ algorithm::LineIntersector* li = 0;
li = new algorithm::LineIntersector();
- noding::SegmentIntersectionDetector * intDetector;
- intDetector = new noding::SegmentIntersectionDetector( li);
+ noding::SegmentIntersectionDetector* intDetector = 0;
+ intDetector = new noding::SegmentIntersectionDetector(li);
intDetector->setFindAllIntersectionTypes( true);
- prepPoly->getIntersectionFinder()->intersects( &lineSegStr, intDetector);
+ prepPoly->getIntersectionFinder()->intersects(&lineSegStr, intDetector);
hasSegmentIntersection = intDetector->hasIntersection();
hasProperIntersection = intDetector->hasProperIntersection();
@@ -91,10 +95,10 @@
delete intDetector;
delete li;
- for ( size_t i = 0, ni = lineSegStr.size(); i < ni; i++ )
+ for (std::size_t i = 0, ni = lineSegStr.size(); i < ni; i++ )
{
- delete lineSegStr[ i ]->getCoordinates();
- delete lineSegStr[ i ];
+ delete lineSegStr[i]->getCoordinates();
+ delete lineSegStr[i];
}
}
Modified: trunk/source/geom/prep/PreparedPolygon.cpp
===================================================================
--- trunk/source/geom/prep/PreparedPolygon.cpp 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/geom/prep/PreparedPolygon.cpp 2008-09-23 23:01:00 UTC (rev 2194)
@@ -13,22 +13,21 @@
*
**********************************************************************/
-
#include <geos/geom/Polygon.h>
-
#include <geos/geom/prep/PreparedPolygon.h>
#include <geos/geom/prep/PreparedPolygonContains.h>
#include <geos/geom/prep/PreparedPolygonContainsProperly.h>
#include <geos/geom/prep/PreparedPolygonCovers.h>
#include <geos/geom/prep/PreparedPolygonIntersects.h>
#include <geos/geom/prep/PreparedPolygonPredicate.h>
-
#include <geos/noding/FastSegmentSetIntersectionFinder.h>
#include <geos/noding/SegmentStringUtil.h>
#include <geos/operation/predicate/RectangleContains.h>
#include <geos/operation/predicate/RectangleIntersects.h>
#include <geos/algorithm/locate/PointOnGeometryLocator.h>
#include <geos/algorithm/locate/IndexedPointInAreaLocator.h>
+// std
+#include <cstddef>
namespace geos {
namespace geom { // geos.geom
@@ -36,22 +35,18 @@
//
// public:
//
-PreparedPolygon::
-PreparedPolygon( const geom::Geometry * geom)
-: BasicPreparedGeometry( geom),
- segIntFinder( NULL),
- ptOnGeomLoc( NULL)
+PreparedPolygon::PreparedPolygon(const geom::Geometry * geom)
+ : BasicPreparedGeometry(geom), segIntFinder(0), ptOnGeomLoc(0)
{
isRectangle = getGeometry().isRectangle();
}
-PreparedPolygon::
-~PreparedPolygon( )
+PreparedPolygon::~PreparedPolygon()
{
delete segIntFinder;
delete ptOnGeomLoc;
- for ( size_t i = 0, ni = segStrings.size(); i < ni; i++ )
+ for ( std::size_t i = 0, ni = segStrings.size(); i < ni; i++ )
{
delete segStrings[ i ]->getCoordinates();
delete segStrings[ i ];
Modified: trunk/source/geom/prep/PreparedPolygonContains.cpp
===================================================================
--- trunk/source/geom/prep/PreparedPolygonContains.cpp 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/geom/prep/PreparedPolygonContains.cpp 2008-09-23 23:01:00 UTC (rev 2194)
@@ -21,9 +21,14 @@
namespace geos {
namespace geom { // geos.geom
namespace prep { // geos.geom.prep
+
//
-// private:
+// public:
//
+PreparedPolygonContains::PreparedPolygonContains(const PreparedPolygon * const prepPoly)
+ : AbstractPreparedPolygonContains( prepPoly)
+{
+}
//
// protected:
@@ -36,7 +41,7 @@
}
//
-// public:
+// private:
//
} // namespace geos.geom.prep
} // namespace geos.geom
Modified: trunk/source/geom/prep/PreparedPolygonPredicate.cpp
===================================================================
--- trunk/source/geom/prep/PreparedPolygonPredicate.cpp 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/geom/prep/PreparedPolygonPredicate.cpp 2008-09-23 23:01:00 UTC (rev 2194)
@@ -13,7 +13,6 @@
*
**********************************************************************/
-
#include <geos/geom/prep/PreparedPolygonPredicate.h>
#include <geos/geom/prep/PreparedPolygon.h>
#include <geos/geom/Coordinate.h>
@@ -21,6 +20,8 @@
#include <geos/geom/Location.h>
#include <geos/algorithm/locate/PointOnGeometryLocator.h>
#include <geos/algorithm/locate/SimplePointInAreaLocator.h>
+// std
+#include <cstddef>
namespace geos {
namespace geom { // geos.geom
@@ -33,84 +34,98 @@
// protected:
//
bool
-PreparedPolygonPredicate::isAllTestComponentsInTargetArea( const geom::Geometry * testGeom)
+PreparedPolygonPredicate::isAllTestComponentsInTargetArea(const geom::Geometry* testGeom)
{
- geom::Coordinate::ConstVect pts;
- geom::util::ComponentCoordinateExtracter::getCoordinates( *testGeom, pts);
+ geom::Coordinate::ConstVect pts;
+ geom::util::ComponentCoordinateExtracter::getCoordinates(*testGeom, pts);
- for ( size_t i = 0, ni = pts.size(); i < ni; i++ )
- {
- const geom::Coordinate * pt = pts[ i ];
- int loc = prepPoly->getPointLocator()->locate( pt );
- if ( loc == geom::Location::EXTERIOR )
- return false;
- }
- return true;
+ for (std::size_t i = 0, ni = pts.size(); i < ni; i++)
+ {
+ const geom::Coordinate* pt = pts[i];
+ const int loc = prepPoly->getPointLocator()->locate(pt);
+ if (geom::Location::EXTERIOR == loc)
+ {
+ return false;
+ }
+ }
+ return true;
}
bool
-PreparedPolygonPredicate::isAllTestComponentsInTargetInterior( const geom::Geometry * testGeom)
+PreparedPolygonPredicate::isAllTestComponentsInTargetInterior(const geom::Geometry* testGeom)
{
- geom::Coordinate::ConstVect pts;
- geom::util::ComponentCoordinateExtracter::getCoordinates( *testGeom, pts);
+ geom::Coordinate::ConstVect pts;
+ geom::util::ComponentCoordinateExtracter::getCoordinates(*testGeom, pts);
- for ( size_t i = 0, ni = pts.size(); i < ni; i++ )
- {
- const geom::Coordinate * pt = pts[ i ];
- int loc = prepPoly->getPointLocator()->locate( pt );
- if ( loc != geom::Location::INTERIOR )
- return false;
- }
- return true;
+ for (std::size_t i = 0, ni = pts.size(); i < ni; i++)
+ {
+ const geom::Coordinate * pt = pts[i];
+ const int loc = prepPoly->getPointLocator()->locate(pt);
+ if (geom::Location::INTERIOR != loc)
+ {
+ return false;
+ }
+ }
+ return true;
}
bool
-PreparedPolygonPredicate::isAnyTestComponentInTargetArea( const geom::Geometry * testGeom)
+PreparedPolygonPredicate::isAnyTestComponentInTargetArea(const geom::Geometry* testGeom)
{
- geom::Coordinate::ConstVect pts;
- geom::util::ComponentCoordinateExtracter::getCoordinates( *testGeom, pts);
+ geom::Coordinate::ConstVect pts;
+ geom::util::ComponentCoordinateExtracter::getCoordinates(*testGeom, pts);
- for ( size_t i = 0, ni = pts.size(); i < ni; i++ )
- {
- const Coordinate * pt = pts[ i ];
- int loc = prepPoly->getPointLocator()->locate( pt );
- if ( loc != geom::Location::EXTERIOR )
- return true;
- }
- return false;
+ for (std::size_t i = 0, ni = pts.size(); i < ni; i++)
+ {
+ const Coordinate* pt = pts[i];
+ const int loc = prepPoly->getPointLocator()->locate(pt);
+ if (geom::Location::EXTERIOR != loc)
+ {
+ return true;
+ }
+ }
+ return false;
}
bool
PreparedPolygonPredicate::isAnyTestComponentInTargetInterior( const geom::Geometry * testGeom)
{
- geom::Coordinate::ConstVect pts;
- geom::util::ComponentCoordinateExtracter::getCoordinates( *testGeom, pts);
+ geom::Coordinate::ConstVect pts;
+ geom::util::ComponentCoordinateExtracter::getCoordinates(*testGeom, pts);
- for ( size_t i = 0, ni = pts.size(); i < ni; i++ )
- {
- const Coordinate * pt = pts[ i ];
- int loc = prepPoly->getPointLocator()->locate( pt );
- if ( loc == geom::Location::INTERIOR)
- return true;
- }
- return false;
+ for (std::size_t i = 0, ni = pts.size(); i < ni; i++)
+ {
+ const Coordinate * pt = pts[i];
+ const int loc = prepPoly->getPointLocator()->locate(pt);
+ if (geom::Location::INTERIOR == loc)
+ {
+ return true;
+ }
+ }
+ return false;
}
-
bool
-PreparedPolygonPredicate::isAnyTargetComponentInTestArea( const geom::Geometry * testGeom, const geom::Coordinate::ConstVect * targetRepPts)
+PreparedPolygonPredicate::isAnyTargetComponentInTestArea(const geom::Geometry* testGeom,
+ const geom::Coordinate::ConstVect* targetRepPts)
{
- algorithm::locate::PointOnGeometryLocator * piaLoc;
- piaLoc = new algorithm::locate::SimplePointInAreaLocator( testGeom);
+ // TODO - mloskot: Replace manual delete with scoped_ptr
+ algorithm::locate::PointOnGeometryLocator* piaLoc = 0;
+ piaLoc = new algorithm::locate::SimplePointInAreaLocator(testGeom);
- for ( size_t i = 0, ni = targetRepPts->size(); i < ni; i++ )
- {
- const geom::Coordinate * pt = (*targetRepPts)[ i ];
- int loc = piaLoc->locate( pt);
- if ( loc != geom::Location::EXTERIOR )
- return true;
- }
- return false;
+ for (std::size_t i = 0, ni = targetRepPts->size(); i < ni; i++)
+ {
+ const geom::Coordinate * pt = (*targetRepPts)[i];
+ const int loc = piaLoc->locate(pt);
+ if (geom::Location::EXTERIOR != loc)
+ {
+ delete piaLoc;
+ return true;
+ }
+ }
+
+ delete piaLoc;
+ return false;
}
//
Modified: trunk/source/headers/geos/geom/prep/PreparedPolygonContains.h
===================================================================
--- trunk/source/headers/geos/geom/prep/PreparedPolygonContains.h 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/headers/geos/geom/prep/PreparedPolygonContains.h 2008-09-23 23:01:00 UTC (rev 2194)
@@ -50,52 +50,50 @@
*/
class PreparedPolygonContains : public AbstractPreparedPolygonContains
{
-private:
-protected:
- /**
- * Computes the full topological <tt>contains</tt> predicate.
- * Used when short-circuit tests are not conclusive.
- *
- * @param geom the test geometry
- * @return true if this prepared polygon contains the test geometry
- */
- bool fullTopologicalPredicate( const geom::Geometry * geom);
-
public:
- /**
- * Computes the </tt>contains</tt> predicate between a {@link PreparedPolygon}
- * and a {@link Geometry}.
- *
- * @param prep the prepared polygon
- * @param geom a test geometry
- * @return true if the polygon contains the geometry
- */
- static bool contains( const PreparedPolygon * const prep, const geom::Geometry * geom)
- {
- PreparedPolygonContains polyInt( prep);
- return polyInt.contains( geom);
- }
/**
* Creates an instance of this operation.
*
* @param prepPoly the PreparedPolygon to evaluate
*/
- PreparedPolygonContains( const PreparedPolygon * const prepPoly)
- : AbstractPreparedPolygonContains( prepPoly)
- { }
-
+ PreparedPolygonContains(const PreparedPolygon * const prepPoly);
+
/**
* Tests whether this PreparedPolygon <tt>contains</tt> a given geometry.
*
* @param geom the test geometry
* @return true if the test geometry is contained
*/
- bool contains( const geom::Geometry * geom)
+ bool contains(const geom::Geometry * geom)
{
- return eval( geom);
+ return eval(geom);
}
-
+
+ /**
+ * Computes the </tt>contains</tt> predicate between a {@link PreparedPolygon}
+ * and a {@link Geometry}.
+ *
+ * @param prep the prepared polygon
+ * @param geom a test geometry
+ * @return true if the polygon contains the geometry
+ */
+ static bool contains(const PreparedPolygon * const prep, const geom::Geometry * geom)
+ {
+ PreparedPolygonContains polyInt(prep);
+ return polyInt.contains(geom);
+ }
+
+protected:
+ /**
+ * Computes the full topological <tt>contains</tt> predicate.
+ * Used when short-circuit tests are not conclusive.
+ *
+ * @param geom the test geometry
+ * @return true if this prepared polygon contains the test geometry
+ */
+ bool fullTopologicalPredicate(const geom::Geometry * geom);
+
};
} // geos::geom::prep
Modified: trunk/source/headers/geos/index/SpatialIndex.h
===================================================================
--- trunk/source/headers/geos/index/SpatialIndex.h 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/headers/geos/index/SpatialIndex.h 2008-09-23 23:01:00 UTC (rev 2194)
@@ -32,8 +32,8 @@
namespace index {
/** \brief
- * The basic insertion and query operations supported by classes
- * implementing spatial index algorithms.
+ * Abstract class defines basic insertion and query operations supported by
+ * classes implementing spatial index algorithms.
*
* A spatial index typically provides a primary filter for range rectangle queries. A
* secondary filter is required to test for exact intersection. Of course, this
@@ -45,13 +45,14 @@
*/
class SpatialIndex {
public:
- virtual ~SpatialIndex() {};
+
+ virtual ~SpatialIndex() {}
/** \brief
* Adds a spatial item with an extent specified by the given Envelope
* to the index
*/
- virtual void insert(const geom::Envelope *itemEnv, void *item)=0;
+ virtual void insert(const geom::Envelope *itemEnv, void *item) = 0;
/** \brief
* Queries the index for all items whose extents intersect the given search Envelope
@@ -63,7 +64,7 @@
* @return a list of the items found by the query in a newly allocated vector
*/
//virtual std::vector<void*>* query(const geom::Envelope *searchEnv)=0;
- virtual void query(const geom::Envelope* searchEnv, std::vector<void*>&)=0;
+ virtual void query(const geom::Envelope* searchEnv, std::vector<void*>&) = 0;
/** \brief
* Queries the index for all items whose extents intersect the given search Envelope
@@ -75,7 +76,7 @@
* @param searchEnv the envelope to query for
* @param visitor a visitor object to apply to the items found
*/
- virtual void query(const geom::Envelope *searchEnv, ItemVisitor& visitor)=0;
+ virtual void query(const geom::Envelope *searchEnv, ItemVisitor& visitor) = 0;
/** \brief
* Removes a single item from the tree.
@@ -84,9 +85,8 @@
* @param item the item to remove
* @return <code>true</code> if the item was found
*/
- virtual bool remove(const geom::Envelope* itemEnv, void* item)=0;
+ virtual bool remove(const geom::Envelope* itemEnv, void* item) = 0;
-
};
Modified: trunk/source/headers/geos/index/chain/MonotoneChain.h
===================================================================
--- trunk/source/headers/geos/index/chain/MonotoneChain.h 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/headers/geos/index/chain/MonotoneChain.h 2008-09-23 23:01:00 UTC (rev 2194)
@@ -76,46 +76,14 @@
*
* Last port: index/chain/MonotoneChain.java rev. 1.13 (JTS-1.7)
*/
-class MonotoneChain {
-
-private:
-
- void computeSelect(const geom::Envelope& searchEnv,
- unsigned int start0,
- unsigned int end0,
- MonotoneChainSelectAction& mcs);
-
- void computeOverlaps(int start0, int end0, MonotoneChain* mc,
- int start1, int end1, MonotoneChainOverlapAction* mco);
-
- const geom::CoordinateSequence* pts;
-
- int start, end;
-
- geom::Envelope* env;
-
- /// user-defined information
- void* context;
-
- /// useful for optimizing chain comparisons
- int id;
-
+class MonotoneChain
+{
public:
+
MonotoneChain(const geom::CoordinateSequence *newPts,
- int nstart, int nend,
- void* nContext)
- :
- pts(newPts),
- start(nstart),
- end(nend),
- env(NULL),
- context(nContext)
- {
- }
+ int nstart, int nend, void* nContext);
- ~MonotoneChain() {
- delete env;
- }
+ ~MonotoneChain();
geom::Envelope* getEnvelope();
@@ -147,6 +115,25 @@
void* getContext() { return context; }
+private:
+
+ void computeSelect(const geom::Envelope& searchEnv,
+ unsigned int start0,
+ unsigned int end0,
+ MonotoneChainSelectAction& mcs);
+
+ void computeOverlaps(int start0, int end0, MonotoneChain* mc,
+ int start1, int end1, MonotoneChainOverlapAction* mco);
+
+ const geom::CoordinateSequence* pts;
+ geom::Envelope* env;
+ /// user-defined information
+ void* context;
+ int start;
+ int end;
+ /// useful for optimizing chain comparisons
+ int id;
+
};
} // namespace geos::index::chain
Modified: trunk/source/headers/geos/index/strtree/ItemBoundable.h
===================================================================
--- trunk/source/headers/geos/index/strtree/ItemBoundable.h 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/headers/geos/index/strtree/ItemBoundable.h 2008-09-23 23:01:00 UTC (rev 2194)
@@ -12,7 +12,6 @@
* See the COPYING file for more information.
*
**********************************************************************/
-
#ifndef GEOS_INDEX_STRTREE_ITEMBOUNDABLE_H
#define GEOS_INDEX_STRTREE_ITEMBOUNDABLE_H
@@ -26,19 +25,25 @@
* \brief
* Boundable wrapper for a non-Boundable spatial object.
* Used internally by AbstractSTRtree.
+ *
+ * \todo TODO: It's unclear who takes ownership of passed newBounds and newItem objects.
*/
-class ItemBoundable: public Boundable {
+class ItemBoundable: public Boundable
+{
+public:
+
+ ItemBoundable(const void* newBounds, void* newItem);
+ virtual ~ItemBoundable();
+
+ const void* getBounds() const;
+ void* getItem() const;
+
private:
+
const void* bounds;
void* item;
-public:
- ItemBoundable(const void* newBounds, void* newItem);
- virtual ~ItemBoundable();
- const void* getBounds() const;
- void* getItem() const;
};
-
} // namespace geos::index::strtree
} // namespace geos::index
} // namespace geos
Modified: trunk/source/headers/geos/noding/MCIndexSegmentSetMutualIntersector.h
===================================================================
--- trunk/source/headers/geos/noding/MCIndexSegmentSetMutualIntersector.h 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/headers/geos/noding/MCIndexSegmentSetMutualIntersector.h 2008-09-23 23:01:00 UTC (rev 2194)
@@ -1,5 +1,5 @@
/**********************************************************************
- * $Id
+ * $Id$
*
* GEOS - Geometry Engine Open Source
* http://geos.refractions.net
@@ -50,58 +50,61 @@
*/
class MCIndexSegmentSetMutualIntersector : public SegmentSetMutualIntersector
{
-private:
- std::vector<index::chain::MonotoneChain *> * monoChains;
- /*
- * The {@link SpatialIndex} used should be something that supports
- * envelope (range) queries efficiently (such as a {@link Quadtree}
- * or {@link STRtree}.
- */
- index::SpatialIndex * index;
- int indexCounter;
- int processCounter;
- // statistics
- int nOverlaps;
+public:
- void addToIndex( SegmentString * segStr);
-
- void intersectChains();
-
- void addToMonoChains( SegmentString * segStr);
-
-protected:
-public:
MCIndexSegmentSetMutualIntersector();
~MCIndexSegmentSetMutualIntersector();
- std::vector<index::chain::MonotoneChain *> * getMonotoneChains()
+ std::vector<index::chain::MonotoneChain *>* getMonotoneChains()
{
return monoChains;
}
- index::SpatialIndex * getIndex()
+ index::SpatialIndex* getIndex()
{
return index;
}
- void setBaseSegments( SegmentString::ConstVect * segStrings);
+ void setBaseSegments(SegmentString::ConstVect* segStrings);
- void process( SegmentString::ConstVect * segStrings);
+ void process(SegmentString::ConstVect* segStrings);
-
class SegmentOverlapAction : public index::chain::MonotoneChainOverlapAction
{
private:
SegmentIntersector & si;
public:
- SegmentOverlapAction( SegmentIntersector & si) : si(si)
- { }
- void overlap( index::chain::MonotoneChain * mc1, int start1, index::chain::MonotoneChain * mc2, int start2);
+ SegmentOverlapAction(SegmentIntersector & si)
+ : si(si)
+ {}
+
+ void overlap(index::chain::MonotoneChain* mc1, int start1, index::chain::MonotoneChain* mc2, int start2);
};
+private:
+
+ std::vector<index::chain::MonotoneChain *> * monoChains;
+
+ /*
+ * The {@link SpatialIndex} used should be something that supports
+ * envelope (range) queries efficiently (such as a {@link Quadtree}
+ * or {@link STRtree}.
+ */
+ index::SpatialIndex * index;
+ int indexCounter;
+ int processCounter;
+ // statistics
+ int nOverlaps;
+
+ void addToIndex( SegmentString * segStr);
+
+ void intersectChains();
+
+ void addToMonoChains( SegmentString * segStr);
+
};
} // namespace geos::noding
Modified: trunk/source/headers/geos/noding/SegmentSetMutualIntersector.h
===================================================================
--- trunk/source/headers/geos/noding/SegmentSetMutualIntersector.h 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/headers/geos/noding/SegmentSetMutualIntersector.h 2008-09-23 23:01:00 UTC (rev 2194)
@@ -1,5 +1,5 @@
/**********************************************************************
- * $Id
+ * $Id$
*
* GEOS - Geometry Engine Open Source
* http://geos.refractions.net
@@ -37,17 +37,13 @@
*/
class SegmentSetMutualIntersector
{
-private:
-protected:
- SegmentIntersector * segInt;
-
public:
- SegmentSetMutualIntersector()
- : segInt( NULL)
- { }
+
+ SegmentSetMutualIntersector()
+ : segInt(0)
+ {}
- virtual ~SegmentSetMutualIntersector()
- { }
+ virtual ~SegmentSetMutualIntersector() {}
/**
* Sets the {@link SegmentIntersector} to use with this intersector.
@@ -56,7 +52,7 @@
*
* @param segInt the segment intersector to use
*/
- void setSegmentIntersector( SegmentIntersector * si)
+ void setSegmentIntersector(SegmentIntersector* si)
{
segInt = si;
}
@@ -65,15 +61,19 @@
*
* @param segStrings0 a collection of {@link SegmentString}s to node
*/
- virtual void setBaseSegments( SegmentString::ConstVect * segStrings) =0;
+ virtual void setBaseSegments(SegmentString::ConstVect* segStrings) = 0;
/**
* Computes the intersections for two collections of {@link SegmentString}s.
*
* @param segStrings1 a collection of {@link SegmentString}s to node
*/
- virtual void process( SegmentString::ConstVect * segStrings) =0;
+ virtual void process(SegmentString::ConstVect* segStrings) = 0;
+protected:
+
+ SegmentIntersector* segInt;
+
};
} // geos::noding
Modified: trunk/source/index/chain/MonotoneChain.cpp
===================================================================
--- trunk/source/index/chain/MonotoneChain.cpp 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/index/chain/MonotoneChain.cpp 2008-09-23 23:01:00 UTC (rev 2194)
@@ -31,116 +31,138 @@
namespace index { // geos.index
namespace chain { // geos.index.chain
+MonotoneChain::MonotoneChain(const geom::CoordinateSequence *newPts,
+ int nstart, int nend, void* nContext)
+: pts(newPts), env(0), context(nContext), start(nstart), end(nend), id(-1)
+{
+}
+
+MonotoneChain::~MonotoneChain()
+{
+ delete env;
+}
+
Envelope*
MonotoneChain::getEnvelope()
{
- if (env==NULL) {
- const Coordinate& p0=pts->getAt(start);
- const Coordinate& p1=pts->getAt(end);
- env=new Envelope(p0,p1);
- }
- return env;
+ if (0 == env)
+ {
+ const Coordinate& p0 = pts->getAt(start);
+ const Coordinate& p1 = pts->getAt(end);
+ env = new Envelope(p0, p1);
+ }
+ return env;
}
void
MonotoneChain::getLineSegment(unsigned int index, LineSegment *ls)
{
- ls->p0=pts->getAt(index);
- ls->p1=pts->getAt(index+1);
+ ls->p0=pts->getAt(index);
+ ls->p1=pts->getAt(index+1);
}
/**
- * Return the subsequence of coordinates forming this chain.
- * Allocates a new array to hold the Coordinates
- */
+* Return the subsequence of coordinates forming this chain.
+* Allocates a new array to hold the Coordinates
+*/
CoordinateSequence*
-MonotoneChain::getCoordinates() {
- return pts->clone();
+MonotoneChain::getCoordinates()
+{
+ return pts->clone();
}
void
MonotoneChain::select(const Envelope& searchEnv, MonotoneChainSelectAction& mcs)
{
- computeSelect(searchEnv,start,end,mcs);
+ computeSelect(searchEnv,start,end,mcs);
}
void
MonotoneChain::computeSelect(const Envelope& searchEnv,
- unsigned int start0, unsigned int end0,
- MonotoneChainSelectAction& mcs )
+ unsigned int start0, unsigned int end0,
+ MonotoneChainSelectAction& mcs )
{
- const Coordinate& p0=pts->getAt(start0);
- const Coordinate& p1=pts->getAt(end0);
- mcs.tempEnv1->init(p0,p1);
+ const Coordinate& p0=pts->getAt(start0);
+ const Coordinate& p1=pts->getAt(end0);
+ mcs.tempEnv1->init(p0,p1);
- //Debug.println("trying:"+p0+p1+" [ "+start0+","+end0+" ]");
- // terminating condition for the recursion
- if(end0-start0==1) {
- //Debug.println("computeSelect:"+p0+p1);
- mcs.select(*this,start0);
- return;
- }
- // nothing to do if the envelopes don't overlap
- if (!searchEnv.intersects(mcs.tempEnv1))
- return;
- // the chains overlap,so split each in half and iterate (binary search)
- unsigned int mid=(start0+end0)/2;
- // Assert: mid != start or end (since we checked above for end-start <= 1)
- // check terminating conditions before recursing
- if (start0<mid) {
- computeSelect(searchEnv,start0,mid,mcs);
- }
- if (mid<end0) {
- computeSelect(searchEnv,mid,end0,mcs);
- }
+ //Debug.println("trying:"+p0+p1+" [ "+start0+","+end0+" ]");
+ // terminating condition for the recursion
+ if(end0-start0==1)
+ {
+ //Debug.println("computeSelect:"+p0+p1);
+ mcs.select(*this,start0);
+ return;
+ }
+ // nothing to do if the envelopes don't overlap
+ if (!searchEnv.intersects(mcs.tempEnv1))
+ return;
+ // the chains overlap,so split each in half and iterate (binary search)
+ unsigned int mid=(start0+end0)/2;
+
+ // Assert: mid != start or end (since we checked above for end-start <= 1)
+ // check terminating conditions before recursing
+ if (start0 < mid)
+ {
+ computeSelect(searchEnv,start0,mid,mcs);
+ }
+
+ if (mid < end0)
+ {
+ computeSelect(searchEnv,mid,end0,mcs);
+ }
}
void
MonotoneChain::computeOverlaps(MonotoneChain *mc, MonotoneChainOverlapAction *mco)
{
- computeOverlaps(start,end,mc,mc->start,mc->end,mco);
+ computeOverlaps(start,end,mc,mc->start,mc->end,mco);
}
void
MonotoneChain::computeOverlaps(int start0, int end0, MonotoneChain *mc,
- int start1, int end1, MonotoneChainOverlapAction *mco)
+ int start1, int end1, MonotoneChainOverlapAction *mco)
{
- //Debug.println("computeIntersectsForChain:"+p00+p01+p10+p11);
- // terminating condition for the recursion
- if (end0-start0==1 && end1-start1==1) {
- mco->overlap(this,start0,mc,start1);
- return;
- }
+ //Debug.println("computeIntersectsForChain:"+p00+p01+p10+p11);
+ // terminating condition for the recursion
+ if (end0-start0==1 && end1-start1==1)
+ {
+ mco->overlap(this,start0,mc,start1);
+ return;
+ }
- const Coordinate& p00=pts->getAt(start0);
- const Coordinate& p01=pts->getAt(end0);
- const Coordinate& p10=mc->pts->getAt(start1);
- const Coordinate& p11=mc->pts->getAt(end1);
+ const Coordinate& p00=pts->getAt(start0);
+ const Coordinate& p01=pts->getAt(end0);
+ const Coordinate& p10=mc->pts->getAt(start1);
+ const Coordinate& p11=mc->pts->getAt(end1);
- // nothing to do if the envelopes of these chains don't overlap
- mco->tempEnv1->init(p00,p01);
- mco->tempEnv2->init(p10,p11);
- if (!mco->tempEnv1->intersects(mco->tempEnv2)) return;
+ // nothing to do if the envelopes of these chains don't overlap
+ mco->tempEnv1->init(p00,p01);
+ mco->tempEnv2->init(p10,p11);
+ if (!mco->tempEnv1->intersects(mco->tempEnv2)) return;
- // the chains overlap,so split each in half and iterate (binary search)
- int mid0=(start0+end0)/2;
- int mid1=(start1+end1)/2;
+ // the chains overlap,so split each in half and iterate (binary search)
+ int mid0=(start0+end0)/2;
+ int mid1=(start1+end1)/2;
- // Assert: mid != start or end (since we checked above for
- // end-start <= 1)
- // check terminating conditions before recursing
- if (start0<mid0) {
- if (start1<mid1)
- computeOverlaps(start0,mid0,mc,start1,mid1,mco);
- if (mid1<end1)
- computeOverlaps(start0,mid0,mc,mid1,end1,mco);
- }
- if (mid0<end0) {
- if (start1<mid1)
- computeOverlaps(mid0,end0,mc,start1,mid1,mco);
- if (mid1<end1)
- computeOverlaps(mid0,end0,mc,mid1,end1,mco);
- }
+ // Assert: mid != start or end (since we checked above for
+ // end-start <= 1)
+ // check terminating conditions before recursing
+ if (start0<mid0)
+ {
+ if (start1<mid1)
+ computeOverlaps(start0,mid0,mc,start1,mid1,mco);
+ if (mid1<end1)
+ computeOverlaps(start0,mid0,mc,mid1,end1,mco);
+ }
+
+ if (mid0<end0)
+ {
+ if (start1<mid1)
+ computeOverlaps(mid0,end0,mc,start1,mid1,mco);
+ if (mid1<end1)
+ computeOverlaps(mid0,end0,mc,mid1,end1,mco);
+ }
}
} // namespace geos.index.chain
Modified: trunk/source/index/chain/MonotoneChainBuilder.cpp
===================================================================
--- trunk/source/index/chain/MonotoneChainBuilder.cpp 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/index/chain/MonotoneChainBuilder.cpp 2008-09-23 23:01:00 UTC (rev 2194)
@@ -39,30 +39,27 @@
/* static public */
vector<MonotoneChain*>*
-MonotoneChainBuilder::getChains(const CoordinateSequence* pts,
- void* context)
+MonotoneChainBuilder::getChains(const CoordinateSequence* pts, void* context)
{
- vector<MonotoneChain*> *mcList=new vector<MonotoneChain*>();
+ vector<MonotoneChain*>* mcList = new vector<MonotoneChain*>();
getChains(pts, context, *mcList);
return mcList;
}
/* static public */
void
-MonotoneChainBuilder::getChains(const CoordinateSequence* pts,
- void* context,
- vector<MonotoneChain*>& mcList)
+MonotoneChainBuilder::getChains(const CoordinateSequence* pts, void* context,
+ vector<MonotoneChain*>& mcList)
{
vector<int> startIndex;
getChainStartIndices(pts, startIndex);
- size_t nindexes=startIndex.size();
- if ( nindexes )
+ size_t nindexes = startIndex.size();
+ if (nindexes > 0)
{
- size_t n=nindexes-1;
- for(size_t i=0; i<n; i++)
+ size_t n = nindexes - 1;
+ for(size_t i = 0; i < n; i++)
{
- MonotoneChain *mc=new MonotoneChain(pts,
- startIndex[i], startIndex[i+1], context);
+ MonotoneChain* mc = new MonotoneChain(pts, startIndex[i], startIndex[i+1], context);
mcList.push_back(mc);
}
}
@@ -76,17 +73,18 @@
*/
void
MonotoneChainBuilder::getChainStartIndices(const CoordinateSequence *pts,
- vector<int>& startIndexList)
+ vector<int>& startIndexList)
{
// find the startpoint (and endpoints) of all monotone chains
// in this edge
- int start=0;
+ int start = 0;
startIndexList.push_back(start);
- const std::size_t n=pts->getSize() - 1;
- do {
- int last=findChainEnd(pts, start);
+ const std::size_t n = pts->getSize() - 1;
+ do
+ {
+ int last = findChainEnd(pts, start);
startIndexList.push_back(last);
- start=last;
+ start = last;
} while (static_cast<std::size_t>(start) < n);
}
Modified: trunk/source/index/strtree/AbstractSTRtree.cpp
===================================================================
--- trunk/source/index/strtree/AbstractSTRtree.cpp 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/index/strtree/AbstractSTRtree.cpp 2008-09-23 23:01:00 UTC (rev 2194)
@@ -18,10 +18,11 @@
#include <geos/index/strtree/AbstractNode.h>
#include <geos/index/strtree/ItemBoundable.h>
#include <geos/index/ItemVisitor.h>
-
+// std
#include <algorithm>
#include <vector>
#include <typeinfo>
+#include <cstddef>
#include <cassert>
using namespace std;
@@ -33,20 +34,21 @@
AbstractSTRtree::~AbstractSTRtree()
{
- assert(itemBoundables);
-
- for (BoundableList::iterator i=itemBoundables->begin(),
- e=itemBoundables->end();
- i!=e;
- ++i)
+ assert(0 != itemBoundables);
+ BoundableList::iterator it = itemBoundables->begin();
+ BoundableList::iterator end = itemBoundables->end();
+ while (it != end)
{
- delete *i;
+ delete *it;
+ ++it;
}
delete itemBoundables;
- assert(nodes);
- for (size_t i=0, nsize=nodes->size(); i<nsize; i++)
+ assert(0 != nodes);
+ for (std::size_t i = 0, nsize = nodes->size(); i < nsize; i++)
+ {
delete (*nodes)[i];
+ }
delete nodes;
}
@@ -73,7 +75,7 @@
for (BoundableList::iterator i=sortedChildBoundables->begin(),
e=sortedChildBoundables->end();
i!=e; i++)
- //for(size_t i=0, scbsize=sortedChildBoundables->size(); i<scbsize; ++i)
+ //for(std::size_t i=0, scbsize=sortedChildBoundables->size(); i<scbsize; ++i)
{
Boundable *childBoundable=*i; // (*sortedChildBoundables)[i];
@@ -260,7 +262,7 @@
IntersectsOp *io=getIntersectsOp();
- //size_t vbsize=vb.size();
+ //std::size_t vbsize=vb.size();
//cerr<<"AbstractSTRtree::query: childBoundables: "<<vbsize<<endl;
for(BoundableList::const_iterator i=vb.begin(), e=vb.end();
i!=e; ++i)
@@ -339,7 +341,7 @@
/**********************************************************************
* $Log$
* Revision 1.30 2006/06/12 10:49:43 strk
- * unsigned int => size_t
+ * unsigned int => std::size_t
*
* Revision 1.29 2006/03/21 10:47:34 strk
* indexStrtree.h split
Modified: trunk/source/index/strtree/ItemBoundable.cpp
===================================================================
--- trunk/source/index/strtree/ItemBoundable.cpp 2008-09-23 22:55:53 UTC (rev 2193)
+++ trunk/source/index/strtree/ItemBoundable.cpp 2008-09-23 23:01:00 UTC (rev 2194)
@@ -20,12 +20,13 @@
namespace index { // geos.index
namespace strtree { // geos.index.strtree
-ItemBoundable::ItemBoundable(const void* newBounds,void* newItem){
- bounds=newBounds;
- item=newItem;
+ItemBoundable::ItemBoundable(const void* newBounds, void* newItem) :
+ bounds(newBounds), item(newItem)
+{
}
-ItemBoundable::~ItemBoundable() {
+ItemBoundable::~ItemBoundable()
+{
}
const void*
More information about the geos-commits
mailing list