[geos-commits] r2468 - in trunk: . source/headers/geos/geom
source/headers/geos/operation/overlay
source/headers/geos/operation/overlay/snap
source/headers/geos/precision source/operation/overlay/snap
source/precision tests/unit tests/unit/operation/overlay
tests/unit/operation/overlay/snap tests/unit/precision
svn_geos at osgeo.org
svn_geos at osgeo.org
Tue May 5 06:14:39 EDT 2009
Author: strk
Date: 2009-05-05 06:14:39 -0400 (Tue, 05 May 2009)
New Revision: 2468
Added:
trunk/source/headers/geos/operation/overlay/snap/Makefile.am
trunk/tests/unit/operation/overlay/snap/
trunk/tests/unit/operation/overlay/snap/GeometrySnapperTest.cpp
trunk/tests/unit/operation/overlay/snap/LineStringSnapperTest.cpp
Removed:
trunk/source/headers/geos/precision/GeometrySnapper.h
trunk/source/headers/geos/precision/LineStringSnapper.h
trunk/source/precision/GeometrySnapper.cpp
trunk/source/precision/LineStringSnapper.cpp
trunk/tests/unit/precision/GeometrySnapperTest.cpp
trunk/tests/unit/precision/LineStringSnapperTest.cpp
Modified:
trunk/configure.in
trunk/source/headers/geos/geom/BinaryOp.h
trunk/source/headers/geos/operation/overlay/Makefile.am
trunk/source/headers/geos/operation/overlay/snap/GeometrySnapper.h
trunk/source/headers/geos/operation/overlay/snap/LineStringSnapper.h
trunk/source/headers/geos/precision/Makefile.am
trunk/source/operation/overlay/snap/GeometrySnapper.cpp
trunk/source/operation/overlay/snap/LineStringSnapper.cpp
trunk/source/operation/overlay/snap/SnapOverlayOp.cpp
trunk/source/precision/Makefile.am
trunk/tests/unit/Makefile.am
Log:
Found old GeometrySnapper/LineStringSnapper classes in an unexpected directory. Move them where they belong, sync with JTS-1.10.
Modified: trunk/configure.in
===================================================================
--- trunk/configure.in 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/configure.in 2009-05-05 10:14:39 UTC (rev 2468)
@@ -321,6 +321,7 @@
source/headers/geos/operation/distance/Makefile
source/headers/geos/operation/linemerge/Makefile
source/headers/geos/operation/overlay/Makefile
+ source/headers/geos/operation/overlay/snap/Makefile
source/headers/geos/operation/polygonize/Makefile
source/headers/geos/operation/predicate/Makefile
source/headers/geos/operation/relate/Makefile
Modified: trunk/source/headers/geos/geom/BinaryOp.h
===================================================================
--- trunk/source/headers/geos/geom/BinaryOp.h 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/source/headers/geos/geom/BinaryOp.h 2009-05-05 10:14:39 UTC (rev 2468)
@@ -53,7 +53,9 @@
#include <geos/geom/PrecisionModel.h>
#include <geos/precision/CommonBitsRemover.h>
#include <geos/precision/SimpleGeometryPrecisionReducer.h>
-#include <geos/precision/GeometrySnapper.h>
+
+#include <geos/operation/overlay/snap/GeometrySnapper.h>
+
#include <geos/simplify/TopologyPreservingSimplifier.h>
#include <geos/operation/valid/IsValidOp.h>
#include <geos/util/TopologyException.h>
@@ -134,7 +136,8 @@
#define CBR_BEFORE_SNAPPING 1
- using geos::precision::GeometrySnapper;
+ //using geos::precision::GeometrySnapper;
+ using geos::operation::overlay::snap::GeometrySnapper;
// Snap tolerance must be computed on the original
// (not commonbits-removed) geoms
Modified: trunk/source/headers/geos/operation/overlay/Makefile.am
===================================================================
--- trunk/source/headers/geos/operation/overlay/Makefile.am 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/source/headers/geos/operation/overlay/Makefile.am 2009-05-05 10:14:39 UTC (rev 2468)
@@ -1,8 +1,9 @@
-#SUBDIRS =
+SUBDIRS = snap
#EXTRA_DIST =
# Notes:
+# snap/GeometrySnapper.h is needed by geom/BinaryOp.h
#
geosdir = $(includedir)/geos/operation/overlay
@@ -21,10 +22,6 @@
OverlayNodeFactory.h \
PointBuilder.h \
PolygonBuilder.h \
- snap/GeometrySnapper.h \
- snap/LineStringSnapper.h \
- snap/SnapOverlayOp.h \
- snap/SnapIfNeededOverlayOp.h \
validate/FuzzyPointLocator.h \
validate/OffsetPointGenerator.h \
validate/OverlayResultValidator.h
Modified: trunk/source/headers/geos/operation/overlay/snap/GeometrySnapper.h
===================================================================
--- trunk/source/headers/geos/operation/overlay/snap/GeometrySnapper.h 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/source/headers/geos/operation/overlay/snap/GeometrySnapper.h 2009-05-05 10:14:39 UTC (rev 2468)
@@ -1,10 +1,11 @@
/**********************************************************************
- * $Id$
+ * $Id: GeometrySnapper.h 1948 2006-12-18 18:44:20Z strk $
*
* GEOS - Geometry Engine Open Source
* http://geos.refractions.net
*
* Copyright (C) 2009 Sandro Santilli <strk at keybit.net>
+ * Copyright (C) 2006 Refractions Research Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
@@ -20,15 +21,16 @@
#ifndef GEOS_OP_OVERLAY_SNAP_GEOMETRYSNAPPER_H
#define GEOS_OP_OVERLAY_SNAP_GEOMETRYSNAPPER_H
-#include <geos/geom/LineSegment.h> // for composition
-#include <geos/geom/LineString.h> // for inlined ctor
+#include <geos/geom/Coordinate.h>
-//#include <vector>
-#include <memory> // for auto_ptr
+#include <memory>
+#include <vector>
// Forward declarations
namespace geos {
- namespace geom {
+ namespace geom {
+ //class PrecisionModel;
+ class Geometry;
class CoordinateSequence;
}
}
@@ -39,34 +41,13 @@
namespace snap { // geos::operation::overlay::snap
/** \brief
- * Snaps the vertices and segments of a geom::Geometry to another
- * Geometry's vertices.
- *
- * Improves robustness for overlay operations, by eliminating
- * nearly parallel edges (which cause problems during noding and
- * intersection calculation).
- *
+ * Snaps the vertices and segments of a geometry to another's vertices.
+ * Should improve robustness for overlay operations.
*/
-class GeometrySnapper
-{
+class GeometrySnapper {
public:
- /** \brief
- * Estimates the snap tolerance for a Geometry, taking into account
- * its precision model.
- *
- * @param g a Geometry
- * @return the estimated snap tolerance
- */
- static double computeOverlaySnapTolerance(const geom::Geometry& g);
-
- static double computeSizeBasedSnapTolerance(const geom::Geometry& g);
-
- static double computeOverlaySnapTolerance(const geom::Geometry& g0,
- const geom::Geometry& g1);
-
-
typedef std::auto_ptr<geom::Geometry> GeomPtr;
typedef std::pair<GeomPtr, GeomPtr> GeomPtrPair;
@@ -86,45 +67,63 @@
/**
* Creates a new snapper acting on the given geometry
*
- * @param nSrcGeom the geometry to snap
+ * @param g the geometry to snap
*/
- GeometrySnapper(const geom::Geometry& nSrcGeom)
+ GeometrySnapper(const geom::Geometry& g)
:
- srcGeom(nSrcGeom)
- {}
+ srcGeom(g)
+ {
+ }
- /**
+ /** \brief
* Snaps the vertices in the component {@link LineString}s
- * of the source geometry
- * to the vertices of the given snap geometry.
+ * of the source geometry to the vertices of the given snap geometry
+ * with a given snap tolerance
*
- * @param snapGeom a geometry to snap the source to
+ * @param g a geometry to snap the source to
* @param snapTolerance
- *
* @return a new snapped Geometry
*/
- GeomPtr snapTo(const geom::Geometry& snapGeom, double snapTolerance);
+ std::auto_ptr<geom::Geometry> snapTo(const geom::Geometry& g,
+ double snapTolerance);
- // why is this public ??
- void extractTargetCoordinates(const geom::Geometry& g,
- std::vector<const geom::Coordinate*>& target);
-
+ /** \brief
+ * Estimates the snap tolerance for a Geometry, taking into account
+ * its precision model.
+ *
+ * @param g a Geometry
+ * @return the estimated snap tolerance
+ */
+ static double computeOverlaySnapTolerance(const geom::Geometry& g);
+ static double computeSizeBasedSnapTolerance(const geom::Geometry& g);
+
+ /** \brief
+ * Computes the snap tolerance based on input geometries;
+ */
+ static double computeOverlaySnapTolerance(const geom::Geometry& g1,
+ const geom::Geometry& g2);
+
+
private:
- static const double SNAP_PRECISION_FACTOR; // = 10e-10;
+ // eventually this will be determined from the geometry topology
+ //static const double snapTol; // = 0.000001;
+ static const double snapPrecisionFactor; // = 10e-10
+
const geom::Geometry& srcGeom;
+
+ /// Extract target (unique) coordinates
+ std::auto_ptr<geom::Coordinate::ConstVect> extractTargetCoordinates(
+ const geom::Geometry& g);
};
+
} // namespace geos::operation::overlay::snap
} // namespace geos::operation::overlay
} // namespace geos::operation
} // namespace geos
-#endif // ndef GEOS_OP_OVERLAY_SNAP_GEOMETRYSNAPPER_H
+#endif // GEOS_OP_OVERLAY_SNAP_GEOMETRYSNAPPER_H
-/**********************************************************************
- * $Log$
- **********************************************************************/
-
Modified: trunk/source/headers/geos/operation/overlay/snap/LineStringSnapper.h
===================================================================
--- trunk/source/headers/geos/operation/overlay/snap/LineStringSnapper.h 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/source/headers/geos/operation/overlay/snap/LineStringSnapper.h 2009-05-05 10:14:39 UTC (rev 2468)
@@ -5,6 +5,7 @@
* http://geos.refractions.net
*
* Copyright (C) 2009 Sandro Santilli <strk at keybit.net>
+ * Copyright (C) 2006 Refractions Research Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
@@ -13,24 +14,26 @@
*
***********************************************************************
*
- * Last port: operation/overlay/snap/LineStringSnapper.java rev 1.5 (JTS-1.10)
+ * Last port: operation/overlay/snap/lineStringSnapper.java rev 1.5 (JTS-1.10)
*
**********************************************************************/
#ifndef GEOS_OP_OVERLAY_SNAP_LINESTRINGSNAPPER_H
#define GEOS_OP_OVERLAY_SNAP_LINESTRINGSNAPPER_H
-#include <geos/geom/LineSegment.h> // for composition
-#include <geos/geom/LineString.h> // for inlined ctor
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/CoordinateList.h>
-#include <vector>
-#include <memory> // for auto_ptr
+#include <memory>
// Forward declarations
namespace geos {
- namespace geom {
- class Coordinate;
- class CoordinateSequence;
+ namespace geom {
+ //class PrecisionModel;
+ //class CoordinateSequence;
+ class CoordinateList;
+ class Geometry;
}
}
@@ -51,130 +54,80 @@
public:
/**
- * Creates a new snapper using the points in the given LineString
- * as source snap points.
- *
- * @param srcLline a LineString to snap
- * @param nSnapTolerance the snap tolerance to use
- */
- LineStringSnapper(const geom::LineString& srcLline,
- double nSnapTolerance)
- :
- snapTolerance(nSnapTolerance),
- srcPts(*(srcLline.getCoordinatesRO())),
- seg(),
- isClosed(false)
- {
- }
-
- /**
* Creates a new snapper using the given points
* as source points to be snapped.
*
* @param nSrcPts the points to snap
* @param nSnapTolerance the snap tolerance to use
*/
- LineStringSnapper(const geom::CoordinateSequence& nSrcPts,
- double nSnapTolerance)
+ LineStringSnapper(const geom::Coordinate::Vect& nSrcPts,
+ double nSnapTol)
:
- snapTolerance(nSnapTolerance),
srcPts(nSrcPts),
- seg(),
- isClosed(false)
+ snapTolerance(nSnapTol)
{
+ size_t s = srcPts.size();
+ isClosed = ( s < 2 || srcPts[0].equals2D(srcPts[s-1]) );
}
- /**
- * Snaps the vertices and segments of the source points
- * to the given set of target snap points.
- *
- * @param snapPts the vertices to snap to
- * @return a sequence formed by the snapped points
- */
- std::auto_ptr<geom::CoordinateSequence> snapTo(
- const geom::CoordinateSequence& snapPts);
+ // Snap points are assumed to be all distinct points (a set would be better, uh ?)
+ std::auto_ptr<geom::Coordinate::Vect> snapTo(const geom::Coordinate::ConstVect& snapPts);
- std::auto_ptr<geom::CoordinateSequence> snapTo(
- const std::vector<const geom::Coordinate*>& snapPts);
-
private:
- /**
- * Snap source vertices to vertices in the target.
- *
- * @param srcCoords the points to snap
- * @param snapPts the points to snap to
- */
- void snapVertices(geom::CoordinateSequence& srcCoords,
- const geom::CoordinateSequence& snapPts);
+ const geom::Coordinate::Vect& srcPts;
- void snapVertices(geom::CoordinateSequence& srcCoords,
- const std::vector<const geom::Coordinate*>& snapPts);
+ double snapTolerance;
+ bool isClosed;
- // return pointer into snapPts memory, or null
- const geom::Coordinate*
- findSnapForVertex(const geom::Coordinate& pt,
- const geom::CoordinateSequence& snapPts);
- const geom::Coordinate*
- findSnapForVertex(const geom::Coordinate& pt,
- const std::vector<const geom::Coordinate*>& snapPts);
+ // Modifies first arg
+ void snapVertices(geom::CoordinateList& srcCoords,
+ const geom::Coordinate::ConstVect& snapPts);
- /**
- * Snap segments of the source to nearby snap vertices.
- * Source segments are "cracked" at a snap vertex, and further
- * snapping takes place on the modified list of segments.
- * For each distinct snap vertex, at most one source segment
- * is snapped to. This prevents "cracking" multiple segments
- * at the same point, which would almost certainly cause the result
- * to be invalid.
- *
- * @param srcCoords
- * @param snapPts
- */
- void snapSegments(geom::CoordinateSequence& srcCoords,
- const geom::CoordinateSequence& snapPts);
- void snapSegments(geom::CoordinateSequence& srcCoords,
- const std::vector<const geom::Coordinate*>& snapPts);
+ // Returns snapPts.end() if no snap point is close enough (within snapTol distance)
+ geom::Coordinate::ConstVect::const_iterator findSnapForVertex(const geom::Coordinate& pt,
+ const geom::Coordinate::ConstVect& snapPts);
- /** \brief
- * Finds a src segment which snaps to (is close to)
- * the given snap point.
- *
- * Only one segment is determined - this is to prevent * snapping to multiple segments, which would almost certainly
- * cause invalid geometry to be created.
- * (The heuristic approach of snapping is really only appropriate when
- * snap pts snap to a unique spot on the src geometry.)
- *
- * @param snapPt the point to snap to
- * @param srcCoords the source segment coordinates
- * @return the index of the snapped segment
- * @return -1 if no segment snaps
- */
- int findSegmentIndexToSnap(const geom::Coordinate& snapPt,
- const geom::CoordinateSequence& srcCoords);
-
+ // Modifies first arg
+ void snapSegments(geom::CoordinateList& srcCoords,
+ const geom::Coordinate::ConstVect& snapPts);
- double snapTolerance;
+ /// \brief
+ /// Finds a src segment which snaps to (is close to) the given snap
+ /// point.
+ //
+ /// Only one segment is determined - this is to prevent
+ /// snapping to multiple segments, which would almost certainly cause
+ /// invalid geometry to be created.
+ /// (The heuristic approach of snapping is really only appropriate
+ /// when snap pts snap to a unique spot on the src geometry.)
+ ///
+ ///
+ /// @param from
+ /// an iterator to first point of first segment to be checked
+ ///
+ /// @param too_far
+ /// an iterator to last point of last segment to be checked
+ ///
+ /// @returns too_far if no segment needs snapping
+ /// (either none within snapTol distance,
+ /// or one fond on the snapPt)
+ ///
+ geom::CoordinateList::iterator findSegmentToSnap(
+ const geom::Coordinate& snapPt,
+ geom::CoordinateList::iterator from,
+ geom::CoordinateList::iterator too_far);
- const geom::CoordinateSequence& srcPts;
-
- geom::LineSegment seg; // for reuse during snapping
-
- bool isClosed;
-
};
+
} // namespace geos::operation::overlay::snap
} // namespace geos::operation::overlay
} // namespace geos::operation
} // namespace geos
-#endif // ndef GEOS_OP_OVERLAY_SNAP_LINESTRINGSNAPPER_H
+#endif // GEOS_OP_OVERLAY_SNAP_LINESTRINGSNAPPER_H
-/**********************************************************************
- * $Log$
- **********************************************************************/
-
Added: trunk/source/headers/geos/operation/overlay/snap/Makefile.am
===================================================================
--- trunk/source/headers/geos/operation/overlay/snap/Makefile.am (rev 0)
+++ trunk/source/headers/geos/operation/overlay/snap/Makefile.am 2009-05-05 10:14:39 UTC (rev 2468)
@@ -0,0 +1,17 @@
+#SUBDIRS =
+
+#EXTRA_DIST =
+
+# Notes:
+# snap/GeometrySnapper.h is needed by geom/BinaryOp.h
+#
+
+geosdir = $(includedir)/geos/operation/overlay/snap
+
+geos_HEADERS = \
+ GeometrySnapper.h
+
+noinst_HEADERS = \
+ LineStringSnapper.h \
+ SnapOverlayOp.h \
+ SnapIfNeededOverlayOp.h
Deleted: trunk/source/headers/geos/precision/GeometrySnapper.h
===================================================================
--- trunk/source/headers/geos/precision/GeometrySnapper.h 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/source/headers/geos/precision/GeometrySnapper.h 2009-05-05 10:14:39 UTC (rev 2468)
@@ -1,110 +0,0 @@
-/**********************************************************************
- * $Id$
- *
- * GEOS - Geometry Engine Open Source
- * http://geos.refractions.net
- *
- * Copyright (C) 2006 Refractions Research Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU Lesser General Public Licence as published
- * by the Free Software Foundation.
- * See the COPYING file for more information.
- *
- ***********************************************************************
- *
- * Last port: operation/overlay/snap/GeometrySnapper.java rev. 1.6
- * (we should move in GEOS too, probably)
- *
- **********************************************************************/
-
-#ifndef GEOS_PRECISION_GEOMETRYSNAPPER_H
-#define GEOS_PRECISION_GEOMETRYSNAPPER_H
-
-#include <geos/geom/Coordinate.h>
-
-#include <memory>
-#include <vector>
-
-// Forward declarations
-namespace geos {
- namespace geom {
- //class PrecisionModel;
- class Geometry;
- class CoordinateSequence;
- }
-}
-
-namespace geos {
-namespace precision { // geos.precision
-
-/** \brief
- * Snaps the vertices and segments of a geometry to another's vertices.
- * Should improve robustness for overlay operations.
- */
-class GeometrySnapper {
-
-public:
-
- GeometrySnapper(const geom::Geometry& g)
- :
- srcGeom(g)
- {
- }
-
- /** \brief
- * Snaps the vertices in the component {@link LineString}s
- * of the source geometry to the vertices of the given geometry
- * with a given snap tolerance
- *
- * @param g
- * @param snapTolerance
- * @return a new snapped Geometry
- */
- std::auto_ptr<geom::Geometry> snapTo(const geom::Geometry& g, double snapTolerance);
-
- /** \brief
- * Estimates the snap tolerance for a Geometry, taking into account
- * its precision model.
- *
- * @param g a Geometry
- * @return the estimated snap tolerance
- */
- static double computeOverlaySnapTolerance(const geom::Geometry& g);
-
- static double computeSizeBasedSnapTolerance(const geom::Geometry& g);
-
- /** \brief
- * Computes the snap tolerance based on input geometries;
- */
- static double computeOverlaySnapTolerance(const geom::Geometry& g1,
- const geom::Geometry& g2);
-
-
-private:
-
- // eventually this will be determined from the geometry topology
- //static const double snapTol; // = 0.000001;
-
- static const double snapPrecisionFactor; // = 10e-10
-
- const geom::Geometry& srcGeom;
-
- /// Extract target (unique) coordinates
- std::auto_ptr<geom::Coordinate::ConstVect> extractTargetCoordinates(
- const geom::Geometry& g);
-};
-
-
-} // namespace geos.precision
-} // namespace geos
-
-#endif // GEOS_PRECISION_GEOMETRYSNAPPER_H
-
-/**********************************************************************
- * $Log$
- * Revision 1.1 2006/07/21 17:09:14 strk
- * Added new precision::LineStringSnapper class + test
- * and precision::GeometrySnapper (w/out test)
- *
- **********************************************************************/
Deleted: trunk/source/headers/geos/precision/LineStringSnapper.h
===================================================================
--- trunk/source/headers/geos/precision/LineStringSnapper.h 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/source/headers/geos/precision/LineStringSnapper.h 2009-05-05 10:14:39 UTC (rev 2468)
@@ -1,126 +0,0 @@
-/**********************************************************************
- * $Id$
- *
- * GEOS - Geometry Engine Open Source
- * http://geos.refractions.net
- *
- * Copyright (C) 2006 Refractions Research Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU Lesser General Public Licence as published
- * by the Free Software Foundation.
- * See the COPYING file for more information.
- *
- ***********************************************************************
- *
- * Last port: operation/overlay/snap/lineStringSnapper.java rev. 1.1
- * (we should move in GEOS too, probably)
- *
- **********************************************************************/
-
-#ifndef GEOS_PRECISION_LINESTRINGSNAPPER_H
-#define GEOS_PRECISION_LINESTRINGSNAPPER_H
-
-#include <geos/geom/Coordinate.h>
-#include <geos/geom/CoordinateSequence.h>
-#include <geos/geom/CoordinateList.h>
-
-#include <memory>
-
-// Forward declarations
-namespace geos {
- namespace geom {
- //class PrecisionModel;
- //class CoordinateSequence;
- class CoordinateList;
- class Geometry;
- }
-}
-
-namespace geos {
-namespace precision { // geos.precision
-
-/** \brief
- * Snaps the vertices and segments of a LineString to another's vertices.
- * Should improve robustness for overlay operations.
- *
- */
-class LineStringSnapper {
-
-public:
-
- LineStringSnapper(const geom::Coordinate::Vect& nSrcPts, double nSnapTol)
- :
- srcPts(nSrcPts),
- snapTolerance(nSnapTol)
- {
- size_t s = srcPts.size();
- isClosed = ( s < 2 || srcPts[0].equals2D(srcPts[s-1]) );
- }
-
- // Snap points are assumed to be all distinct points (a set would be better, uh ?)
- std::auto_ptr<geom::Coordinate::Vect> snapTo(const geom::Coordinate::ConstVect& snapPts);
-
-private:
-
- const geom::Coordinate::Vect& srcPts;
-
- double snapTolerance;
-
- bool isClosed;
-
-
- // Modifies first arg
- void snapVertices(geom::CoordinateList& srcCoords,
- const geom::Coordinate::ConstVect& snapPts);
-
-
- // Returns snapPts.end() if no snap point is close enough (within snapTol distance)
- geom::Coordinate::ConstVect::const_iterator findSnapForVertex(const geom::Coordinate& pt,
- const geom::Coordinate::ConstVect& snapPts);
-
- // Modifies first arg
- void snapSegments(geom::CoordinateList& srcCoords,
- const geom::Coordinate::ConstVect& snapPts);
-
- /// \brief
- /// Finds a src segment which snaps to (is close to) the given snap
- /// point.
- //
- /// Only one segment is determined - this is to prevent
- /// snapping to multiple segments, which would almost certainly cause
- /// invalid geometry to be created.
- /// (The heuristic approach of snapping is really only appropriate
- /// when snap pts snap to a unique spot on the src geometry.)
- ///
- ///
- /// @param from
- /// an iterator to first point of first segment to be checked
- ///
- /// @param too_far
- /// an iterator to last point of last segment to be checked
- ///
- /// @returns too_far if no segment needs snapping
- /// (either none within snapTol distance,
- /// or one fond on the snapPt)
- ///
- geom::CoordinateList::iterator findSegmentToSnap(
- const geom::Coordinate& snapPt,
- geom::CoordinateList::iterator from,
- geom::CoordinateList::iterator too_far);
-
-};
-
-
-} // namespace geos.precision
-} // namespace geos
-
-#endif // GEOS_PRECISION_LINESTRINGSNAPPER_H
-
-/**********************************************************************
- * $Log$
- * Revision 1.1 2006/07/21 17:09:14 strk
- * Added new precision::LineStringSnapper class + test
- * and precision::GeometrySnapper (w/out test)
- *
- **********************************************************************/
Modified: trunk/source/headers/geos/precision/Makefile.am
===================================================================
--- trunk/source/headers/geos/precision/Makefile.am 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/source/headers/geos/precision/Makefile.am 2009-05-05 10:14:39 UTC (rev 2468)
@@ -14,9 +14,7 @@
CommonBitsOp.h \
CommonBitsRemover.h \
EnhancedPrecisionOp.h \
- GeometrySnapper.h \
SimpleGeometryPrecisionReducer.h
noinst_HEADERS = \
- CommonBits.h \
- LineStringSnapper.h
+ CommonBits.h
Modified: trunk/source/operation/overlay/snap/GeometrySnapper.cpp
===================================================================
--- trunk/source/operation/overlay/snap/GeometrySnapper.cpp 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/source/operation/overlay/snap/GeometrySnapper.cpp 2009-05-05 10:14:39 UTC (rev 2468)
@@ -5,6 +5,7 @@
* http://geos.refractions.net
*
* Copyright (C) 2009 Sandro Santilli <strk at keybit.net>
+ * Copyright (C) 2006 Refractions Research Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
@@ -19,22 +20,20 @@
#include <geos/operation/overlay/snap/GeometrySnapper.h>
#include <geos/operation/overlay/snap/LineStringSnapper.h>
-#include <geos/geom/PrecisionModel.h>
-#include <geos/geom/util/GeometryTransformer.h> // SnapTransformer inheritance
-#include <geos/geom/CoordinateSequence.h>
-#include <geos/util/UniqueCoordinateArrayFilter.h>
+#include <geos/geom/util/GeometryTransformer.h> // inherit. of SnapTransformer
+#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/GeometryFactory.h>
+#include <geos/geom/CoordinateSequenceFactory.h>
+#include <geos/geom/PrecisionModel.h>
+#include <geos/util/UniqueCoordinateArrayFilter.h>
+#include <geos/util.h>
-#include <cassert>
-#include <limits> // for numeric_limits
-#include <memory> // for auto_ptr
+#include <vector>
+#include <memory>
+#include <algorithm>
-#include <algorithm> // for std::min
-
-#ifndef GEOS_DEBUG
-#define GEOS_DEBUG 0
-#endif
-
-using namespace std;
+//using namespace std;
using namespace geos::geom;
namespace geos {
@@ -42,55 +41,94 @@
namespace overlay { // geos.operation.overlay
namespace snap { // geos.operation.overlay.snap
-namespace { // anonymous
+const double GeometrySnapper::snapPrecisionFactor = 10e-10;
-class SnapTransformer : public geom::util::GeometryTransformer
-{
+class SnapTransformer: public geos::geom::util::GeometryTransformer {
+
+private:
+
+ double snapTol;
+
+ const Coordinate::ConstVect& snapPts;
+
+ CoordinateSequence::AutoPtr snapLine(
+ const CoordinateSequence* srcPts)
+ {
+ using std::auto_ptr;
+
+ assert(srcPts);
+ assert(srcPts->toVector());
+ LineStringSnapper snapper(*(srcPts->toVector()), snapTol);
+ auto_ptr<Coordinate::Vect> newPts = snapper.snapTo(snapPts);
+
+ const CoordinateSequenceFactory* cfact = factory->getCoordinateSequenceFactory();
+ return auto_ptr<CoordinateSequence>(cfact->create(newPts.release()));
+ }
+
public:
- double snapTolerance;
- const vector<const Coordinate*>& snapPts;
-
- SnapTransformer(double nSnapTolerance,
- const vector<const Coordinate*>& nSnapPts)
+ SnapTransformer(double nSnapTol,
+ const Coordinate::ConstVect& nSnapPts)
:
- snapTolerance(nSnapTolerance),
+ snapTol(nSnapTol),
snapPts(nSnapPts)
{
}
-protected:
-
- virtual CoordinateSequence::AutoPtr transformCoordinates(
- const CoordinateSequence* coords,
- const Geometry* parent)
+ CoordinateSequence::AutoPtr transformCoordinates(
+ const CoordinateSequence* coords,
+ const Geometry* parent)
{
- return snapLine(*coords, snapPts);
+ UNREFERENCED_PARAMETER(parent);
+ return snapLine(coords);
}
-private:
- auto_ptr< CoordinateSequence >
- snapLine(const CoordinateSequence& srcPts,
- const vector<const Coordinate*>& snapPts)
- {
- // TODO: make the LineStringSnapper a private member...
- LineStringSnapper snapper(srcPts, snapTolerance);
-
- return snapper.snapTo(snapPts);
- }
};
-} // anonymous namespace
+/*private*/
+std::auto_ptr<Coordinate::ConstVect>
+GeometrySnapper::extractTargetCoordinates(const Geometry& g)
+{
+ std::auto_ptr<Coordinate::ConstVect> snapPts(new Coordinate::ConstVect());
+ util::UniqueCoordinateArrayFilter filter(*snapPts);
+ g.apply_ro(&filter);
+ // integrity check
+ assert( snapPts->size() <= g.getNumPoints() );
+ return snapPts;
+}
-/* private static */
-const double GeometrySnapper::SNAP_PRECISION_FACTOR = 10e-10;
+/*public*/
+std::auto_ptr<geom::Geometry>
+GeometrySnapper::snapTo(const geom::Geometry& g, double snapTolerance)
+{
+ using std::auto_ptr;
+ using geom::util::GeometryTransformer;
+
+ // Get snap points
+ auto_ptr<Coordinate::ConstVect> snapPts=extractTargetCoordinates(g);
-/* public static */
+ // Apply a SnapTransformer to source geometry
+ // (we need a pointer for dynamic polymorphism)
+ auto_ptr<GeometryTransformer> snapTrans(new SnapTransformer(snapTolerance, *snapPts));
+ return snapTrans->transform(&srcGeom);
+}
+
+/*public static*/
double
-GeometrySnapper::computeOverlaySnapTolerance(const Geometry& g)
+GeometrySnapper::computeSizeBasedSnapTolerance(const geom::Geometry& g)
{
+ const Envelope* env = g.getEnvelopeInternal();
+ double minDimension = std::min(env->getHeight(), env->getWidth());
+ double snapTol = minDimension * snapPrecisionFactor;
+ return snapTol;
+}
+
+/*public static*/
+double
+GeometrySnapper::computeOverlaySnapTolerance(const geom::Geometry& g)
+{
double snapTolerance = computeSizeBasedSnapTolerance(g);
/**
@@ -102,35 +140,26 @@
* the distance from a corner of a precision grid cell
* to the centre point of the cell.
*/
+ assert(g.getPrecisionModel());
const PrecisionModel& pm = *(g.getPrecisionModel());
- if (pm.getType() == PrecisionModel::FIXED) {
+ if (pm.getType() == PrecisionModel::FIXED)
+ {
double fixedSnapTol = (1 / pm.getScale()) * 2 / 1.415;
- if (fixedSnapTol > snapTolerance)
+ if ( fixedSnapTol > snapTolerance )
snapTolerance = fixedSnapTol;
}
return snapTolerance;
}
-/* public static */
+/*public static*/
double
-GeometrySnapper::computeSizeBasedSnapTolerance(const geom::Geometry& g)
+GeometrySnapper::computeOverlaySnapTolerance(const geom::Geometry& g1,
+ const geom::Geometry& g2)
{
- const Envelope& env = *(g.getEnvelopeInternal());
- double minDimension = std::min(env.getHeight(), env.getWidth());
- double snapTol = minDimension * SNAP_PRECISION_FACTOR;
- return snapTol;
+ return std::min(computeOverlaySnapTolerance(g1), computeOverlaySnapTolerance(g2));
}
/* public static */
-double
-GeometrySnapper::computeOverlaySnapTolerance(const geom::Geometry& g0,
- const geom::Geometry& g1)
-{
- return std::min(computeOverlaySnapTolerance(g0),
- computeOverlaySnapTolerance(g1));
-}
-
-/* public static */
void
GeometrySnapper::snap(const geom::Geometry& g0,
const geom::Geometry& g1,
@@ -152,30 +181,9 @@
// cout << *snapGeom.first << endl;
// cout << *snapGeom.second << endl;
- //return snapGeom;
}
-/*public*/
-GeometrySnapper::GeomPtr
-GeometrySnapper::snapTo(const geom::Geometry& snapGeom, double snapTolerance)
-{
- vector<const Coordinate*> snapPts;
- extractTargetCoordinates(snapGeom, snapPts);
- SnapTransformer snapTrans(snapTolerance, snapPts);
- return snapTrans.transform(&srcGeom);
-}
-
-/*public*/
-void
-GeometrySnapper::extractTargetCoordinates(const Geometry& g,
- vector<const Coordinate*>& target)
-{
- util::UniqueCoordinateArrayFilter filter(target);
- g.apply_ro(&filter);
-}
-
-
} // namespace geos.operation.snap
} // namespace geos.operation.overlay
} // namespace geos.operation
Modified: trunk/source/operation/overlay/snap/LineStringSnapper.cpp
===================================================================
--- trunk/source/operation/overlay/snap/LineStringSnapper.cpp 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/source/operation/overlay/snap/LineStringSnapper.cpp 2009-05-05 10:14:39 UTC (rev 2468)
@@ -5,6 +5,7 @@
* http://geos.refractions.net
*
* Copyright (C) 2009 Sandro Santilli <strk at keybit.net>
+ * Copyright (C) 2006 Refractions Research Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
@@ -13,22 +14,31 @@
*
***********************************************************************
*
- * Last port: operation/overlay/snap/LineStringSnapper.java rev 1.5 (JTS-1.10)
+ * Last port: operation/overlay/snap/lineStringSnapper.java rev 1.5 (JTS-1.10)
*
**********************************************************************/
#include <geos/operation/overlay/snap/LineStringSnapper.h>
-#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateList.h>
+#include <geos/util/UniqueCoordinateArrayFilter.h>
+#include <geos/geom/LineSegment.h>
-#include <cassert>
-#include <limits> // for numeric_limits
-#include <memory> // for auto_ptr
+#include <vector>
+#include <memory>
#ifndef GEOS_DEBUG
#define GEOS_DEBUG 0
#endif
-using namespace std;
+#if GEOS_DEBUG
+#include <iostream>
+using std::cerr;
+using std::endl;
+#endif
+
+//using namespace std;
using namespace geos::geom;
namespace geos {
@@ -37,177 +47,216 @@
namespace snap { // geos.operation.overlay.snap
/*public*/
-auto_ptr<CoordinateSequence>
-LineStringSnapper::snapTo(const CoordinateSequence& snapPts)
+std::auto_ptr<Coordinate::Vect>
+LineStringSnapper::snapTo(const geom::Coordinate::ConstVect& snapPts)
{
- auto_ptr<CoordinateSequence> coordList(snapPts.clone());
+ geom::CoordinateList coordList(srcPts);
- snapVertices(*coordList, snapPts);
- snapSegments(*coordList, snapPts);
+ snapVertices(coordList, snapPts);
+ snapSegments(coordList, snapPts);
- return coordList;
-}
+ return coordList.toCoordinateArray();
+}
-/*public*/
-auto_ptr<CoordinateSequence>
-LineStringSnapper::snapTo(const vector<const Coordinate*>& snapPts)
+/*private*/
+void
+LineStringSnapper::snapVertices(geom::CoordinateList& srcCoords,
+ const geom::Coordinate::ConstVect& snapPts)
{
- auto_ptr<CoordinateSequence> coordList(srcPts.clone());
+ using geom::CoordinateList;
- snapVertices(*coordList, snapPts);
- snapSegments(*coordList, snapPts);
+ geom::Coordinate::ConstVect::const_iterator not_found = snapPts.end();
- return coordList;
-}
+ // try snapping vertices
+ // assume src list has a closing point (is a ring)
+ CoordinateList::iterator it = srcCoords.begin();
+ CoordinateList::iterator end = srcCoords.end();
+ CoordinateList::iterator last = end; --last;
+ for ( ; it != end; ++it )
+ {
+ Coordinate& srcPt = *it;
-/*private*/
-void
-LineStringSnapper::snapVertices(geom::CoordinateSequence& srcCoords,
- const geom::CoordinateSequence& snapPts)
-{
- // try snapping vertices
- // assume src list has a closing point (is a ring)
- for (size_t i = 0; i < srcCoords.size() - 1; i++) {
- const Coordinate& srcPt = srcCoords.getAt(i);
- const Coordinate* snapVert = findSnapForVertex(srcPt, snapPts);
- if (snapVert != NULL) {
- // update src with snap pt
- srcCoords.setAt(*snapVert, i);
- // keep final closing point in synch (rings only)
- if (i == 0 && isClosed)
- srcCoords.setAt(*snapVert, srcCoords.size() - 1);
- }
- }
-}
+#if GEOS_DEBUG
+cerr << "Checking for a snap for source coordinate " << srcPt << endl;
+#endif
-/*private*/
-void
-LineStringSnapper::snapVertices(geom::CoordinateSequence& srcCoords,
- const vector<const Coordinate*>& snapPts)
-{
- // try snapping vertices
- // assume src list has a closing point (is a ring)
- for (size_t i = 0; i < srcCoords.size() - 1; i++) {
- const Coordinate& srcPt = srcCoords.getAt(i);
- const Coordinate* snapVert = findSnapForVertex(srcPt, snapPts);
- if (snapVert != NULL) {
- // update src with snap pt
- srcCoords.setAt(*snapVert, i);
- // keep final closing point in synch (rings only)
- if (i == 0 && isClosed)
- srcCoords.setAt(*snapVert, srcCoords.size() - 1);
- }
- }
-}
+ geom::Coordinate::ConstVect::const_iterator found = findSnapForVertex(srcPt, snapPts);
+ if ( found == not_found )
+ { // no snaps found (or no need to snap)
+#if GEOS_DEBUG
+cerr << "No snap found" << endl;
+#endif
+ continue;
+ }
-/*private*/
-const geom::Coordinate*
-LineStringSnapper::findSnapForVertex(const geom::Coordinate& pt,
- const geom::CoordinateSequence& snapPts)
-{
- for (size_t i = 0; i < snapPts.size(); i++) {
- // if point is already equal to a src pt, don't snap
- if (pt.equals2D(snapPts[i]))
- return 0;
- if (pt.distance(snapPts[i]) < snapTolerance)
- return &(snapPts[i]);
- }
- return 0;
-}
+ assert(*found);
+ const Coordinate& snapPt = *(*found);
+
+#if GEOS_DEBUG
+cerr << "Found snap point " << snapPt << endl;
+#endif
-/*private*/
-const geom::Coordinate*
-LineStringSnapper::findSnapForVertex(const geom::Coordinate& pt,
- const vector<const Coordinate*>& snapPts)
-{
- for (size_t i = 0; i < snapPts.size(); i++) {
- // if point is already equal to a src pt, don't snap
- if (pt.equals2D(*snapPts[i]))
- return 0;
- if (pt.distance(*snapPts[i]) < snapTolerance)
- return snapPts[i];
- }
- return 0;
+ // update src with snap pt
+ *it = snapPt;
+
+#if GEOS_DEBUG
+cerr << "Source point became " << srcPt << endl;
+#endif
+
+ // keep final closing point in synch (rings only)
+ if (it == srcCoords.begin() && isClosed)
+ {
+ *last = snapPt;
+ }
+ }
}
/*private*/
-void
-LineStringSnapper::snapSegments(geom::CoordinateSequence& srcCoords,
- const geom::CoordinateSequence& snapPts)
+Coordinate::ConstVect::const_iterator
+LineStringSnapper::findSnapForVertex(const Coordinate& pt,
+ const Coordinate::ConstVect& snapPts)
{
- int distinctPtCount = snapPts.size();
- // check for duplicate snap pts.
- // Need to do this better - need to check all points for dups (using a Set?)
- if (snapPts[0].equals2D(snapPts[snapPts.size() - 1]))
- distinctPtCount = snapPts.size() - 1;
+ // TODO: use std::find_if
+ Coordinate::ConstVect::const_iterator end=snapPts.end();
+ for ( Coordinate::ConstVect::const_iterator
+ it=snapPts.begin();
+ it != end;
+ ++it)
+ {
+ assert(*it);
+ const Coordinate& snapPt = *(*it);
- for (int i = 0; i < distinctPtCount; i++) {
- const Coordinate& snapPt = snapPts[i];
- int index = findSegmentIndexToSnap(snapPt, srcCoords);
- /**
- * If a segment to snap to was found, "crack" it at the snap pt.
- * The new pt is inserted immediately into the src segment list,
- * so that subsequent snapping will take place on the latest segments.
- * Duplicate points are not added.
- */
- if (index >= 0) {
- srcCoords.add(index + 1, snapPt, false);
- }
- }
+#if GEOS_DEBUG
+cerr << " misuring distance between snap point " << snapPt << " and source point " << pt << endl;
+#endif
+
+ // shouldn't we look for *all* segments to be snapped rather then a single one?
+ if ( snapPt.equals2D(pt) )
+ {
+#if GEOS_DEBUG
+cerr << " points are equal, returning not-found " << endl;
+#endif
+ return end;
+ //continue;
+ }
+
+ double dist = snapPt.distance(pt);
+ if ( dist < snapTolerance )
+ {
+#if GEOS_DEBUG
+cerr << " points are within distance (" << dist << ") returning iterator to snap point" << endl;
+#endif
+ return it;
+ }
+ }
+
+#if GEOS_DEBUG
+cerr << " No snap point within distance, returning not-found" << endl;
+#endif
+
+ return end;
}
+
/*private*/
void
-LineStringSnapper::snapSegments(geom::CoordinateSequence& srcCoords,
- const vector<const Coordinate*>& snapPts)
+LineStringSnapper::snapSegments(geom::CoordinateList& srcCoords,
+ const geom::Coordinate::ConstVect& snapPts)
{
- int distinctPtCount = snapPts.size();
- // check for duplicate snap pts.
- // Need to do this better - need to check all points for dups (using a Set?)
- if (snapPts[0]->equals2D(*snapPts[snapPts.size() - 1]))
- distinctPtCount = snapPts.size() - 1;
+#if GEOS_DEBUG
+cerr << " Snapping segment from: " << srcCoords << endl;
+#endif
- for (int i = 0; i < distinctPtCount; i++) {
- const Coordinate& snapPt = *(snapPts[i]);
- int index = findSegmentIndexToSnap(snapPt, srcCoords);
- /**
- * If a segment to snap to was found, "crack" it at the snap pt.
- * The new pt is inserted immediately into the src segment list,
- * so that subsequent snapping will take place on the latest segments.
- * Duplicate points are not added.
- */
- if (index >= 0) {
- srcCoords.add(index + 1, snapPt, false);
- }
- }
+ for ( Coordinate::ConstVect::const_iterator
+ it=snapPts.begin(), end=snapPts.end();
+ it != end;
+ ++it)
+ {
+ assert(*it);
+ const Coordinate& snapPt = *(*it);
+
+#if GEOS_DEBUG
+cerr << "Checking for a segment to snap to snapPt " << snapPt << endl;
+#endif
+
+ // shouldn't we look for *all* segments to be snapped
+ // rather then a single one?
+ CoordinateList::iterator too_far = srcCoords.end(); --too_far;
+ CoordinateList::iterator segpos =
+ findSegmentToSnap(snapPt, srcCoords.begin(), too_far);
+ if ( segpos == too_far)
+ {
+#if GEOS_DEBUG
+cerr << " No segment to snap" << endl;
+#endif
+ continue;
+ }
+#if GEOS_DEBUG
+cerr << " Segment to be snapped found, inserting point" << endl;
+#endif
+ // insert must happen one-past first point (before next point)
+ ++segpos;
+ srcCoords.insert(segpos, snapPt);
+ }
+
+#if GEOS_DEBUG
+cerr << " After segment snapping, srcCoors are: " << srcCoords << endl;
+#endif
+
}
/*private*/
-int
-LineStringSnapper::findSegmentIndexToSnap(const geom::Coordinate& snapPt,
- const geom::CoordinateSequence& srcCoords)
+CoordinateList::iterator
+LineStringSnapper::findSegmentToSnap(
+ const Coordinate& snapPt,
+ CoordinateList::iterator from,
+ CoordinateList::iterator too_far)
{
- double minDist = numeric_limits<double>::max();
- int snapIndex = -1;
- for (size_t i = 0; i < srcCoords.size() - 1; i++) {
- seg.p0 = srcCoords.getAt(i);
- seg.p1 = srcCoords.getAt(i + 1);
+ LineSegment seg;
+ double minDist = snapTolerance+1; // make sure the first closer then
+ // snapTolerance is accepted
+ CoordinateList::iterator match=too_far;
- /**
- * If the snap pt is already in the src list, don't snap
- */
- if (seg.p0.equals2D(snapPt) || seg.p1.equals2D(snapPt))
- return -1;
+ // TODO: use std::find_if
+ for ( ; from != too_far; ++from)
+ {
+ seg.p0 = *from;
+ CoordinateList::iterator to = from;
+ ++to;
+ seg.p1 = *to;
- double dist = seg.distance(snapPt);
- if (dist < snapTolerance && dist < minDist) {
- minDist = dist;
- snapIndex = i;
- }
- }
- return snapIndex;
+#if GEOS_DEBUG
+cerr << " Checking segment " << seg << " for snapping against point " << snapPt << endl;
+#endif
+
+ if ( seg.p0.equals2D(snapPt) || seg.p1.equals2D(snapPt) )
+ {
+
+#if GEOS_DEBUG
+cerr << " One of segment endpoints equal snap point, returning too_far" << endl;
+#endif
+ // If the snap pt is already in the src list,
+ // don't snap
+ return too_far;
+ }
+
+ double dist = seg.distance(snapPt);
+#if GEOS_DEBUG
+cerr << " dist=" << dist << " minDist=" << minDist << " snapTolerance=" << snapTolerance << endl;
+#endif
+ if ( dist < minDist && dist < snapTolerance )
+ {
+#if GEOS_DEBUG
+cerr << " Segment/snapPt distance within tolerance and closer then previous match (" << dist << ") " << endl;
+#endif
+ match = from;
+ minDist = dist;
+ }
+ }
+
+ return match;
}
} // namespace geos.operation.snap
Modified: trunk/source/operation/overlay/snap/SnapOverlayOp.cpp
===================================================================
--- trunk/source/operation/overlay/snap/SnapOverlayOp.cpp 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/source/operation/overlay/snap/SnapOverlayOp.cpp 2009-05-05 10:14:39 UTC (rev 2468)
@@ -20,7 +20,7 @@
#include <geos/operation/overlay/snap/SnapOverlayOp.h>
#include <geos/operation/overlay/snap/GeometrySnapper.h>
#include <geos/precision/CommonBitsRemover.h>
-//#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/Geometry.h>
#include <cassert>
#include <limits> // for numeric_limits
Deleted: trunk/source/precision/GeometrySnapper.cpp
===================================================================
--- trunk/source/precision/GeometrySnapper.cpp 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/source/precision/GeometrySnapper.cpp 2009-05-05 10:14:39 UTC (rev 2468)
@@ -1,170 +0,0 @@
-/**********************************************************************
- * $Id$
- *
- * GEOS - Geometry Engine Open Source
- * http://geos.refractions.net
- *
- * Copyright (C) 2006 Refractions Research Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU Lesser General Public Licence as published
- * by the Free Software Foundation.
- * See the COPYING file for more information.
- *
- ***********************************************************************
- *
- * Last port: operation/overlay/snap/GeometrySnapper.java rev. 1.6
- * (we should move in GEOS too, probably)
- *
- **********************************************************************/
-
-#include <geos/precision/GeometrySnapper.h>
-#include <geos/precision/LineStringSnapper.h>
-#include <geos/geom/util/GeometryTransformer.h> // inherit. of SnapTransformer
-#include <geos/geom/CoordinateSequence.h>
-#include <geos/geom/Coordinate.h>
-#include <geos/geom/GeometryFactory.h>
-#include <geos/geom/CoordinateSequenceFactory.h>
-#include <geos/geom/PrecisionModel.h>
-#include <geos/util/UniqueCoordinateArrayFilter.h>
-#include <geos/util.h>
-
-#include <vector>
-#include <memory>
-#include <algorithm>
-
-//using namespace std;
-using namespace geos::geom;
-
-namespace geos {
-namespace precision { // geos.precision
-
-const double GeometrySnapper::snapPrecisionFactor = 10e-10;
-
-class SnapTransformer: public geos::geom::util::GeometryTransformer {
-
-private:
-
- double snapTol;
-
- const Coordinate::ConstVect& snapPts;
-
- CoordinateSequence::AutoPtr snapLine(
- const CoordinateSequence* srcPts)
- {
- using std::auto_ptr;
-
- assert(srcPts);
- assert(srcPts->toVector());
- LineStringSnapper snapper(*(srcPts->toVector()), snapTol);
- auto_ptr<Coordinate::Vect> newPts = snapper.snapTo(snapPts);
-
- const CoordinateSequenceFactory* cfact = factory->getCoordinateSequenceFactory();
- return auto_ptr<CoordinateSequence>(cfact->create(newPts.release()));
- }
-
-public:
-
- SnapTransformer(double nSnapTol,
- const Coordinate::ConstVect& nSnapPts)
- :
- snapTol(nSnapTol),
- snapPts(nSnapPts)
- {
- }
-
- CoordinateSequence::AutoPtr transformCoordinates(
- const CoordinateSequence* coords,
- const Geometry* parent)
- {
- UNREFERENCED_PARAMETER(parent);
- return snapLine(coords);
- }
-
-
-};
-
-/*private*/
-std::auto_ptr<Coordinate::ConstVect>
-GeometrySnapper::extractTargetCoordinates(const Geometry& g)
-{
- std::auto_ptr<Coordinate::ConstVect> snapPts(new Coordinate::ConstVect());
- util::UniqueCoordinateArrayFilter filter(*snapPts);
- g.apply_ro(&filter);
- // integrity check
- assert( snapPts->size() <= g.getNumPoints() );
- return snapPts;
-}
-
-/*public*/
-std::auto_ptr<geom::Geometry>
-GeometrySnapper::snapTo(const geom::Geometry& g, double snapTolerance)
-{
-
- using std::auto_ptr;
- using geom::util::GeometryTransformer;
-
- // Get snap points
- auto_ptr<Coordinate::ConstVect> snapPts=extractTargetCoordinates(g);
-
- // Apply a SnapTransformer to source geometry
- // (we need a pointer for dynamic polymorphism)
- auto_ptr<GeometryTransformer> snapTrans(new SnapTransformer(snapTolerance, *snapPts));
- return snapTrans->transform(&srcGeom);
-}
-
-/*public static*/
-double
-GeometrySnapper::computeSizeBasedSnapTolerance(const geom::Geometry& g)
-{
- const Envelope* env = g.getEnvelopeInternal();
- double minDimension = std::min(env->getHeight(), env->getWidth());
- double snapTol = minDimension * snapPrecisionFactor;
- return snapTol;
-}
-
-/*public static*/
-double
-GeometrySnapper::computeOverlaySnapTolerance(const geom::Geometry& g)
-{
- double snapTolerance = computeSizeBasedSnapTolerance(g);
-
- /*
- * Overlay is carried out in most precise precision model of inputs.
- * If this precision model is fixed, then the snap tolerance
- * must reflect the grid size.
- * Precisely, the snap tolerance should be at least
- * the distance from a corner of a precision grid cell
- * to the centre point of the cell.
- */
- assert(g.getPrecisionModel());
- const PrecisionModel& pm = *(g.getPrecisionModel());
- if (pm.getType() == PrecisionModel::FIXED)
- {
- double fixedSnapTol = (1 / pm.getScale()) * 2 / 1.415;
- if ( fixedSnapTol > snapTolerance )
- snapTolerance = fixedSnapTol;
- }
- return snapTolerance;
-}
-
-/*public static*/
-double
-GeometrySnapper::computeOverlaySnapTolerance(const geom::Geometry& g1,
- const geom::Geometry& g2)
-{
- return std::min(computeOverlaySnapTolerance(g1), computeOverlaySnapTolerance(g2));
-}
-
-
-} // namespace geos.precision
-} // namespace geos
-
-/**********************************************************************
- * $Log$
- * Revision 1.1 2006/07/21 17:09:14 strk
- * Added new precision::LineStringSnapper class + test
- * and precision::GeometrySnapper (w/out test)
- *
- **********************************************************************/
-
Deleted: trunk/source/precision/LineStringSnapper.cpp
===================================================================
--- trunk/source/precision/LineStringSnapper.cpp 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/source/precision/LineStringSnapper.cpp 2009-05-05 10:14:39 UTC (rev 2468)
@@ -1,273 +0,0 @@
-/**********************************************************************
- * $Id$
- *
- * GEOS - Geometry Engine Open Source
- * http://geos.refractions.net
- *
- * Copyright (C) 2006 Refractions Research Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU Lesser General Public Licence as published
- * by the Free Software Foundation.
- * See the COPYING file for more information.
- *
- ***********************************************************************
- *
- * Last port: operation/overlay/snap/lineStringSnapper.java rev. 1.1
- * (we should move in GEOS too, probably)
- *
- **********************************************************************/
-
-#include <geos/precision/LineStringSnapper.h>
-#include <geos/geom/CoordinateSequence.h>
-#include <geos/geom/Coordinate.h>
-#include <geos/geom/CoordinateList.h>
-#include <geos/util/UniqueCoordinateArrayFilter.h>
-#include <geos/geom/LineSegment.h>
-
-#include <vector>
-#include <memory>
-
-#ifndef GEOS_DEBUG
-#define GEOS_DEBUG 0
-#endif
-
-#if GEOS_DEBUG
-#include <iostream>
-using std::cerr;
-using std::endl;
-#endif
-
-//using namespace std;
-using namespace geos::geom;
-
-namespace geos {
-namespace precision { // geos.precision
-
-/*public*/
-std::auto_ptr<Coordinate::Vect>
-LineStringSnapper::snapTo(const geom::Coordinate::ConstVect& snapPts)
-{
- geom::CoordinateList coordList(srcPts);
-
- snapVertices(coordList, snapPts);
- snapSegments(coordList, snapPts);
-
- return coordList.toCoordinateArray();
-}
-
-/*private*/
-void
-LineStringSnapper::snapVertices(geom::CoordinateList& srcCoords,
- const geom::Coordinate::ConstVect& snapPts)
-{
- using geom::CoordinateList;
-
- geom::Coordinate::ConstVect::const_iterator not_found = snapPts.end();
-
- // try snapping vertices
- // assume src list has a closing point (is a ring)
- CoordinateList::iterator it = srcCoords.begin();
- CoordinateList::iterator end = srcCoords.end();
- CoordinateList::iterator last = end; --last;
- for ( ; it != end; ++it )
- {
- Coordinate& srcPt = *it;
-
-#if GEOS_DEBUG
-cerr << "Checking for a snap for source coordinate " << srcPt << endl;
-#endif
-
- geom::Coordinate::ConstVect::const_iterator found = findSnapForVertex(srcPt, snapPts);
- if ( found == not_found )
- { // no snaps found (or no need to snap)
-#if GEOS_DEBUG
-cerr << "No snap found" << endl;
-#endif
- continue;
- }
-
- assert(*found);
- const Coordinate& snapPt = *(*found);
-
-#if GEOS_DEBUG
-cerr << "Found snap point " << snapPt << endl;
-#endif
-
- // update src with snap pt
- *it = snapPt;
-
-#if GEOS_DEBUG
-cerr << "Source point became " << srcPt << endl;
-#endif
-
- // keep final closing point in synch (rings only)
- if (it == srcCoords.begin() && isClosed)
- {
- *last = snapPt;
- }
- }
-}
-
-/*private*/
-Coordinate::ConstVect::const_iterator
-LineStringSnapper::findSnapForVertex(const Coordinate& pt,
- const Coordinate::ConstVect& snapPts)
-{
-
- // TODO: use std::find_if
- Coordinate::ConstVect::const_iterator end=snapPts.end();
- for ( Coordinate::ConstVect::const_iterator
- it=snapPts.begin();
- it != end;
- ++it)
- {
- assert(*it);
- const Coordinate& snapPt = *(*it);
-
-#if GEOS_DEBUG
-cerr << " misuring distance between snap point " << snapPt << " and source point " << pt << endl;
-#endif
-
- // shouldn't we look for *all* segments to be snapped rather then a single one?
- if ( snapPt.equals2D(pt) )
- {
-#if GEOS_DEBUG
-cerr << " points are equal, returning not-found " << endl;
-#endif
- return end;
- //continue;
- }
-
- double dist = snapPt.distance(pt);
- if ( dist < snapTolerance )
- {
-#if GEOS_DEBUG
-cerr << " points are within distance (" << dist << ") returning iterator to snap point" << endl;
-#endif
- return it;
- }
- }
-
-#if GEOS_DEBUG
-cerr << " No snap point within distance, returning not-found" << endl;
-#endif
-
- return end;
-}
-
-
-/*private*/
-void
-LineStringSnapper::snapSegments(geom::CoordinateList& srcCoords,
- const geom::Coordinate::ConstVect& snapPts)
-{
-
-#if GEOS_DEBUG
-cerr << " Snapping segment from: " << srcCoords << endl;
-#endif
-
- for ( Coordinate::ConstVect::const_iterator
- it=snapPts.begin(), end=snapPts.end();
- it != end;
- ++it)
- {
- assert(*it);
- const Coordinate& snapPt = *(*it);
-
-#if GEOS_DEBUG
-cerr << "Checking for a segment to snap to snapPt " << snapPt << endl;
-#endif
-
- // shouldn't we look for *all* segments to be snapped
- // rather then a single one?
- CoordinateList::iterator too_far = srcCoords.end(); --too_far;
- CoordinateList::iterator segpos =
- findSegmentToSnap(snapPt, srcCoords.begin(), too_far);
- if ( segpos == too_far)
- {
-#if GEOS_DEBUG
-cerr << " No segment to snap" << endl;
-#endif
- continue;
- }
-#if GEOS_DEBUG
-cerr << " Segment to be snapped found, inserting point" << endl;
-#endif
- // insert must happen one-past first point (before next point)
- ++segpos;
- srcCoords.insert(segpos, snapPt);
- }
-
-#if GEOS_DEBUG
-cerr << " After segment snapping, srcCoors are: " << srcCoords << endl;
-#endif
-
-}
-
-/*private*/
-CoordinateList::iterator
-LineStringSnapper::findSegmentToSnap(
- const Coordinate& snapPt,
- CoordinateList::iterator from,
- CoordinateList::iterator too_far)
-{
- LineSegment seg;
- double minDist = snapTolerance+1; // make sure the first closer then
- // snapTolerance is accepted
- CoordinateList::iterator match=too_far;
-
- // TODO: use std::find_if
- for ( ; from != too_far; ++from)
- {
- seg.p0 = *from;
- CoordinateList::iterator to = from;
- ++to;
- seg.p1 = *to;
-
-#if GEOS_DEBUG
-cerr << " Checking segment " << seg << " for snapping against point " << snapPt << endl;
-#endif
-
- if ( seg.p0.equals2D(snapPt) || seg.p1.equals2D(snapPt) )
- {
-
-#if GEOS_DEBUG
-cerr << " One of segment endpoints equal snap point, returning too_far" << endl;
-#endif
- // If the snap pt is already in the src list,
- // don't snap
- return too_far;
- }
-
- double dist = seg.distance(snapPt);
-#if GEOS_DEBUG
-cerr << " dist=" << dist << " minDist=" << minDist << " snapTolerance=" << snapTolerance << endl;
-#endif
- if ( dist < minDist && dist < snapTolerance )
- {
-#if GEOS_DEBUG
-cerr << " Segment/snapPt distance within tolerance and closer then previous match (" << dist << ") " << endl;
-#endif
- match = from;
- minDist = dist;
- }
- }
-
- return match;
-}
-
-} // namespace geos.precision
-} // namespace geos
-
-/**********************************************************************
- * $Log$
- * Revision 1.2 2006/07/21 17:59:05 strk
- * Fixed preprocessor directive use
- *
- * Revision 1.1 2006/07/21 17:09:14 strk
- * Added new precision::LineStringSnapper class + test
- * and precision::GeometrySnapper (w/out test)
- *
- **********************************************************************/
-
Modified: trunk/source/precision/Makefile.am
===================================================================
--- trunk/source/precision/Makefile.am 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/source/precision/Makefile.am 2009-05-05 10:14:39 UTC (rev 2468)
@@ -8,8 +8,6 @@
CommonBits.cpp \
CommonBitsOp.cpp \
CommonBitsRemover.cpp \
- GeometrySnapper.cpp \
- LineStringSnapper.cpp \
EnhancedPrecisionOp.cpp \
SimpleGeometryPrecisionReducer.cpp
Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/tests/unit/Makefile.am 2009-05-05 10:14:39 UTC (rev 2468)
@@ -70,12 +70,12 @@
operation/overlay/validate/FuzzyPointLocatorTest.cpp \
operation/overlay/validate/OffsetPointGeneratorTest.cpp \
operation/overlay/validate/OverlayResultValidatorTest.cpp \
+ operation/overlay/snap/GeometrySnapperTest.cpp \
+ operation/overlay/snap/LineStringSnapperTest.cpp \
operation/union/CascadedPolygonUnionTest.cpp \
operation/valid/IsValidTest.cpp \
operation/valid/ValidClosedRingTest.cpp \
operation/valid/ValidSelfTouchingRingFormingHoleTest.cpp \
- precision/GeometrySnapperTest.cpp \
- precision/LineStringSnapperTest.cpp \
precision/SimpleGeometryPrecisionReducerTest.cpp \
simplify/DouglasPeuckerSimplifierTest.cpp \
simplify/TopologyPreservingSimplifierTest.cpp \
Copied: trunk/tests/unit/operation/overlay/snap/GeometrySnapperTest.cpp (from rev 2455, trunk/tests/unit/precision/GeometrySnapperTest.cpp)
===================================================================
--- trunk/tests/unit/operation/overlay/snap/GeometrySnapperTest.cpp (rev 0)
+++ trunk/tests/unit/operation/overlay/snap/GeometrySnapperTest.cpp 2009-05-05 10:14:39 UTC (rev 2468)
@@ -0,0 +1,97 @@
+// $Id$
+//
+// Test Suite for geos::operation::overlay::snap::GeometrySnapper class.
+
+// tut
+#include <tut.hpp>
+// geos
+#include <geos/operation/overlay/snap/GeometrySnapper.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/GeometryFactory.h>
+#include <geos/io/WKTReader.h>
+// std
+#include <memory>
+#include <string>
+#include <vector>
+
+namespace tut
+{
+ //
+ // Test Group
+ //
+
+ // Common data used by tests
+ struct test_geometrysnapper_data
+ {
+ typedef std::auto_ptr<geos::geom::Geometry> GeomAutoPtr;
+
+ geos::geom::GeometryFactory factory;
+
+ geos::io::WKTReader reader;
+
+ GeomAutoPtr src;
+
+ geos::operation::overlay::snap::GeometrySnapper snapper;
+
+ test_geometrysnapper_data()
+ :
+ factory(), // initialize before use!
+ reader(&factory),
+ src(reader.read(
+ "POLYGON ((0 0, 0 100, 100 100, 100 0, 0 0))"
+ )),
+ snapper( *(src.get()) )
+
+ {
+ }
+ };
+
+ typedef test_group<test_geometrysnapper_data> group;
+ typedef group::object object;
+
+ group test_geometrysnapper_group("geos::operation::overlay::snap::GeometrySnapper");
+
+ //
+ // Test Cases
+ //
+
+ // Test vertices snapping
+ template<>
+ template<>
+ void object::test<1>()
+ {
+ GeomAutoPtr snap(reader.read(
+ "MULTIPOINT ((0 0), (0 100.0000001), (100 100), (100 0))"
+ ));
+
+ GeomAutoPtr expected(reader.read(
+ "POLYGON ((0 0, 0 100.0000001, 100 100, 100 0, 0 0))"
+ ));
+
+ GeomAutoPtr ret(snapper.snapTo( *(snap.get()), 0.000001 ));
+
+ ensure( ret->equalsExact(expected.get(),0) );
+
+ }
+
+ // Test vertices snapping
+ template<>
+ template<>
+ void object::test<2>()
+ {
+ GeomAutoPtr snap(reader.read(
+ "MULTIPOINT ((0.0000001 50))"
+ ));
+
+ GeomAutoPtr expected(reader.read(
+ "POLYGON ((0 0, 0.0000001 50, 0 100, 100 100, 100 0, 0 0))"
+ ));
+
+ GeomAutoPtr ret(snapper.snapTo( *(snap.get()), 0.000001 ));
+
+ ensure( ret->equalsExact(expected.get(),0) );
+ }
+
+
+
+} // namespace tut
Property changes on: trunk/tests/unit/operation/overlay/snap/GeometrySnapperTest.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: trunk/tests/unit/operation/overlay/snap/LineStringSnapperTest.cpp (from rev 2455, trunk/tests/unit/precision/LineStringSnapperTest.cpp)
===================================================================
--- trunk/tests/unit/operation/overlay/snap/LineStringSnapperTest.cpp (rev 0)
+++ trunk/tests/unit/operation/overlay/snap/LineStringSnapperTest.cpp 2009-05-05 10:14:39 UTC (rev 2468)
@@ -0,0 +1,115 @@
+// $Id$
+//
+// Test Suite for geos::operation::overlay::snap::LineStringSnapper class.
+
+// tut
+#include <tut.hpp>
+// geos
+#include <geos/operation/overlay/snap/LineStringSnapper.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateList.h>
+#include <geos/geom/CoordinateArraySequence.h>
+// std
+#include <string>
+#include <vector>
+
+namespace tut
+{
+ //
+ // Test Group
+ //
+
+ // Common data used by tests
+ struct test_linestringsnapper_data
+ {
+
+ test_linestringsnapper_data() {}
+ };
+
+ typedef test_group<test_linestringsnapper_data> group;
+ typedef group::object object;
+
+ group test_linestringsnapper_group("geos::operation::overlay::snap::LineStringSnapper");
+
+ //
+ // Test Cases
+ //
+
+ // Test vertices snapping
+ template<>
+ template<>
+ void object::test<1>()
+ {
+ using geos::geom::Coordinate;
+ using geos::operation::overlay::snap::LineStringSnapper;
+
+ typedef std::auto_ptr<Coordinate::Vect> CoordsVectAptr;
+
+
+ // source coordinates
+ Coordinate src_a(0, 0);
+ Coordinate src_b(10, 10);
+
+ // snap coordinates
+ Coordinate snp_a(0.1, 0);
+ Coordinate snp_b(10, 10.1);
+
+ Coordinate::Vect srcCoords;
+ srcCoords.push_back( src_a );
+ srcCoords.push_back( src_b );
+
+ Coordinate::ConstVect snpCoords;
+ snpCoords.push_back( &snp_a );
+ snpCoords.push_back( &snp_b );
+
+ LineStringSnapper snapper(srcCoords, 0.4);
+
+ CoordsVectAptr ret(snapper.snapTo(snpCoords));
+
+ // both points should have been snapped
+ ensure_equals(ret->operator[](0), snp_a);
+ ensure_equals(ret->operator[](1), snp_b);
+
+ }
+
+ // Test segment snapping
+ template<>
+ template<>
+ void object::test<2>()
+ {
+ using geos::geom::Coordinate;
+ using geos::operation::overlay::snap::LineStringSnapper;
+
+ typedef std::auto_ptr<Coordinate::Vect> CoordsVectAptr;
+
+
+ // source coordinates
+ Coordinate src_a(0, 0);
+ Coordinate src_b(10, 10);
+
+ // snap coordinates
+ Coordinate snp_a(0.4, 0);
+ Coordinate snp_b(10, 10.4);
+
+ Coordinate::Vect srcCoords;
+ srcCoords.push_back( src_a );
+ srcCoords.push_back( src_b );
+
+ Coordinate::ConstVect snpCoords;
+ snpCoords.push_back( &snp_a );
+ snpCoords.push_back( &snp_b );
+
+ LineStringSnapper snapper(srcCoords, 0.3);
+
+ CoordsVectAptr ret(snapper.snapTo(snpCoords));
+
+ // snap point a should be inserted
+ ensure_equals(ret->size(), 3u);
+ ensure_equals(ret->operator[](0), src_a);
+ ensure_equals(ret->operator[](1), snp_a);
+ ensure_equals(ret->operator[](2), src_b);
+
+ }
+
+
+} // namespace tut
Property changes on: trunk/tests/unit/operation/overlay/snap/LineStringSnapperTest.cpp
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Deleted: trunk/tests/unit/precision/GeometrySnapperTest.cpp
===================================================================
--- trunk/tests/unit/precision/GeometrySnapperTest.cpp 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/tests/unit/precision/GeometrySnapperTest.cpp 2009-05-05 10:14:39 UTC (rev 2468)
@@ -1,97 +0,0 @@
-// $Id$
-//
-// Test Suite for geos::precision::GeometrySnapper class.
-
-// tut
-#include <tut.hpp>
-// geos
-#include <geos/precision/GeometrySnapper.h>
-#include <geos/geom/Geometry.h>
-#include <geos/geom/GeometryFactory.h>
-#include <geos/io/WKTReader.h>
-// std
-#include <memory>
-#include <string>
-#include <vector>
-
-namespace tut
-{
- //
- // Test Group
- //
-
- // Common data used by tests
- struct test_geometrysnapper_data
- {
- typedef std::auto_ptr<geos::geom::Geometry> GeomAutoPtr;
-
- geos::geom::GeometryFactory factory;
-
- geos::io::WKTReader reader;
-
- GeomAutoPtr src;
-
- geos::precision::GeometrySnapper snapper;
-
- test_geometrysnapper_data()
- :
- factory(), // initialize before use!
- reader(&factory),
- src(reader.read(
- "POLYGON ((0 0, 0 100, 100 100, 100 0, 0 0))"
- )),
- snapper( *(src.get()) )
-
- {
- }
- };
-
- typedef test_group<test_geometrysnapper_data> group;
- typedef group::object object;
-
- group test_geometrysnapper_group("geos::precision::GeometrySnapper");
-
- //
- // Test Cases
- //
-
- // Test vertices snapping
- template<>
- template<>
- void object::test<1>()
- {
- GeomAutoPtr snap(reader.read(
- "MULTIPOINT ((0 0), (0 100.0000001), (100 100), (100 0))"
- ));
-
- GeomAutoPtr expected(reader.read(
- "POLYGON ((0 0, 0 100.0000001, 100 100, 100 0, 0 0))"
- ));
-
- GeomAutoPtr ret(snapper.snapTo( *(snap.get()), 0.000001 ));
-
- ensure( ret->equalsExact(expected.get(),0) );
-
- }
-
- // Test vertices snapping
- template<>
- template<>
- void object::test<2>()
- {
- GeomAutoPtr snap(reader.read(
- "MULTIPOINT ((0.0000001 50))"
- ));
-
- GeomAutoPtr expected(reader.read(
- "POLYGON ((0 0, 0.0000001 50, 0 100, 100 100, 100 0, 0 0))"
- ));
-
- GeomAutoPtr ret(snapper.snapTo( *(snap.get()), 0.000001 ));
-
- ensure( ret->equalsExact(expected.get(),0) );
- }
-
-
-
-} // namespace tut
Deleted: trunk/tests/unit/precision/LineStringSnapperTest.cpp
===================================================================
--- trunk/tests/unit/precision/LineStringSnapperTest.cpp 2009-05-05 00:04:34 UTC (rev 2467)
+++ trunk/tests/unit/precision/LineStringSnapperTest.cpp 2009-05-05 10:14:39 UTC (rev 2468)
@@ -1,115 +0,0 @@
-// $Id$
-//
-// Test Suite for geos::precision::LineStringSnapper class.
-
-// tut
-#include <tut.hpp>
-// geos
-#include <geos/precision/LineStringSnapper.h>
-#include <geos/geom/Coordinate.h>
-#include <geos/geom/CoordinateList.h>
-#include <geos/geom/CoordinateArraySequence.h>
-// std
-#include <string>
-#include <vector>
-
-namespace tut
-{
- //
- // Test Group
- //
-
- // Common data used by tests
- struct test_linestringsnapper_data
- {
-
- test_linestringsnapper_data() {}
- };
-
- typedef test_group<test_linestringsnapper_data> group;
- typedef group::object object;
-
- group test_linestringsnapper_group("geos::precision::LineStringSnapper");
-
- //
- // Test Cases
- //
-
- // Test vertices snapping
- template<>
- template<>
- void object::test<1>()
- {
- using geos::geom::Coordinate;
- using geos::precision::LineStringSnapper;
-
- typedef std::auto_ptr<Coordinate::Vect> CoordsVectAptr;
-
-
- // source coordinates
- Coordinate src_a(0, 0);
- Coordinate src_b(10, 10);
-
- // snap coordinates
- Coordinate snp_a(0.1, 0);
- Coordinate snp_b(10, 10.1);
-
- Coordinate::Vect srcCoords;
- srcCoords.push_back( src_a );
- srcCoords.push_back( src_b );
-
- Coordinate::ConstVect snpCoords;
- snpCoords.push_back( &snp_a );
- snpCoords.push_back( &snp_b );
-
- LineStringSnapper snapper(srcCoords, 0.4);
-
- CoordsVectAptr ret(snapper.snapTo(snpCoords));
-
- // both points should have been snapped
- ensure_equals(ret->operator[](0), snp_a);
- ensure_equals(ret->operator[](1), snp_b);
-
- }
-
- // Test segment snapping
- template<>
- template<>
- void object::test<2>()
- {
- using geos::geom::Coordinate;
- using geos::precision::LineStringSnapper;
-
- typedef std::auto_ptr<Coordinate::Vect> CoordsVectAptr;
-
-
- // source coordinates
- Coordinate src_a(0, 0);
- Coordinate src_b(10, 10);
-
- // snap coordinates
- Coordinate snp_a(0.4, 0);
- Coordinate snp_b(10, 10.4);
-
- Coordinate::Vect srcCoords;
- srcCoords.push_back( src_a );
- srcCoords.push_back( src_b );
-
- Coordinate::ConstVect snpCoords;
- snpCoords.push_back( &snp_a );
- snpCoords.push_back( &snp_b );
-
- LineStringSnapper snapper(srcCoords, 0.3);
-
- CoordsVectAptr ret(snapper.snapTo(snpCoords));
-
- // snap point a should be inserted
- ensure_equals(ret->size(), 3u);
- ensure_equals(ret->operator[](0), src_a);
- ensure_equals(ret->operator[](1), snp_a);
- ensure_equals(ret->operator[](2), src_b);
-
- }
-
-
-} // namespace tut
More information about the geos-commits
mailing list