[geos-commits] r2319 - in trunk: source/geomgraph
source/headers/geos/geomgraph source/headers/geos/noding
source/headers/geos/noding/snapround
source/headers/geos/operation/buffer source/noding
source/noding/snapround source/operation/buffer tests/unit
tests/unit/noding
svn_geos at osgeo.org
svn_geos at osgeo.org
Tue Apr 7 15:00:36 EDT 2009
Author: strk
Date: 2009-04-07 15:00:36 -0400 (Tue, 07 Apr 2009)
New Revision: 2319
Added:
trunk/source/headers/geos/noding/BasicSegmentString.h
trunk/source/noding/BasicSegmentString.cpp
trunk/tests/unit/noding/BasicSegmentStringTest.cpp
trunk/tests/unit/noding/NodedSegmentStringTest.cpp
Removed:
trunk/tests/unit/noding/SegmentStringTest.cpp
Modified:
trunk/source/geomgraph/EdgeNodingValidator.cpp
trunk/source/headers/geos/geomgraph/EdgeNodingValidator.h
trunk/source/headers/geos/noding/IntersectionAdder.h
trunk/source/headers/geos/noding/IntersectionFinderAdder.h
trunk/source/headers/geos/noding/IteratedNoder.h
trunk/source/headers/geos/noding/MCIndexNoder.h
trunk/source/headers/geos/noding/MCIndexNoder.inl
trunk/source/headers/geos/noding/Makefile.am
trunk/source/headers/geos/noding/NodableSegmentString.h
trunk/source/headers/geos/noding/NodedSegmentString.h
trunk/source/headers/geos/noding/SegmentNodeList.h
trunk/source/headers/geos/noding/SegmentString.h
trunk/source/headers/geos/noding/SegmentString.inl
trunk/source/headers/geos/noding/SimpleNoder.h
trunk/source/headers/geos/noding/snapround/MCIndexPointSnapper.h
trunk/source/headers/geos/noding/snapround/MCIndexSnapRounder.h
trunk/source/headers/geos/noding/snapround/MCIndexSnapRounder.inl
trunk/source/headers/geos/noding/snapround/SimpleSnapRounder.h
trunk/source/headers/geos/operation/buffer/OffsetCurveSetBuilder.h
trunk/source/noding/IntersectionAdder.cpp
trunk/source/noding/IntersectionFinderAdder.cpp
trunk/source/noding/IteratedNoder.cpp
trunk/source/noding/MCIndexNoder.cpp
trunk/source/noding/Makefile.am
trunk/source/noding/NodedSegmentString.cpp
trunk/source/noding/ScaledNoder.cpp
trunk/source/noding/SegmentNodeList.cpp
trunk/source/noding/SegmentString.cpp
trunk/source/noding/SimpleNoder.cpp
trunk/source/noding/snapround/MCIndexPointSnapper.cpp
trunk/source/noding/snapround/MCIndexSnapRounder.cpp
trunk/source/noding/snapround/SimpleSnapRounder.cpp
trunk/source/operation/buffer/OffsetCurveSetBuilder.cpp
trunk/tests/unit/Makefile.am
trunk/tests/unit/noding/SegmentNodeTest.cpp
Log:
Refactor SegmentString to be an abstract class, to be in sync with JTS-1.9.
Modified: trunk/source/geomgraph/EdgeNodingValidator.cpp
===================================================================
--- trunk/source/geomgraph/EdgeNodingValidator.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/geomgraph/EdgeNodingValidator.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -14,13 +14,15 @@
*
**********************************************************************
*
+ * Last port: geomgraph/EdgeNodingValidator.java rev. 1.6 (JTS-1.9)
+ *
**********************************************************************/
#include <vector>
#include <geos/geomgraph/EdgeNodingValidator.h>
#include <geos/geomgraph/Edge.h>
-#include <geos/noding/SegmentString.h>
+#include <geos/noding/BasicSegmentString.h>
#include <geos/geom/CoordinateSequence.h>
using namespace std;
@@ -38,7 +40,7 @@
Edge *e=edges[i];
CoordinateSequence* cs=e->getCoordinates()->clone();
newCoordSeq.push_back(cs);
- segStr.push_back(new SegmentString(cs, e));
+ segStr.push_back(new BasicSegmentString(cs, e));
}
return segStr;
}
Modified: trunk/source/headers/geos/geomgraph/EdgeNodingValidator.h
===================================================================
--- trunk/source/headers/geos/geomgraph/EdgeNodingValidator.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/geomgraph/EdgeNodingValidator.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -12,6 +12,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: geomgraph/EdgeNodingValidator.java rev. 1.6 (JTS-1.9)
+ *
**********************************************************************/
Added: trunk/source/headers/geos/noding/BasicSegmentString.h
===================================================================
--- trunk/source/headers/geos/noding/BasicSegmentString.h (rev 0)
+++ trunk/source/headers/geos/noding/BasicSegmentString.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -0,0 +1,111 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2009 Sandro Santilli <strk at keybit.net>
+ *
+ * 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.
+ *
+ **********************************************************************
+ *
+ * Last port: noding/BasicSegmentString.java rev. 1.1 (JTS-1.9)
+ *
+ **********************************************************************/
+
+#ifndef GEOS_NODING_BASICSEGMENTSTRING_H
+#define GEOS_NODING_BASICSEGMENTSTRING_H
+
+#include <geos/noding/SegmentString.h> // for inheritance
+#include <geos/geom/CoordinateSequence.h> // for inlines (size())
+
+#include <geos/inline.h>
+
+#include <vector>
+
+// Forward declarations
+namespace geos {
+ namespace algorithm {
+ //class LineIntersector;
+ }
+}
+
+namespace geos {
+namespace noding { // geos.noding
+
+/**
+ * Represents a list of contiguous line segments,
+ * and supports noding the segments.
+ * The line segments are represented by an array of {@link Coordinate}s.
+ * Intended to optimize the noding of contiguous segments by
+ * reducing the number of allocated objects.
+ * SegmentStrings can carry a context object, which is useful
+ * for preserving topological or parentage information.
+ * All noded substrings are initialized with the same context object.
+ */
+class BasicSegmentString : public SegmentString {
+
+public:
+
+ /// Construct a BasicSegmentString.
+ //
+ /// @param newPts CoordinateSequence representing the string,
+ /// externally owned
+ /// @param newContext the context associated to this SegmentString
+ ///
+ BasicSegmentString(geom::CoordinateSequence *newPts,
+ const void* newContext)
+ :
+ SegmentString(newContext),
+ pts(newPts)
+ {}
+
+ virtual ~BasicSegmentString()
+ {}
+
+ /// see dox in SegmentString.h
+ virtual unsigned int size() const
+ {
+ return pts->size();
+ }
+
+ /// see dox in SegmentString.h
+ virtual const geom::Coordinate& getCoordinate(unsigned int i) const;
+
+ /// see dox in SegmentString.h
+ virtual geom::CoordinateSequence* getCoordinates() const;
+
+ /// see dox in SegmentString.h
+ virtual bool isClosed() const;
+
+ /// see dox in SegmentString.h
+ virtual std::ostream& print(std::ostream& os) const;
+
+ /** \brief
+ * Gets the octant of the segment starting at vertex index.
+ *
+ * @param index the index of the vertex starting the segment.
+ * Must not be the last index in the vertex list
+ * @return the octant of the segment at the vertex
+ */
+ int getSegmentOctant(unsigned int index) const;
+
+private:
+
+ geom::CoordinateSequence *pts;
+
+};
+
+} // namespace geos.noding
+} // namespace geos
+
+#ifdef GEOS_INLINE
+# include "geos/noding/SegmentString.inl"
+#endif
+
+#endif // ndef GEOS_NODING_BASICSEGMENTSTRING_H
+
Modified: trunk/source/headers/geos/noding/IntersectionAdder.h
===================================================================
--- trunk/source/headers/geos/noding/IntersectionAdder.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/IntersectionAdder.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/IntersectionAdder.java rev. 1.6 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODING_INTERSECTIONADDER_H
@@ -49,8 +53,6 @@
* detects that two SegmentStrings <i>might</i> intersect.
* This class is an example of the <i>Strategy</i> pattern.
*
- * Last port: noding/IntersectionAdder.java rev. 1.4 (JTS-1.7)
- *
*/
class IntersectionAdder: public SegmentIntersector {
@@ -160,6 +162,14 @@
return std::abs(i1 - i2) == 1;
}
+ /**
+ * Always process all intersections
+ *
+ * @return false always
+ */
+ virtual bool isDone() const {
+ return false;
+ }
};
Modified: trunk/source/headers/geos/noding/IntersectionFinderAdder.h
===================================================================
--- trunk/source/headers/geos/noding/IntersectionFinderAdder.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/IntersectionFinderAdder.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/IntersectionFinderAdder.java rev. 1.5 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODING_INTERSECTIONFINDERADDER_H
@@ -44,8 +48,6 @@
* Finds proper and interior intersections in a set of SegmentStrings,
* and adds them as nodes.
*
- * Last port: noding/IntersectionFinderAdder.java rev. 1.2 (JTS-1.7)
- *
*/
class IntersectionFinderAdder: public SegmentIntersector {
@@ -87,6 +89,14 @@
return interiorIntersections;
}
+ /**
+ * Always process all intersections
+ *
+ * @return false always
+ */
+ virtual bool isDone() const {
+ return false;
+ }
};
} // namespace geos.noding
Modified: trunk/source/headers/geos/noding/IteratedNoder.h
===================================================================
--- trunk/source/headers/geos/noding/IteratedNoder.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/IteratedNoder.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/IteratedNoder.java rev. 1.6 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODING_ITERATEDNODER_H
@@ -45,7 +49,6 @@
* due to roundoff error. This problem is detected and an exception is thrown.
* Clients can choose to rerun the noding using a lower precision model.
*
- * Last port: noding/IteratedNoder.java rev. 1.6 (JTS-1.7)
*/
class IteratedNoder : public Noder { // implements Noder
@@ -89,7 +92,7 @@
void setMaximumIterations(int n) { maxIter = n; }
std::vector<SegmentString*>* getNodedSubstrings() const {
- return SegmentString::getNodedSubstrings(*nodedSegStrings);
+ return nodedSegStrings;
}
Modified: trunk/source/headers/geos/noding/MCIndexNoder.h
===================================================================
--- trunk/source/headers/geos/noding/MCIndexNoder.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/MCIndexNoder.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/MCIndexNoder.java rev. 1.6 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODING_MCINDEXNODER_H
Modified: trunk/source/headers/geos/noding/MCIndexNoder.inl
===================================================================
--- trunk/source/headers/geos/noding/MCIndexNoder.inl 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/MCIndexNoder.inl 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/MCIndexNoder.java rev. 1.6 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODINGMCINDEXNODER_INL
@@ -18,6 +22,7 @@
#include <geos/noding/MCIndexNoder.h>
#include <geos/noding/SegmentString.h>
+#include <geos/noding/NodedSegmentString.h>
#include <cassert>
@@ -34,7 +39,7 @@
MCIndexNoder::getNodedSubstrings() const
{
assert(nodedSegStrings); // must have colled computeNodes before!
- return SegmentString::getNodedSubstrings(*nodedSegStrings);
+ return NodedSegmentString::getNodedSubstrings(*nodedSegStrings);
}
} // namespace geos::noding
Modified: trunk/source/headers/geos/noding/Makefile.am
===================================================================
--- trunk/source/headers/geos/noding/Makefile.am 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/Makefile.am 2009-04-07 19:00:36 UTC (rev 2319)
@@ -6,6 +6,7 @@
#
noinst_HEADERS = \
+ BasicSegmentString.h \
FastNodingValidator.h \
FastSegmentSetIntersectionFinder.h \
IntersectionAdder.h \
Modified: trunk/source/headers/geos/noding/NodableSegmentString.h
===================================================================
--- trunk/source/headers/geos/noding/NodableSegmentString.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/NodableSegmentString.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -39,8 +39,9 @@
private:
protected:
public:
- NodableSegmentString( geom::CoordinateSequence *newPts, const void* newContext)
- : SegmentString( newPts, newContext )
+ NodableSegmentString(const void* newContext)
+ :
+ SegmentString( newContext )
{ }
/**
Modified: trunk/source/headers/geos/noding/NodedSegmentString.h
===================================================================
--- trunk/source/headers/geos/noding/NodedSegmentString.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/NodedSegmentString.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -12,11 +12,16 @@
* See the COPYING file for more information.
*
*
+ **********************************************************************
+ *
+ * Last port: noding/NodedSegmentString.java rev. 1.2 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODING_NODEDSEGMENTSTRING_H
#define GEOS_NODING_NODEDSEGMENTSTRING_H
+#include <geos/geom/CoordinateSequence.h> // for inlines
#include <geos/algorithm/LineIntersector.h>
#include <geos/noding/NodableSegmentString.h>
#include <geos/noding/SegmentNode.h>
@@ -41,14 +46,13 @@
* for preserving topological or parentage information.
* All noded substrings are initialized with the same context object.
*
- * @version 1.7
*/
class NodedSegmentString : public NodableSegmentString
{
-private:
-protected:
public:
- static void getNodedSubstrings( SegmentString::ConstVect * segStrings, SegmentString::NonConstVect * resultEdgelist)
+
+ static void getNodedSubstrings(SegmentString::ConstVect* segStrings,
+ SegmentString::NonConstVect* resultEdgelist)
{
for (size_t i=0, n=segStrings->size(); i<n; i++)
{
@@ -57,14 +61,30 @@
}
}
+ static void getNodedSubstrings(
+ const SegmentString::NonConstVect& segStrings,
+ SegmentString::NonConstVect* resultEdgeList);
+
+ /// Returns allocated object
+ static SegmentString::NonConstVect* getNodedSubstrings(
+ const SegmentString::NonConstVect& segStrings);
+
+
/**
* Creates a new segment string from a list of vertices.
*
- * @param pts the vertices of the segment string
- * @param data the user-defined data of this segment string (may be null)
+ * @param newPts CoordinateSequence representing the string,
+ * externally owned
+ *
+ * @param data the user-defined data of this segment string
+ * (may be null)
*/
- NodedSegmentString( geom::CoordinateSequence *newPts, const void* newContext)
- : NodableSegmentString( newPts, newContext )
+ NodedSegmentString(geom::CoordinateSequence *newPts,
+ const void* newContext)
+ :
+ NodableSegmentString(newContext),
+ nodeList(this),
+ pts(newPts)
{ }
~NodedSegmentString()
@@ -102,6 +122,69 @@
return ei;
}
+ SegmentNodeList& getNodeList();
+
+ const SegmentNodeList& getNodeList() const;
+
+ virtual unsigned int size() const
+ {
+ return pts->size();
+ }
+
+ virtual const geom::Coordinate& getCoordinate(unsigned int i) const;
+
+ virtual geom::CoordinateSequence* getCoordinates() const;
+
+ virtual bool isClosed() const;
+
+ virtual std::ostream& print(std::ostream& os) const;
+
+
+ /** \brief
+ * Gets the octant of the segment starting at vertex index.
+ *
+ * @param index the index of the vertex starting the segment.
+ * Must not be the last index in the vertex list
+ * @return the octant of the segment at the vertex
+ */
+ int getSegmentOctant(unsigned int index) const;
+
+ /** \brief
+ * Add {SegmentNode}s for one or both
+ * intersections found for a segment of an edge to the edge
+ * intersection list.
+ */
+ void addIntersections(algorithm::LineIntersector *li,
+ unsigned int segmentIndex, int geomIndex);
+
+ /** \brief
+ * Add an SegmentNode for intersection intIndex.
+ *
+ * An intersection that falls exactly on a vertex
+ * of the SegmentString is normalized
+ * to use the higher of the two possible segmentIndexes
+ */
+ void addIntersection(algorithm::LineIntersector *li,
+ unsigned int segmentIndex,
+ int geomIndex, int intIndex);
+
+ /** \brief
+ * Add an SegmentNode for intersection intIndex.
+ *
+ * An intersection that falls exactly on a vertex of the
+ * edge is normalized
+ * to use the higher of the two possible segmentIndexes
+ */
+ void addIntersection(const geom::Coordinate& intPt,
+ unsigned int segmentIndex);
+
+
+private:
+
+ SegmentNodeList nodeList;
+
+ geom::CoordinateSequence *pts;
+
};
} // namespace geos::noding
Modified: trunk/source/headers/geos/noding/SegmentNodeList.h
===================================================================
--- trunk/source/headers/geos/noding/SegmentNodeList.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/SegmentNodeList.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/SegmentNodeList.java rev. 1.8 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODING_SEGMENTNODELIST_H
@@ -23,7 +27,7 @@
#include <vector>
#include <set>
-#include <geos/noding/SegmentNode.h>
+#include <geos/noding/SegmentNode.h> // for composition
// Forward declarations
namespace geos {
@@ -31,7 +35,7 @@
class CoordinateSequence;
}
namespace noding {
- class SegmentString;
+ class NodedSegmentString;
}
}
@@ -41,15 +45,13 @@
/** \brief
* A list of the SegmentNode present along a
* noded SegmentString.
- *
- * Last port: noding/SegmentNodeList.java rev. 1.7 (JTS-1.7)
*/
class SegmentNodeList {
private:
std::set<SegmentNode*,SegmentNodeLT> nodeMap;
// the parent edge
- const SegmentString& edge;
+ const NodedSegmentString& edge;
// UNUSED
//std::vector<SegmentNode*> *sortedNodes;
@@ -113,11 +115,11 @@
typedef container::iterator iterator;
typedef container::const_iterator const_iterator;
- SegmentNodeList(const SegmentString* newEdge): edge(*newEdge) {}
+ SegmentNodeList(const NodedSegmentString* newEdge): edge(*newEdge) {}
- SegmentNodeList(const SegmentString& newEdge): edge(newEdge) {}
+ SegmentNodeList(const NodedSegmentString& newEdge): edge(newEdge) {}
- const SegmentString& getEdge() const { return edge; }
+ const NodedSegmentString& getEdge() const { return edge; }
// TODO: Is this a final class ?
// Should remove the virtual in that case
Modified: trunk/source/headers/geos/noding/SegmentString.h
===================================================================
--- trunk/source/headers/geos/noding/SegmentString.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/SegmentString.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,13 +11,16 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/SegmentString.java rev. 1.6 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODING_SEGMENTSTRING_H
#define GEOS_NODING_SEGMENTSTRING_H
#include <geos/noding/SegmentNodeList.h>
-#include <geos/geom/CoordinateSequence.h> // for testInvariant
#include <geos/inline.h>
@@ -34,23 +37,11 @@
namespace noding { // geos.noding
/** \brief
- * Represents a list of contiguous line segments,
- * and supports noding the segments.
+ * An interface for classes which represent a sequence of contiguous
+ * line segments.
*
- * The line segments are represented by a CoordinateSequence.
- *
- * TODO:
- * This should be changed to use a vector of Coordinate,
- * to optimize the noding of contiguous segments by
- * reducing the number of allocated objects.
- *
* SegmentStrings can carry a context object, which is useful
* for preserving topological or parentage information.
- * All noded substrings are initialized with the same context object.
- *
- * Final class.
- *
- * Last port: noding/SegmentString.java rev. 1.5 (JTS-1.7)
*/
class SegmentString {
public:
@@ -60,40 +51,36 @@
friend std::ostream& operator<< (std::ostream& os,
const SegmentString& ss);
-private:
- SegmentNodeList nodeList;
- geom::CoordinateSequence *pts;
- mutable unsigned int npts; // this is a cache
- const void* context;
- bool isIsolatedVar;
-
-public:
-
- void testInvariant() const;
-
/// Construct a SegmentString.
//
- /// @param newPts CoordinateSequence representing the string,
- /// externally owned
- ///
/// @param newContext the context associated to this SegmentString
///
- SegmentString(geom::CoordinateSequence *newPts, const void* newContext);
+ SegmentString(const void* newContext)
+ :
+ context(newContext)
+ {}
- virtual ~SegmentString();
+ virtual ~SegmentString() {}
- //const void* getContext() const { return getData(); }
+ /**
+ * Gets the user-defined data for this segment string.
+ *
+ * @return the user-defined data
+ */
+ const void* getData() const { return context; }
- const void* getData() const;
+ /**
+ * Sets the user-defined data for this segment string.
+ *
+ * @param data an Object containing user-defined data
+ */
+ void setData(const void* data) { context=data; }
- const SegmentNodeList& getNodeList() const;
- SegmentNodeList& getNodeList();
+ virtual unsigned int size() const=0;
- unsigned int size() const;
+ virtual const geom::Coordinate& getCoordinate(unsigned int i) const=0;
- const geom::Coordinate& getCoordinate(unsigned int i) const;
-
/// \brief
/// Return a pointer to the CoordinateSequence associated
/// with this SegmentString.
@@ -101,81 +88,21 @@
/// Note that the CoordinateSequence is not owned by
/// this SegmentString!
///
- geom::CoordinateSequence* getCoordinates() const;
+ virtual geom::CoordinateSequence* getCoordinates() const=0;
- /// \brief
- /// Notify this object that the CoordinateSequence associated
- /// with it might have been updated.
- //
- /// This must be called so that the SegmentString object makes
- /// all the necessary checks and updates to verify consistency
- ///
- void notifyCoordinatesChange() const;
-
// Return a read-only pointer to this SegmentString CoordinateSequence
//const CoordinateSequence* getCoordinatesRO() const { return pts; }
- void setIsolated(bool isIsolated);
+ virtual bool isClosed() const=0;
- bool isIsolated() const;
-
- bool isClosed() const;
+ virtual std::ostream& print(std::ostream& os) const;
- /** \brief
- * Gets the octant of the segment starting at vertex
- * <code>index</code>.
- *
- * @param index the index of the vertex starting the segment.
- * Must not be the last index in the vertex list
- * @return the octant of the segment at the vertex
- */
- int getSegmentOctant(unsigned int index) const;
+private:
- /** \brief
- * Add {SegmentNode}s for one or both
- * intersections found for a segment of an edge to the edge
- * intersection list.
- */
- void addIntersections(algorithm::LineIntersector *li,
- unsigned int segmentIndex, int geomIndex);
+ const void* context;
- /** \brief
- * Add an SegmentNode for intersection intIndex.
- *
- * An intersection that falls exactly on a vertex
- * of the SegmentString is normalized
- * to use the higher of the two possible segmentIndexes
- */
- void addIntersection(algorithm::LineIntersector *li,
- unsigned int segmentIndex,
- int geomIndex, int intIndex);
-
- /** \brief
- * Add an SegmentNode for intersection intIndex.
- *
- * An intersection that falls exactly on a vertex of the
- * edge is normalized
- * to use the higher of the two possible segmentIndexes
- */
- void addIntersection(const geom::Coordinate& intPt,
- unsigned int segmentIndex);
-
- static void getNodedSubstrings(
- const SegmentString::NonConstVect& segStrings,
- SegmentString::NonConstVect* resultEdgeList);
-
- static SegmentString::NonConstVect* getNodedSubstrings(
- const SegmentString::NonConstVect& segStrings);
};
-inline void
-SegmentString::testInvariant() const
-{
- assert(pts);
- assert(pts->size() > 1);
- assert(pts->size() == npts);
-}
-
std::ostream& operator<< (std::ostream& os, const SegmentString& ss);
} // namespace geos.noding
Modified: trunk/source/headers/geos/noding/SegmentString.inl
===================================================================
--- trunk/source/headers/geos/noding/SegmentString.inl 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/SegmentString.inl 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/SegmentString.java rev. 1.6 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODING_SEGMENTSTRING_INL
@@ -24,84 +28,8 @@
namespace geos {
namespace noding { // geos.noding
-INLINE
-SegmentString::SegmentString(geom::CoordinateSequence *newPts, const void* newContext)
- :
- nodeList(this),
- pts(newPts),
- npts(pts->size()),
- context(newContext),
- isIsolatedVar(false)
-{
- testInvariant();
-}
-INLINE
-SegmentString::~SegmentString() {}
-INLINE const void*
-SegmentString::getData() const
-{
- testInvariant();
- return context;
-}
-
-INLINE const SegmentNodeList&
-SegmentString::getNodeList() const
-{
- testInvariant();
- return nodeList;
-}
-
-INLINE SegmentNodeList&
-SegmentString::getNodeList()
-{
- testInvariant();
- return nodeList;
-}
-
-INLINE unsigned int
-SegmentString::size() const
-{
- testInvariant();
- return npts;
-}
-
-INLINE const geom::Coordinate&
-SegmentString::getCoordinate(unsigned int i) const
-{
- testInvariant();
- return pts->getAt(i);
-}
-
-INLINE geom::CoordinateSequence*
-SegmentString::getCoordinates() const
-{
- testInvariant();
- return pts;
-}
-
-INLINE void
-SegmentString::setIsolated(bool isIsolated)
-{
- isIsolatedVar=isIsolated;
- testInvariant();
-}
-
-INLINE bool
-SegmentString::isIsolated() const
-{
- testInvariant();
- return isIsolatedVar;
-}
-
-INLINE bool
-SegmentString::isClosed() const
-{
- testInvariant();
- return pts->getAt(0)==pts->getAt(npts-1);
-}
-
} // namespace geos.noding
} // namespace geos
Modified: trunk/source/headers/geos/noding/SimpleNoder.h
===================================================================
--- trunk/source/headers/geos/noding/SimpleNoder.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/SimpleNoder.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/SimpleNoder.java rev. 1.7 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODING_SIMPLENODER_H
@@ -21,7 +25,7 @@
#include <geos/inline.h>
#include <geos/noding/SinglePassNoder.h>
-#include <geos/noding/SegmentString.h> // for inlined (FIXME)
+#include <geos/noding/NodedSegmentString.h> // for inlined (FIXME)
// Forward declarations
namespace geos {
@@ -57,7 +61,7 @@
void computeNodes(std::vector<SegmentString*>* inputSegmentStrings);
std::vector<SegmentString*>* getNodedSubstrings() const {
- return SegmentString::getNodedSubstrings(*nodedSegStrings);
+ return NodedSegmentString::getNodedSubstrings(*nodedSegStrings);
}
};
Modified: trunk/source/headers/geos/noding/snapround/MCIndexPointSnapper.h
===================================================================
--- trunk/source/headers/geos/noding/snapround/MCIndexPointSnapper.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/snapround/MCIndexPointSnapper.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/snapround/MCIndexPointSnapper.java rev. 1.4 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODING_SNAPROUND_MCINDEXPOINTSNAPPER_H
@@ -39,7 +43,6 @@
* "Snaps" all {@link SegmentString}s in a {@link SpatialIndex} containing
* {@link MonotoneChain}s to a given {@link HotPixel}.
*
- * Last port: noding/snapround/MCIndexPointSnapper.java rev. 1.2 (JTS-1.7)
*/
class MCIndexPointSnapper {
@@ -68,10 +71,10 @@
* @param vertexIndex the index of the vertex, if applicable, or -1
* @return <code>true</code> if a node was added for this pixel
*/
- bool snap(const HotPixel& hotPixel, SegmentString* parentEdge,
+ bool snap(HotPixel& hotPixel, SegmentString* parentEdge,
unsigned int vertexIndex);
- bool snap(const HotPixel& hotPixel) {
+ bool snap(HotPixel& hotPixel) {
return snap(hotPixel, 0, 0);
}
Modified: trunk/source/headers/geos/noding/snapround/MCIndexSnapRounder.h
===================================================================
--- trunk/source/headers/geos/noding/snapround/MCIndexSnapRounder.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/snapround/MCIndexSnapRounder.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/snapround/MCIndexSnapRounder.java rev. 1.3 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODING_SNAPROUND_MCINDEXSNAPROUNDER_H
@@ -34,6 +38,7 @@
}
namespace noding {
class SegmentString;
+ class NodedSegmentString;
class MCIndexNoder;
namespace snapround {
//class HotPixel;
@@ -66,9 +71,6 @@
*
* It will function with non-integer precision models, but the
* results are not 100% guaranteed to be correctly noded.
- *
- * Last port: noding/snapround/MCIndexSnapRounder.java rev. 1.1 (JTS-1.7)
- *
*/
class MCIndexSnapRounder: public Noder { // implments Noder
@@ -109,7 +111,7 @@
* Performs a brute-force comparison of every segment in each {@link SegmentString}.
* This has n^2 performance.
*/
- void computeEdgeVertexSnaps(SegmentString* e);
+ void computeVertexSnaps(NodedSegmentString* e);
void checkCorrectness(std::vector<SegmentString*>& inputSegmentStrings);
@@ -126,6 +128,8 @@
* snapping segments to vertices of other segments
*
* @param segStrings the list of segment strings to snap together
+ * NOTE: they *must* be instances of NodedSegmentString, or
+ * an assertion will fail.
*/
void computeVertexSnaps(std::vector<SegmentString*>& edges);
Modified: trunk/source/headers/geos/noding/snapround/MCIndexSnapRounder.inl
===================================================================
--- trunk/source/headers/geos/noding/snapround/MCIndexSnapRounder.inl 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/snapround/MCIndexSnapRounder.inl 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/snapround/MCIndexSnapRounder.java rev. 1.3 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODING_SNAPROUND_MCINDEXSNAPROUNDER_INL
@@ -19,6 +23,7 @@
#include <geos/noding/snapround/MCIndexSnapRounder.h>
#include <geos/noding/snapround/MCIndexPointSnapper.h>
#include <geos/noding/SegmentString.h>
+#include <geos/noding/NodedSegmentString.h>
#include <geos/geom/PrecisionModel.h>
#include <memory>
@@ -30,7 +35,7 @@
INLINE std::vector<SegmentString*>*
MCIndexSnapRounder::getNodedSubstrings() const
{
- return SegmentString::getNodedSubstrings(*nodedSegStrings);
+ return NodedSegmentString::getNodedSubstrings(*nodedSegStrings);
}
INLINE
Modified: trunk/source/headers/geos/noding/snapround/SimpleSnapRounder.h
===================================================================
--- trunk/source/headers/geos/noding/snapround/SimpleSnapRounder.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/noding/snapround/SimpleSnapRounder.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/snapround/SimpleSnapRounder.java rev. 1.4 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_NODING_SNAPROUND_SIMPLESNAPROUNDER_H
@@ -35,6 +39,7 @@
}
namespace noding {
class SegmentString;
+ class NodedSegmentString;
namespace snapround {
class HotPixel;
}
@@ -100,14 +105,14 @@
void computeSnaps(const std::vector<SegmentString*>& segStrings,
std::vector<geom::Coordinate>& snapPts);
- void computeSnaps(SegmentString* ss, std::vector<geom::Coordinate>& snapPts);
+ void computeSnaps(NodedSegmentString* ss, std::vector<geom::Coordinate>& snapPts);
/** \brief
* Performs a brute-force comparison of every segment in each
* {@link SegmentString}.
* This has n^2 performance.
*/
- void computeVertexSnaps(SegmentString* e0, SegmentString* e1);
+ void computeVertexSnaps(NodedSegmentString* e0, NodedSegmentString* e1);
public:
@@ -129,14 +134,15 @@
* @return <code>true</code> if a node was added
*/
static bool addSnappedNode(const HotPixel& hotPix,
- SegmentString& segStr,
+ NodedSegmentString& segStr,
unsigned int segIndex);
/**
* Computes nodes introduced as a result of
* snapping segments to vertices of other segments
*
- * @param segStrings the list of segment strings to snap together
+ * @param segStrings the list of segment strings to snap together.
+ * Must be NodedSegmentString or an assertion will fail.
*/
void computeVertexSnaps(const std::vector<SegmentString*>& edges);
};
Modified: trunk/source/headers/geos/operation/buffer/OffsetCurveSetBuilder.h
===================================================================
--- trunk/source/headers/geos/operation/buffer/OffsetCurveSetBuilder.h 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/headers/geos/operation/buffer/OffsetCurveSetBuilder.h 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: operation/buffer/OffsetCurveSetBuilder.java rev. 1.11 (JTS-1.9)
+ *
**********************************************************************/
#ifndef GEOS_OP_BUFFER_OFFSETCURVESETBUILDER_H
@@ -54,8 +58,6 @@
* Raw curves need to be noded together and polygonized to form the
* final buffer area.
*
- * Last port: operation/buffer/OffsetCurveSetBuilder.java rev. 1.7 (JTS-1.7)
- *
*/
class OffsetCurveSetBuilder {
Added: trunk/source/noding/BasicSegmentString.cpp
===================================================================
--- trunk/source/noding/BasicSegmentString.cpp (rev 0)
+++ trunk/source/noding/BasicSegmentString.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -0,0 +1,84 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2009 Sandro Santilli <strk at keybit.net>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************
+ *
+ * Last port: noding/BasicSegmentString.java rev. 1.1 (JTS-1.9)
+ *
+ **********************************************************************/
+
+#include <geos/noding/BasicSegmentString.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequence.h>
+#include <geos/util/IllegalArgumentException.h>
+#include <geos/noding/Octant.h>
+//#include <geos/profiler.h>
+
+#ifndef GEOS_DEBUG
+#define GEOS_DEBUG 0
+#endif
+
+#include <iostream>
+#include <sstream>
+
+using namespace geos::algorithm;
+using namespace geos::geom;
+
+namespace geos {
+namespace noding { // geos.noding
+
+
+
+/*public*/
+int
+BasicSegmentString::getSegmentOctant(unsigned int index) const
+{
+ if (index >= size() - 1) return -1;
+ return Octant::octant(getCoordinate(index), getCoordinate(index+1));
+}
+
+/* virtual public */
+const geom::Coordinate&
+BasicSegmentString::getCoordinate(unsigned int i) const
+{
+ return pts->getAt(i);
+}
+
+/* virtual public */
+geom::CoordinateSequence*
+BasicSegmentString::getCoordinates() const
+{
+ return pts;
+}
+
+/* virtual public */
+bool
+BasicSegmentString::isClosed() const
+{
+ return pts->getAt(0)==pts->getAt(size()-1);
+}
+
+/* public virtual */
+std::ostream&
+BasicSegmentString::print(std::ostream& os) const
+{
+ os << "BasicSegmentString: " << std::endl;
+ os << " LINESTRING" << *(pts) << ";" << std::endl;
+
+ return os;
+}
+
+
+} // namespace geos.noding
+} // namespace geos
+
Modified: trunk/source/noding/IntersectionAdder.cpp
===================================================================
--- trunk/source/noding/IntersectionAdder.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/noding/IntersectionAdder.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -13,12 +13,13 @@
*
**********************************************************************
*
- * Last port: noding/IntersectionAdder.java rev. 1.4 (JTS-1.7)
+ * Last port: noding/IntersectionAdder.java rev. 1.6 (JTS-1.9)
*
**********************************************************************/
#include <geos/noding/IntersectionAdder.h>
#include <geos/noding/SegmentString.h>
+#include <geos/noding/NodedSegmentString.h>
#include <geos/algorithm/LineIntersector.h>
#include <geos/geom/Coordinate.h>
@@ -90,8 +91,13 @@
if (! isTrivialIntersection(e0, segIndex0, e1, segIndex1))
{
hasIntersectionVar = true;
- e0->addIntersections(&li, segIndex0, 0);
- e1->addIntersections(&li, segIndex1, 1);
+
+ NodedSegmentString* ee0 = dynamic_cast<NodedSegmentString*>(e0);
+ NodedSegmentString* ee1 = dynamic_cast<NodedSegmentString*>(e1);
+ assert(ee0 && ee1);
+ ee0->addIntersections(&li, segIndex0, 0);
+ ee1->addIntersections(&li, segIndex1, 1);
+
if (li.isProper()) {
numProperIntersections++;
//Debug.println(li.toString());
Modified: trunk/source/noding/IntersectionFinderAdder.cpp
===================================================================
--- trunk/source/noding/IntersectionFinderAdder.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/noding/IntersectionFinderAdder.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -13,7 +13,7 @@
*
**********************************************************************
*
- * Last port: noding/IntersectionFinderAdder.java rev. 1.2 (JTS-1.7)
+ * Last port: noding/IntersectionFinderAdder.java rev. 1.5 (JTS-1.9)
*
**********************************************************************/
@@ -21,6 +21,7 @@
#include <geos/noding/IntersectionFinderAdder.h>
#include <geos/noding/SegmentString.h>
+#include <geos/noding/NodedSegmentString.h>
#include <geos/algorithm/LineIntersector.h>
#include <geos/geom/Coordinate.h>
@@ -53,8 +54,12 @@
{
interiorIntersections.push_back(li.getIntersection(intIndex));
}
- e0->addIntersections(&li, segIndex0, 0);
- e1->addIntersections(&li, segIndex1, 1);
+
+ NodedSegmentString* ee0 = dynamic_cast<NodedSegmentString*>(e0);
+ NodedSegmentString* ee1 = dynamic_cast<NodedSegmentString*>(e1);
+ assert(ee0 && ee1);
+ ee0->addIntersections(&li, segIndex0, 0);
+ ee1->addIntersections(&li, segIndex1, 1);
}
}
}
Modified: trunk/source/noding/IteratedNoder.cpp
===================================================================
--- trunk/source/noding/IteratedNoder.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/noding/IteratedNoder.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -14,7 +14,7 @@
*
**********************************************************************
*
- * Last port: noding/IteratedNoder.java rev. 1.6 (JTS-1.7)
+ * Last port: noding/IteratedNoder.java rev. 1.6 (JTS-1.9)
*
**********************************************************************/
Modified: trunk/source/noding/MCIndexNoder.cpp
===================================================================
--- trunk/source/noding/MCIndexNoder.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/noding/MCIndexNoder.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -13,13 +13,13 @@
*
**********************************************************************
*
- * Last port: noding/MCIndexNoder.java rev. 1.4 (JTS-1.7)
+ * Last port: noding/MCIndexNoder.java rev. 1.6 (JTS-1.9)
*
**********************************************************************/
#include <geos/noding/MCIndexNoder.h>
#include <geos/noding/SegmentIntersector.h>
-#include <geos/noding/SegmentString.h>
+#include <geos/noding/NodedSegmentString.h>
#include <geos/index/chain/MonotoneChain.h>
#include <geos/index/chain/MonotoneChainBuilder.h>
Modified: trunk/source/noding/Makefile.am
===================================================================
--- trunk/source/noding/Makefile.am 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/noding/Makefile.am 2009-04-07 19:00:36 UTC (rev 2319)
@@ -5,6 +5,7 @@
INCLUDES = -I$(top_srcdir)/source/headers
libnoding_la_SOURCES = \
+ BasicSegmentString.cpp \
FastNodingValidator.cpp \
FastSegmentSetIntersectionFinder.cpp \
IntersectionAdder.cpp \
Modified: trunk/source/noding/NodedSegmentString.cpp
===================================================================
--- trunk/source/noding/NodedSegmentString.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/noding/NodedSegmentString.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,14 +11,163 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/NodedSegmentString.java rev. 1.2 (JTS-1.9)
+ *
**********************************************************************/
#include <geos/noding/NodedSegmentString.h>
+#include <geos/noding/Octant.h>
+#include <geos/algorithm/LineIntersector.h>
+using namespace geos::algorithm;
+using namespace geos::geom;
+
namespace geos {
namespace noding { // geos::noding
+const SegmentNodeList&
+NodedSegmentString::getNodeList() const
+{
+ return nodeList;
+}
+
+SegmentNodeList&
+NodedSegmentString::getNodeList()
+{
+ return nodeList;
+}
+
+
+/*public*/
+int
+NodedSegmentString::getSegmentOctant(unsigned int index) const
+{
+ if (index >= size() - 1) return -1;
+ return Octant::octant(getCoordinate(index), getCoordinate(index+1));
+}
+
+/*public*/
+void
+NodedSegmentString::addIntersections(LineIntersector *li, unsigned int
+ segmentIndex, int geomIndex)
+{
+ for (int i=0, n=li->getIntersectionNum(); i<n; ++i) {
+ addIntersection(li, segmentIndex, geomIndex, i);
+ }
+}
+
+/*public*/
+void
+NodedSegmentString::addIntersection(LineIntersector *li,
+ unsigned int segmentIndex,
+ int geomIndex, int intIndex)
+{
+ UNREFERENCED_PARAMETER(geomIndex);
+
+ const Coordinate &intPt=li->getIntersection(intIndex);
+ addIntersection(intPt, segmentIndex);
+}
+
+/*public*/
+void
+NodedSegmentString::addIntersection(const Coordinate& intPt,
+ unsigned int segmentIndex)
+{
+ unsigned int normalizedSegmentIndex = segmentIndex;
+
+ if ( segmentIndex > size()-2 )
+ {
+ throw util::IllegalArgumentException("SegmentString::addIntersection: SegmentIndex out of range");
+ }
+
+ // normalize the intersection point location
+ unsigned int nextSegIndex = normalizedSegmentIndex + 1;
+ if (nextSegIndex < size())
+ {
+ const Coordinate& nextPt = pts->getAt(nextSegIndex);
+
+ // Normalize segment index if intPt falls on vertex
+ // The check for point equality is 2D only -
+ // Z values are ignored
+ if (intPt.equals2D(nextPt)) {
+ normalizedSegmentIndex = nextSegIndex;
+ }
+ }
+
+ /*
+ * Add the intersection point to edge intersection list
+ * (unless the node is already known)
+ */
+ //SegmentNode *ei=
+ nodeList.add(intPt, normalizedSegmentIndex);
+
+
+}
+
+/* public static */
+void
+NodedSegmentString::getNodedSubstrings(
+ const SegmentString::NonConstVect& segStrings,
+ SegmentString::NonConstVect *resultEdgeList)
+{
+ assert(resultEdgeList);
+ for ( SegmentString::NonConstVect::const_iterator
+ i=segStrings.begin(), iEnd=segStrings.end();
+ i != iEnd; ++i )
+ {
+ NodedSegmentString* ss = dynamic_cast<NodedSegmentString*>(*i);
+ assert(ss);
+ ss->getNodeList().addSplitEdges(resultEdgeList);
+ }
+}
+
+/* public static */
+SegmentString::NonConstVect*
+NodedSegmentString::getNodedSubstrings(
+ const SegmentString::NonConstVect& segStrings)
+{
+ SegmentString::NonConstVect* resultEdgelist = \
+ new SegmentString::NonConstVect();
+ getNodedSubstrings(segStrings, resultEdgelist);
+ return resultEdgelist;
+}
+
+/* virtual public */
+const geom::Coordinate&
+NodedSegmentString::getCoordinate(unsigned int i) const
+{
+ return pts->getAt(i);
+}
+
+/* virtual public */
+geom::CoordinateSequence*
+NodedSegmentString::getCoordinates() const
+{
+ return pts;
+}
+
+/* virtual public */
+bool
+NodedSegmentString::isClosed() const
+{
+ return pts->getAt(0)==pts->getAt(size()-1);
+}
+
+/* public virtual */
+std::ostream&
+NodedSegmentString::print(std::ostream& os) const
+{
+ os << "NodedSegmentString: " << std::endl;
+ os << " LINESTRING" << *(pts) << ";" << std::endl;
+ os << " Nodes: " << nodeList.size() << std::endl;
+
+ return os;
+}
+
+
} // geos::noding
} // geos
Modified: trunk/source/noding/ScaledNoder.cpp
===================================================================
--- trunk/source/noding/ScaledNoder.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/noding/ScaledNoder.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -146,8 +146,6 @@
{
SegmentString* ss=*i0;
- ss->testInvariant();
-
CoordinateSequence* cs=ss->getCoordinates();
#ifndef NDEBUG
@@ -162,8 +160,6 @@
// the memory cost ?
cs->removeRepeatedPoints();
- // Let SegmentString know that something might be changed
- ss->notifyCoordinatesChange();
}
}
Modified: trunk/source/noding/SegmentNodeList.cpp
===================================================================
--- trunk/source/noding/SegmentNodeList.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/noding/SegmentNodeList.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -14,7 +14,7 @@
*
**********************************************************************
*
- * Last port: noding/SegmentNodeList.java rev. 1.7 (JTS-1.7)
+ * Last port: noding/SegmentNodeList.java rev. 1.8 (JTS-1.9)
*
**********************************************************************/
@@ -24,7 +24,7 @@
#include <geos/profiler.h>
#include <geos/util/GEOSException.h>
#include <geos/noding/SegmentNodeList.h>
-#include <geos/noding/SegmentString.h>
+#include <geos/noding/NodedSegmentString.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/CoordinateArraySequence.h> // FIXME: should we really be using this ?
@@ -283,7 +283,7 @@
}
if (useIntPt1) pts->setAt(ei1->coord, ipt++);
- SegmentString *ret = new SegmentString(pts, edge.getData());
+ SegmentString *ret = new NodedSegmentString(pts, edge.getData());
#if GEOS_DEBUG
std::cerr<<" SegmentString created"<<std::endl;
#endif
Modified: trunk/source/noding/SegmentString.cpp
===================================================================
--- trunk/source/noding/SegmentString.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/noding/SegmentString.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -11,15 +11,19 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/SegmentString.java rev. 1.6 (JTS-1.9)
+ *
**********************************************************************/
#include <geos/noding/SegmentString.h>
-#include <geos/noding/SegmentNodeList.h>
-#include <geos/algorithm/LineIntersector.h>
-#include <geos/geom/Coordinate.h>
-#include <geos/geom/CoordinateSequence.h>
-#include <geos/util/IllegalArgumentException.h>
-#include <geos/noding/Octant.h>
+//#include <geos/noding/SegmentNodeList.h>
+//#include <geos/algorithm/LineIntersector.h>
+//#include <geos/geom/Coordinate.h>
+//#include <geos/geom/CoordinateSequence.h>
+//#include <geos/util/IllegalArgumentException.h>
+//#include <geos/noding/Octant.h>
//#include <geos/profiler.h>
#ifndef GEOS_DEBUG
@@ -39,122 +43,18 @@
namespace geos {
namespace noding { // geos.noding
-/*public*/
-void
-SegmentString::addIntersections(LineIntersector *li, unsigned int segmentIndex,
- int geomIndex)
+std::ostream& operator<< (std::ostream& os, const SegmentString& ss)
{
- for (int i=0, n=li->getIntersectionNum(); i<n; ++i) {
- addIntersection(li, segmentIndex, geomIndex, i);
- }
+ return ss.print(os);
}
-/*public*/
-void
-SegmentString::addIntersection(LineIntersector *li, unsigned int segmentIndex,
- int geomIndex, int intIndex)
+std::ostream&
+SegmentString::print(std::ostream& os) const
{
- UNREFERENCED_PARAMETER(geomIndex);
-
- const Coordinate &intPt=li->getIntersection(intIndex);
- addIntersection(intPt, segmentIndex);
-}
-
-/*public*/
-void
-SegmentString::addIntersection(const Coordinate& intPt,
- unsigned int segmentIndex)
-{
- unsigned int normalizedSegmentIndex = segmentIndex;
-
- if ( segmentIndex > size()-2 )
- {
- throw util::IllegalArgumentException("SegmentString::addIntersection: SegmentIndex out of range");
- }
-
- // normalize the intersection point location
- unsigned int nextSegIndex = normalizedSegmentIndex + 1;
- if (nextSegIndex < size())
- {
- const Coordinate& nextPt = pts->getAt(nextSegIndex);
-
- // Normalize segment index if intPt falls on vertex
- // The check for point equality is 2D only -
- // Z values are ignored
- if (intPt.equals2D(nextPt)) {
- normalizedSegmentIndex = nextSegIndex;
- }
- }
-
- /*
- * Add the intersection point to edge intersection list
- * (unless the node is already known)
- */
- //SegmentNode *ei=
- nodeList.add(intPt, normalizedSegmentIndex);
-
-
- testInvariant();
-}
-
-/* public static */
-void
-SegmentString::getNodedSubstrings(const SegmentString::NonConstVect& segStrings,
- SegmentString::NonConstVect *resultEdgeList)
-{
- assert(resultEdgeList);
- for ( SegmentString::NonConstVect::const_iterator
- i=segStrings.begin(), iEnd=segStrings.end();
- i != iEnd; ++i )
- {
- SegmentString* ss = *i;
- assert(ss);
- ss->getNodeList().addSplitEdges(resultEdgeList);
- }
-}
-
-/* public static */
-SegmentString::NonConstVect*
-SegmentString::getNodedSubstrings(const SegmentString::NonConstVect& segStrings)
-{
- SegmentString::NonConstVect* resultEdgelist = \
- new SegmentString::NonConstVect();
- getNodedSubstrings(segStrings, resultEdgelist);
- return resultEdgelist;
-}
-
-/*public*/
-int
-SegmentString::getSegmentOctant(unsigned int index) const
-{
- testInvariant();
- if (index >= size() - 1) return -1;
- return Octant::octant(getCoordinate(index), getCoordinate(index+1));
-}
-
-/* public */
-void
-SegmentString::notifyCoordinatesChange() const
-{
- npts = pts->size();
-
- // What about SegmentNodes ? should
- // we invalidate them as well ?
-
- testInvariant();
-}
-
-
-std::ostream& operator<< (std::ostream& os, const SegmentString& ss)
-{
- os << "SegmentString: " << std::endl;
- os << " LINESTRING" << *(ss.pts) << ";" << std::endl;
- os << " Nodes: " << ss.nodeList.size() << std::endl;
-
+ os << "SegmentString" << std::endl;
return os;
}
-
} // namespace geos.noding
} // namespace geos
Modified: trunk/source/noding/SimpleNoder.cpp
===================================================================
--- trunk/source/noding/SimpleNoder.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/noding/SimpleNoder.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -12,6 +12,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: noding/SimpleNoder.java rev. 1.7 (JTS-1.9)
+ *
**********************************************************************/
#include <geos/noding/SimpleNoder.h>
Modified: trunk/source/noding/snapround/MCIndexPointSnapper.cpp
===================================================================
--- trunk/source/noding/snapround/MCIndexPointSnapper.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/noding/snapround/MCIndexPointSnapper.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -13,7 +13,7 @@
*
**********************************************************************
*
- * Last port: noding/snapround/MCIndexPointSnapper.java rev. 1.2 (JTS-1.7)
+ * Last port: noding/snapround/MCIndexPointSnapper.java rev. 1.4 (JTS-1.9)
*
**********************************************************************/
@@ -21,6 +21,7 @@
#include <geos/noding/snapround/HotPixel.h>
#include <geos/noding/snapround/SimpleSnapRounder.h>
#include <geos/noding/SegmentString.h>
+#include <geos/noding/NodedSegmentString.h>
#include <geos/spatialIndex.h>
#include <geos/geom/Envelope.h>
#include <geos/index/chain/MonotoneChainSelectAction.h>
@@ -39,14 +40,14 @@
class HotPixelSnapAction: public index::chain::MonotoneChainSelectAction {
private:
- const HotPixel& hotPixel;
+ HotPixel& hotPixel;
SegmentString* parentEdge;
unsigned int vertexIndex;
bool isNodeAddedVar;
public:
- HotPixelSnapAction(const HotPixel& nHotPixel,
+ HotPixelSnapAction(HotPixel& nHotPixel,
SegmentString* nParentEdge,
unsigned int nVertexIndex)
:
@@ -61,13 +62,16 @@
void select(chain::MonotoneChain& mc, unsigned int startIndex)
{
// This is casting away 'constness'!
- SegmentString& ss = *(static_cast<SegmentString*>(mc.getContext()));
+ NodedSegmentString& ss = *(static_cast<NodedSegmentString*>(mc.getContext()));
// don't snap a vertex to itself
if ( parentEdge ) {
if (&ss == parentEdge && startIndex == vertexIndex) return;
}
- isNodeAddedVar = SimpleSnapRounder::addSnappedNode(hotPixel, ss, startIndex);
+
+ //isNodeAddedVar = SimpleSnapRounder::addSnappedNode(hotPixel, ss, startIndex);
+
+ isNodeAddedVar = hotPixel.addSnappedNode(ss, startIndex);
}
void select(LineSegment* ls)
@@ -100,7 +104,7 @@
/* public */
bool
-MCIndexPointSnapper::snap(const HotPixel& hotPixel,
+MCIndexPointSnapper::snap(HotPixel& hotPixel,
SegmentString* parentEdge,
unsigned int vertexIndex)
{
Modified: trunk/source/noding/snapround/MCIndexSnapRounder.cpp
===================================================================
--- trunk/source/noding/snapround/MCIndexSnapRounder.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/noding/snapround/MCIndexSnapRounder.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -13,7 +13,7 @@
*
**********************************************************************
*
- * Last port: noding/snapround/MCIndexSnapRounder.java rev. 1.1 (JTS-1.7)
+ * Last port: noding/snapround/MCIndexSnapRounder.java rev. 1.3 (JTS-1.9)
*
**********************************************************************/
@@ -46,7 +46,7 @@
/*private*/
void
MCIndexSnapRounder::findInteriorIntersections(MCIndexNoder& noder,
- SegmentString::NonConstVect* segStrings,
+ NodedSegmentString::NonConstVect* segStrings,
vector<Coordinate>& intersections)
{
IntersectionFinderAdder intFinderAdder(li, intersections);
@@ -71,7 +71,7 @@
/*private*/
void
-MCIndexSnapRounder::computeEdgeVertexSnaps(SegmentString* e)
+MCIndexSnapRounder::computeVertexSnaps(NodedSegmentString* e)
{
CoordinateSequence& pts0 = *(e->getCoordinates());
for (unsigned int i=0, n=pts0.size()-1; i<n; ++i)
@@ -89,7 +89,14 @@
void
MCIndexSnapRounder::computeVertexSnaps(SegmentString::NonConstVect& edges)
{
- for_each(edges.begin(), edges.end(), bind1st(mem_fun(&MCIndexSnapRounder::computeEdgeVertexSnaps), this));
+ SegmentString::NonConstVect::iterator i=edges.begin(), e=edges.end();
+ for (; i!=e; ++i)
+ {
+ NodedSegmentString* edge0 =
+ dynamic_cast<NodedSegmentString*>(*i);
+ assert(edge0);
+ computeVertexSnaps(edge0);
+ }
}
/*private*/
@@ -125,7 +132,7 @@
SegmentString::NonConstVect& inputSegmentStrings)
{
auto_ptr<SegmentString::NonConstVect> resultSegStrings(
- SegmentString::getNodedSubstrings(inputSegmentStrings)
+ NodedSegmentString::getNodedSubstrings(inputSegmentStrings)
);
NodingValidator nv(*(resultSegStrings.get()));
Modified: trunk/source/noding/snapround/SimpleSnapRounder.cpp
===================================================================
--- trunk/source/noding/snapround/SimpleSnapRounder.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/noding/snapround/SimpleSnapRounder.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -13,13 +13,14 @@
*
**********************************************************************
*
- * Last port: noding/snapround/SimpleSnapRounder.java rev. 1.2 (JTS-1.7)
+ * Last port: noding/snapround/SimpleSnapRounder.java rev. 1.4 (JTS-1.9)
*
**********************************************************************/
#include <geos/noding/snapround/SimpleSnapRounder.h>
#include <geos/noding/snapround/HotPixel.h>
#include <geos/noding/SegmentString.h>
+#include <geos/noding/NodedSegmentString.h>
#include <geos/noding/NodingValidator.h>
#include <geos/noding/MCIndexNoder.h>
#include <geos/noding/IntersectionFinderAdder.h>
@@ -77,7 +78,7 @@
SegmentString::NonConstVect& inputSegmentStrings)
{
auto_ptr<SegmentString::NonConstVect> resultSegStrings(
- SegmentString::getNodedSubstrings(inputSegmentStrings)
+ NodedSegmentString::getNodedSubstrings(inputSegmentStrings)
);
NodingValidator nv(*(resultSegStrings.get()));
@@ -99,17 +100,15 @@
i=segStrings.begin(), iEnd=segStrings.end();
i!=iEnd; ++i)
{
- SegmentString* ss = *i;
+ NodedSegmentString* ss = dynamic_cast<NodedSegmentString*>(*i);
- ss->testInvariant();
-
computeSnaps(ss, snapPts);
}
}
/*private*/
void
-SimpleSnapRounder::computeSnaps(SegmentString* ss, vector<Coordinate>& snapPts)
+SimpleSnapRounder::computeSnaps(NodedSegmentString* ss, vector<Coordinate>& snapPts)
{
for (vector<Coordinate>::iterator
it=snapPts.begin(), itEnd=snapPts.end();
@@ -126,7 +125,7 @@
/* public static */
bool
SimpleSnapRounder::addSnappedNode(const HotPixel& hotPix,
- SegmentString& segStr, unsigned int segIndex)
+ NodedSegmentString& segStr, unsigned int segIndex)
{
const Coordinate& p0 = segStr.getCoordinate(segIndex);
const Coordinate& p1 = segStr.getCoordinate(segIndex + 1);
@@ -144,7 +143,7 @@
/*private*/
void
-SimpleSnapRounder::computeVertexSnaps(SegmentString* e0, SegmentString* e1)
+SimpleSnapRounder::computeVertexSnaps(NodedSegmentString* e0, NodedSegmentString* e1)
{
const CoordinateSequence* pts0 = e0->getCoordinates();
const CoordinateSequence* pts1 = e1->getCoordinates();
@@ -179,12 +178,14 @@
i0=edges.begin(), i0End=edges.end();
i0!=i0End; ++i0)
{
- SegmentString* edge0 = *i0;
+ NodedSegmentString* edge0 = dynamic_cast<NodedSegmentString*>(*i0);
+ assert(edge0);
for (SegmentString::NonConstVect::const_iterator
i1=edges.begin(), i1End=edges.end();
i1!=i1End; ++i1)
{
- SegmentString* edge1 = *i1;
+ NodedSegmentString* edge1 = dynamic_cast<NodedSegmentString*>(*i1);
+ assert(edge1);
computeVertexSnaps(edge0, edge1);
}
}
Modified: trunk/source/operation/buffer/OffsetCurveSetBuilder.cpp
===================================================================
--- trunk/source/operation/buffer/OffsetCurveSetBuilder.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/source/operation/buffer/OffsetCurveSetBuilder.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -14,7 +14,7 @@
*
**********************************************************************
*
- * Last port: operation/buffer/OffsetCurveSetBuilder.java rev. 1.7 (JTS-1.7)
+ * Last port: operation/buffer/OffsetCurveSetBuilder.java rev. 1.11 (JTS-1.9)
*
**********************************************************************/
@@ -35,7 +35,7 @@
#include <geos/geom/Triangle.h>
#include <geos/geomgraph/Position.h>
#include <geos/geomgraph/Label.h>
-#include <geos/noding/SegmentString.h>
+#include <geos/noding/NodedSegmentString.h>
#include <cmath>
#include <cassert>
@@ -68,7 +68,6 @@
OffsetCurveSetBuilder::~OffsetCurveSetBuilder()
{
- //delete cga;
for (size_t i=0, n=curveList.size(); i<n; ++i)
{
delete curveList[i]->getCoordinates();
@@ -117,7 +116,11 @@
// add the edge for a coordinate list which is a raw offset curve
Label *newlabel = new Label(0, Location::BOUNDARY, leftLoc, rightLoc);
- SegmentString *e=new SegmentString(coord, newlabel); // SegmentString doesnt own the sequence, so we need to delete in the destructor
+
+ SegmentString *e=new NodedSegmentString(coord, newlabel);
+
+ // SegmentString doesnt own the sequence, so we need to delete in
+ // the destructor
newLabels.push_back(newlabel);
curveList.push_back(e);
}
@@ -222,6 +225,14 @@
return;
}
+ // don't attemtp to buffer a polygon
+ // with too few distinct vertices
+ if (distance <= 0.0 && shellCoord->size() < 3)
+ {
+ delete shellCoord;
+ return;
+ }
+
addPolygonRing(
shellCoord,
offsetDistance,
Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/tests/unit/Makefile.am 2009-04-07 19:00:36 UTC (rev 2319)
@@ -50,9 +50,10 @@
index/quadtree/DoubleBitsTest.cpp \
io/ByteOrderValuesTest.cpp \
io/WKBReaderTest.cpp \
+ noding/BasicSegmentStringTest.cpp \
+ noding/NodedSegmentStringTest.cpp \
noding/SegmentNodeTest.cpp \
noding/SegmentPointComparatorTest.cpp \
- noding/SegmentStringTest.cpp \
operation/distance/DistanceOpTest.cpp \
operation/IsSimpleOpTest.cpp \
operation/overlay/FuzzyPointLocatorTest.cpp \
Copied: trunk/tests/unit/noding/BasicSegmentStringTest.cpp (from rev 2311, trunk/tests/unit/noding/SegmentStringTest.cpp)
===================================================================
--- trunk/tests/unit/noding/BasicSegmentStringTest.cpp (rev 0)
+++ trunk/tests/unit/noding/BasicSegmentStringTest.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -0,0 +1,211 @@
+// $Id@
+//
+// Test Suite for geos::noding::BasicSegmentString class.
+
+// TUT
+#include <tut.h>
+// GEOS
+#include <geos/noding/BasicSegmentString.h>
+#include <geos/noding/Octant.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/CoordinateArraySequenceFactory.h>
+#include <memory>
+
+namespace tut
+{
+ //
+ // Test Group
+ //
+
+ // Common data used by tests
+ struct test_basicsegmentstring_data
+ {
+
+ typedef std::auto_ptr<geos::geom::CoordinateSequence> \
+ CoordinateSequenceAutoPtr;
+
+ typedef std::auto_ptr<geos::noding::BasicSegmentString> \
+ SegmentStringAutoPtr;
+
+ const geos::geom::CoordinateSequenceFactory* csFactory;
+
+ SegmentStringAutoPtr
+ makeSegmentString(geos::geom::CoordinateSequence* cs, void *d = 0)
+ {
+ return SegmentStringAutoPtr(
+ new geos::noding::BasicSegmentString(cs, d)
+ );
+ }
+
+ test_basicsegmentstring_data()
+ :
+ csFactory(geos::geom::CoordinateArraySequenceFactory::instance())
+ {
+ }
+
+ ~test_basicsegmentstring_data()
+ {
+ }
+
+ };
+
+ typedef test_group<test_basicsegmentstring_data> group;
+ typedef group::object object;
+
+ group test_basicsegmentstring_group("geos::noding::BasicSegmentString");
+
+ //
+ // Test Cases
+ //
+
+ // test constructor with 2 equal points
+ template<>
+ template<>
+ void object::test<1>()
+ {
+ CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+
+ ensure(cs.get());
+
+ geos::geom::Coordinate c0(0, 0);
+ geos::geom::Coordinate c1(0, 0);
+
+ cs->add(c0);
+ cs->add(c1);
+
+ ensure_equals(cs->size(), 2u);
+
+ SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
+ ensure(ss.get());
+
+ ensure_equals(ss->size(), 2u);
+
+ ensure_equals(ss->getData(), (void*)0);
+
+ ensure_equals(ss->getCoordinates(), cs.get());
+
+ ensure_equals(ss->getCoordinate(0), c0);
+
+ ensure_equals(ss->getCoordinate(1), c1);
+
+ ensure_equals(ss->isClosed(), true);
+
+ // this would throw an exception
+ bool octant_failed=false;
+ try {
+ ss->getSegmentOctant(0);
+ } catch (...) {
+ octant_failed=true;
+ }
+ ensure(octant_failed);
+
+ }
+
+ // test constructor with 2 different points
+ template<>
+ template<>
+ void object::test<2>()
+ {
+ CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+
+ ensure(cs.get());
+
+ geos::geom::Coordinate c0(0, 0);
+ geos::geom::Coordinate c1(1, 0);
+
+ cs->add(c0);
+ cs->add(c1);
+
+ ensure_equals(cs->size(), 2u);
+
+ SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
+ ensure(ss.get());
+
+ ensure_equals(ss->size(), 2u);
+
+ ensure_equals(ss->getData(), (void*)0);
+
+ ensure_equals(ss->getCoordinates(), cs.get());
+
+ ensure_equals(ss->getCoordinate(0), c0);
+
+ ensure_equals(ss->getCoordinate(1), c1);
+
+ ensure_equals(ss->isClosed(), false);
+
+ ensure_equals(ss->getSegmentOctant(0), 0);
+
+ }
+
+ // test constructor with 4 different points forming a ring
+ template<>
+ template<>
+ void object::test<3>()
+ {
+ CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+
+ ensure(cs.get());
+
+ geos::geom::Coordinate c0(0, 0);
+ geos::geom::Coordinate c1(1, 0);
+ geos::geom::Coordinate c2(1, 1);
+
+ cs->add(c0);
+ cs->add(c1);
+ cs->add(c2);
+ cs->add(c0);
+
+ ensure_equals(cs->size(), 4u);
+
+ SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
+ ensure(ss.get());
+
+ ensure_equals(ss->size(), 4u);
+
+ ensure_equals(ss->getData(), (void*)0);
+
+ ensure_equals(ss->getCoordinates(), cs.get());
+
+ ensure_equals(ss->getCoordinate(0), c0);
+
+ ensure_equals(ss->getCoordinate(1), c1);
+
+ ensure_equals(ss->getCoordinate(2), c2);
+
+ ensure_equals(ss->getCoordinate(3), c0);
+
+ ensure_equals(ss->isClosed(), true);
+
+ ensure_equals(ss->getSegmentOctant(2), 4);
+
+ ensure_equals(ss->getSegmentOctant(1), 1);
+
+ ensure_equals(ss->getSegmentOctant(0), 0);
+
+ }
+
+ // test Octant class
+ template<>
+ template<>
+ void object::test<4>()
+ {
+ geos::geom::Coordinate p0(0, 0);
+ geos::geom::Coordinate p1(5,-5);
+ int octant_rc1 = 0;
+ int octant_rc2 = 0;
+ int testPassed = true;
+ try {
+ octant_rc1 = geos::noding::Octant::octant(p0,p1);
+ octant_rc2 = geos::noding::Octant::octant(&p0,&p1);
+ testPassed = (octant_rc1 == octant_rc2);
+ }
+ catch (...) {
+ testPassed = false;
+ }
+ ensure(testPassed);
+ }
+
+
+} // namespace tut
+
Property changes on: trunk/tests/unit/noding/BasicSegmentStringTest.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Added: trunk/tests/unit/noding/NodedSegmentStringTest.cpp
===================================================================
--- trunk/tests/unit/noding/NodedSegmentStringTest.cpp (rev 0)
+++ trunk/tests/unit/noding/NodedSegmentStringTest.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -0,0 +1,283 @@
+// $Id@
+//
+// Test Suite for geos::noding::NodedSegmentString class.
+
+// TUT
+#include <tut.h>
+// GEOS
+#include <geos/noding/NodedSegmentString.h>
+#include <geos/noding/Octant.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/CoordinateArraySequenceFactory.h>
+#include <memory>
+
+namespace tut
+{
+ //
+ // Test Group
+ //
+
+ // Common data used by tests
+ struct test_nodedsegmentstring_data
+ {
+
+ typedef std::auto_ptr<geos::geom::CoordinateSequence> \
+ CoordinateSequenceAutoPtr;
+
+ typedef std::auto_ptr<geos::noding::NodedSegmentString> \
+ SegmentStringAutoPtr;
+
+ const geos::geom::CoordinateSequenceFactory* csFactory;
+
+ SegmentStringAutoPtr
+ makeSegmentString(geos::geom::CoordinateSequence* cs, void *d = 0)
+ {
+ return SegmentStringAutoPtr(
+ new geos::noding::NodedSegmentString(cs, d)
+ );
+ }
+
+ test_nodedsegmentstring_data()
+ :
+ csFactory(geos::geom::CoordinateArraySequenceFactory::instance())
+ {
+ }
+
+ ~test_nodedsegmentstring_data()
+ {
+ }
+
+ };
+
+ typedef test_group<test_nodedsegmentstring_data> group;
+ typedef group::object object;
+
+ group test_nodedsegmentstring_group("geos::noding::NodedSegmentString");
+
+ //
+ // Test Cases
+ //
+
+ // test constructor with 2 equal points
+ template<>
+ template<>
+ void object::test<1>()
+ {
+ CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+
+ ensure(cs.get());
+
+ geos::geom::Coordinate c0(0, 0);
+ geos::geom::Coordinate c1(0, 0);
+
+ cs->add(c0);
+ cs->add(c1);
+
+ ensure_equals(cs->size(), 2u);
+
+ SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
+ ensure(ss.get());
+
+ ensure_equals(ss->size(), 2u);
+
+ ensure_equals(ss->getData(), (void*)0);
+
+ ensure_equals(ss->getCoordinates(), cs.get());
+
+ ensure_equals(ss->getCoordinate(0), c0);
+
+ ensure_equals(ss->getCoordinate(1), c1);
+
+ ensure_equals(ss->isClosed(), true);
+
+ ensure_equals(ss->getNodeList().size(), 0u);
+
+ // this would throw an exception
+ bool octant_failed=false;
+ try {
+ ss->getSegmentOctant(0);
+ } catch (...) {
+ octant_failed=true;
+ }
+ ensure(octant_failed);
+
+ }
+
+ // test constructor with 2 different points
+ template<>
+ template<>
+ void object::test<2>()
+ {
+ CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+
+ ensure(cs.get());
+
+ geos::geom::Coordinate c0(0, 0);
+ geos::geom::Coordinate c1(1, 0);
+
+ cs->add(c0);
+ cs->add(c1);
+
+ ensure_equals(cs->size(), 2u);
+
+ SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
+ ensure(ss.get());
+
+ ensure_equals(ss->size(), 2u);
+
+ ensure_equals(ss->getData(), (void*)0);
+
+ ensure_equals(ss->getCoordinates(), cs.get());
+
+ ensure_equals(ss->getCoordinate(0), c0);
+
+ ensure_equals(ss->getCoordinate(1), c1);
+
+ ensure_equals(ss->isClosed(), false);
+
+ ensure_equals(ss->getSegmentOctant(0), 0);
+
+ ensure_equals(ss->getNodeList().size(), 0u);
+ }
+
+ // test constructor with 4 different points forming a ring
+ template<>
+ template<>
+ void object::test<3>()
+ {
+ CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+
+ ensure(cs.get());
+
+ geos::geom::Coordinate c0(0, 0);
+ geos::geom::Coordinate c1(1, 0);
+ geos::geom::Coordinate c2(1, 1);
+
+ cs->add(c0);
+ cs->add(c1);
+ cs->add(c2);
+ cs->add(c0);
+
+ ensure_equals(cs->size(), 4u);
+
+ SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
+ ensure(ss.get());
+
+ ensure_equals(ss->size(), 4u);
+
+ ensure_equals(ss->getData(), (void*)0);
+
+ ensure_equals(ss->getCoordinates(), cs.get());
+
+ ensure_equals(ss->getCoordinate(0), c0);
+
+ ensure_equals(ss->getCoordinate(1), c1);
+
+ ensure_equals(ss->getCoordinate(2), c2);
+
+ ensure_equals(ss->getCoordinate(3), c0);
+
+ ensure_equals(ss->isClosed(), true);
+
+ ensure_equals(ss->getSegmentOctant(2), 4);
+
+ ensure_equals(ss->getSegmentOctant(1), 1);
+
+ ensure_equals(ss->getSegmentOctant(0), 0);
+
+ ensure_equals(ss->getNodeList().size(), 0u);
+ }
+
+ // test Octant class
+ template<>
+ template<>
+ void object::test<4>()
+ {
+ geos::geom::Coordinate p0(0, 0);
+ geos::geom::Coordinate p1(5,-5);
+ int octant_rc1 = 0;
+ int octant_rc2 = 0;
+ int testPassed = true;
+ try {
+ octant_rc1 = geos::noding::Octant::octant(p0,p1);
+ octant_rc2 = geos::noding::Octant::octant(&p0,&p1);
+ testPassed = (octant_rc1 == octant_rc2);
+ }
+ catch (...) {
+ testPassed = false;
+ }
+ ensure(testPassed);
+ }
+
+ // test adding intersections
+ template<>
+ template<>
+ void object::test<5>()
+ {
+ geos::geom::Coordinate p0(0, 0);
+ geos::geom::Coordinate p1(10, 0);
+
+
+ CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
+ cs->add(p0);
+ cs->add(p1);
+
+ SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
+
+ ensure_equals(ss->getNodeList().size(), 0u);
+
+ // the intersection is invalid, but SegmentString trusts us
+ ss->addIntersection(p0, 0);
+ ensure_equals(ss->getNodeList().size(), 1u);
+
+ // This node is already present, so shouldn't be
+ // accepted as a new one
+ ss->addIntersection(p0, 0);
+ ensure_equals(ss->getNodeList().size(), 1u);
+
+ ss->addIntersection(p1, 0);
+ ensure_equals(ss->getNodeList().size(), 2u);
+
+ ss->addIntersection(p1, 0);
+ ensure_equals(ss->getNodeList().size(), 2u);
+
+ ss->addIntersection(p0, 0);
+ ensure_equals(ss->getNodeList().size(), 2u);
+
+ }
+
+ // TODO: test getting noded substrings
+// template<>
+// template<>
+// void object::test<6>()
+// {
+// geos::geom::Coordinate cs1p0(0, 0);
+// geos::geom::Coordinate cs1p1(10, 0);
+// CoordinateSequenceAutoPtr cs1(csFactory->create(0, 2));
+// cs1->add(cs1p0);
+// cs1->add(cs1p1);
+//
+// geos::geom::Coordinate cs2p0(5, -5);
+// geos::geom::Coordinate cs2p1(5, 5);
+// CoordinateSequenceAutoPtr cs2(csFactory->create(0, 2));
+// cs2->add(cs2p0);
+// cs2->add(cs2p1);
+//
+// using geos::noding::SegmentString;
+// using geos::noding::NodedSegmentString;
+//
+// SegmentString::NonConstVect inputStrings;
+// inputStrings.push_back(makeSegmentString(cs2.get()).get());
+//
+// std::auto_ptr<SegmentString::NonConstVect> nodedStrings(
+// NodedSegmentString::getNodedSubstrings(inputStrings)
+// );
+//
+// ensure_equals(nodedStrings->size(), 0u);
+// }
+
+
+
+} // namespace tut
+
Modified: trunk/tests/unit/noding/SegmentNodeTest.cpp
===================================================================
--- trunk/tests/unit/noding/SegmentNodeTest.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/tests/unit/noding/SegmentNodeTest.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -6,7 +6,7 @@
#include <tut.h>
// GEOS
#include <geos/noding/SegmentNode.h>
-#include <geos/noding/SegmentString.h>
+#include <geos/noding/BasicSegmentString.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/CoordinateArraySequenceFactory.h>
@@ -50,7 +50,7 @@
void object::test<1>()
{
using geos::geom::Coordinate;
- using geos::noding::SegmentString;
+ using geos::noding::BasicSegmentString;
using geos::noding::SegmentNode;
// Create coordinates sequence
@@ -68,7 +68,7 @@
// Create SegmentString instance
- SegmentString segment(cs.get(), 0);
+ BasicSegmentString segment(cs.get(), 0);
ensure_equals( segment.size(), coords_size );
Deleted: trunk/tests/unit/noding/SegmentStringTest.cpp
===================================================================
--- trunk/tests/unit/noding/SegmentStringTest.cpp 2009-04-07 12:36:50 UTC (rev 2318)
+++ trunk/tests/unit/noding/SegmentStringTest.cpp 2009-04-07 19:00:36 UTC (rev 2319)
@@ -1,263 +0,0 @@
-// $Id$
-//
-// Test Suite for geos::noding::SegmentString class.
-
-// TUT
-#include <tut.h>
-// GEOS
-#include <geos/noding/SegmentString.h>
-#include <geos/noding/Octant.h>
-#include <geos/geom/Coordinate.h>
-#include <geos/geom/CoordinateSequence.h>
-#include <geos/geom/CoordinateArraySequenceFactory.h>
-#include <memory>
-
-namespace tut
-{
- //
- // Test Group
- //
-
- // Common data used by tests
- struct test_segmentstring_data
- {
-
- typedef std::auto_ptr<geos::geom::CoordinateSequence> \
- CoordinateSequenceAutoPtr;
-
- typedef std::auto_ptr<geos::noding::SegmentString> \
- SegmentStringAutoPtr;
-
- const geos::geom::CoordinateSequenceFactory* csFactory;
-
- SegmentStringAutoPtr
- makeSegmentString(geos::geom::CoordinateSequence* cs, void *d = 0)
- {
- return SegmentStringAutoPtr(
- new geos::noding::SegmentString(cs, d)
- );
- }
-
- test_segmentstring_data()
- :
- csFactory(geos::geom::CoordinateArraySequenceFactory::instance())
- {
- }
-
- ~test_segmentstring_data()
- {
- }
-
- };
-
- typedef test_group<test_segmentstring_data> group;
- typedef group::object object;
-
- group test_segmentstring_group("geos::noding::SegmentString");
-
- //
- // Test Cases
- //
-
- // test constructor with 2 equal points
- template<>
- template<>
- void object::test<1>()
- {
- CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
-
- ensure(cs.get());
-
- geos::geom::Coordinate c0(0, 0);
- geos::geom::Coordinate c1(0, 0);
-
- cs->add(c0);
- cs->add(c1);
-
- ensure_equals(cs->size(), 2u);
-
- SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
- ensure(ss.get());
-
- ensure_equals(ss->size(), 2u);
-
- ensure_equals(ss->getData(), (void*)0);
-
- ensure_equals(ss->getCoordinates(), cs.get());
-
- ensure_equals(ss->getCoordinate(0), c0);
-
- ensure_equals(ss->getCoordinate(1), c1);
-
- ensure_equals(ss->isIsolated(), false);
-
- ensure_equals(ss->isClosed(), true);
-
- // this would throw an exception
- bool octant_failed=false;
- try {
- ss->getSegmentOctant(0);
- } catch (...) {
- octant_failed=true;
- }
- ensure(octant_failed);
-
- ensure_equals(ss->getNodeList().size(), 0u);
-
- ss->testInvariant();
- }
-
- // test constructor with 2 different points
- template<>
- template<>
- void object::test<2>()
- {
- CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
-
- ensure(cs.get());
-
- geos::geom::Coordinate c0(0, 0);
- geos::geom::Coordinate c1(1, 0);
-
- cs->add(c0);
- cs->add(c1);
-
- ensure_equals(cs->size(), 2u);
-
- SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
- ensure(ss.get());
-
- ensure_equals(ss->size(), 2u);
-
- ensure_equals(ss->getData(), (void*)0);
-
- ensure_equals(ss->getCoordinates(), cs.get());
-
- ensure_equals(ss->getCoordinate(0), c0);
-
- ensure_equals(ss->getCoordinate(1), c1);
-
- ensure_equals(ss->isIsolated(), false);
-
- ensure_equals(ss->isClosed(), false);
-
- ensure_equals(ss->getSegmentOctant(0), 0);
-
- ensure_equals(ss->getNodeList().size(), 0u);
-
- ss->testInvariant();
- }
-
- // test constructor with 4 different points forming a ring
- template<>
- template<>
- void object::test<3>()
- {
- CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
-
- ensure(cs.get());
-
- geos::geom::Coordinate c0(0, 0);
- geos::geom::Coordinate c1(1, 0);
- geos::geom::Coordinate c2(1, 1);
-
- cs->add(c0);
- cs->add(c1);
- cs->add(c2);
- cs->add(c0);
-
- ensure_equals(cs->size(), 4u);
-
- SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
- ensure(ss.get());
-
- ensure_equals(ss->size(), 4u);
-
- ensure_equals(ss->getData(), (void*)0);
-
- ensure_equals(ss->getCoordinates(), cs.get());
-
- ensure_equals(ss->getCoordinate(0), c0);
-
- ensure_equals(ss->getCoordinate(1), c1);
-
- ensure_equals(ss->getCoordinate(2), c2);
-
- ensure_equals(ss->getCoordinate(3), c0);
-
- ensure_equals(ss->isIsolated(), false);
-
- ensure_equals(ss->isClosed(), true);
-
- ensure_equals(ss->getSegmentOctant(2), 4);
-
- ensure_equals(ss->getSegmentOctant(1), 1);
-
- ensure_equals(ss->getSegmentOctant(0), 0);
-
- ensure_equals(ss->getNodeList().size(), 0u);
-
- ss->testInvariant();
- }
-
- // test adding intersections
- template<>
- template<>
- void object::test<4>()
- {
- geos::geom::Coordinate p0(0, 0);
- geos::geom::Coordinate p1(10, 0);
-
-
- CoordinateSequenceAutoPtr cs(csFactory->create(0, 2));
- cs->add(p0);
- cs->add(p1);
-
- SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
-
- ensure_equals(ss->getNodeList().size(), 0u);
-
- // the intersection is invalid, but SegmentString trusts us
- ss->addIntersection(p0, 0);
- ensure_equals(ss->getNodeList().size(), 1u);
-
- // This node is already present, so shouldn't be
- // accepted as a new one
- ss->addIntersection(p0, 0);
- ensure_equals(ss->getNodeList().size(), 1u);
-
- ss->addIntersection(p1, 0);
- ensure_equals(ss->getNodeList().size(), 2u);
-
- ss->addIntersection(p1, 0);
- ensure_equals(ss->getNodeList().size(), 2u);
-
- ss->addIntersection(p0, 0);
- ensure_equals(ss->getNodeList().size(), 2u);
-
- }
-
- // test Octant class
- template<>
- template<>
- void object::test<5>()
- {
- geos::geom::Coordinate p0(0, 0);
- geos::geom::Coordinate p1(5,-5);
- int octant_rc1 = 0;
- int octant_rc2 = 0;
- int testPassed = true;
- try {
- octant_rc1 = geos::noding::Octant::octant(p0,p1);
- octant_rc2 = geos::noding::Octant::octant(&p0,&p1);
- testPassed = (octant_rc1 == octant_rc2);
- }
- catch (...) {
- testPassed = false;
- }
- ensure(testPassed);
- }
-
-
-} // namespace tut
-
More information about the geos-commits
mailing list