[geos-commits] r2401 - in trunk: source/geom source/headers/geos/geom tests/unit/geom

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Apr 21 11:12:20 EDT 2009


Author: strk
Date: 2009-04-21 11:12:20 -0400 (Tue, 21 Apr 2009)
New Revision: 2401

Modified:
   trunk/source/geom/LinearRing.cpp
   trunk/source/headers/geos/geom/LinearRing.h
   trunk/tests/unit/geom/LinearRingTest.cpp
Log:
Sync LinearRing to JTS-1.10 (fixing a bug in isClosed)


Modified: trunk/source/geom/LinearRing.cpp
===================================================================
--- trunk/source/geom/LinearRing.cpp	2009-04-21 14:03:45 UTC (rev 2400)
+++ trunk/source/geom/LinearRing.cpp	2009-04-21 15:12:20 UTC (rev 2401)
@@ -12,13 +12,19 @@
  * by the Free Software Foundation. 
  * See the COPYING file for more information.
  *
+ **********************************************************************
+ *
+ * Last port: geom/LinearRing.java rev. 1.32 (JTS-1.10)
+ *
  **********************************************************************/
 
 #include <geos/geom/LinearRing.h>
+#include <geos/geom/Dimension.h>
 #include <geos/geom/CoordinateSequence.h>
 #include <geos/geom/GeometryFactory.h>
 #include <geos/util/IllegalArgumentException.h>
 
+#include <sstream>
 #include <string>
 #include <memory>
 
@@ -52,12 +58,23 @@
 void
 LinearRing::validateConstruction()
 {
-	if (!LineString::isEmpty() && !LineString::isClosed()) {
-		throw util::IllegalArgumentException("points must form a closed linestring");
-    }
-	if (!points->isEmpty() && (points->getSize()>=1 && points->getSize()<=3)) {
-		throw util::IllegalArgumentException("Number of points must be 0 or >3");
+	// Empty ring is valid
+	if ( points->isEmpty() ) return;
+
+	if ( !LineString::isClosed() )
+	{
+		throw util::IllegalArgumentException(
+		  "Points of LinearRing do not form a closed linestring"
+		);
 	}
+
+	if ( points->getSize() <= 3 )
+	{
+		std::ostringstream os;
+		os << "Invalid number of points in LinearRing found "
+		   << points->getSize() << " - must be 0 or >= 4";
+		throw util::IllegalArgumentException(os.str());
+	}
 }
 
 
@@ -66,15 +83,21 @@
 LinearRing::~LinearRing(){
 }
 
-bool LinearRing::isSimple() const {
+int
+LinearRing::getBoundaryDimension() const
+{
+	return Dimension::False;
+}
+
+bool
+LinearRing::isSimple() const
+{
 	return true;
 }
+
 string LinearRing::getGeometryType() const {
 	return "LinearRing";
 }
-bool LinearRing::isClosed() const {
-	return true;
-}
 
 void LinearRing::setPoints(CoordinateSequence* cl){
 	const vector<Coordinate> *v=cl->toVector();
@@ -87,6 +110,16 @@
 	return GEOS_LINEARRING;
 }
 
+Geometry*
+LinearRing::reverse() const
+{
+	assert(points.get());
+	CoordinateSequence* seq = points->clone();
+	CoordinateSequence::reverse(seq);
+	assert(getFactory());
+	return getFactory()->createLinearRing(seq);
+}
+
 } // namespace geos::geom
 } // namespace geos
 

Modified: trunk/source/headers/geos/geom/LinearRing.h
===================================================================
--- trunk/source/headers/geos/geom/LinearRing.h	2009-04-21 14:03:45 UTC (rev 2400)
+++ trunk/source/headers/geos/geom/LinearRing.h	2009-04-21 15:12:20 UTC (rev 2401)
@@ -12,6 +12,10 @@
  * by the Free Software Foundation. 
  * See the COPYING file for more information.
  *
+ **********************************************************************
+ *
+ * Last port: geom/LinearRing.java rev. 1.32 (JTS-1.10)
+ *
  **********************************************************************/
 
 #ifndef GEOS_GEOS_LINEARRING_H
@@ -36,13 +40,19 @@
 namespace geom { // geos::geom
 
 /**
+ * \brief 
+ * Models an OGC SFS <code>LinearRing</code>.
  *
- * \brief Basic implementation of <code>LinearRing</code>.
- *
- * The first and last point in the coordinate sequence must be equal.
+ * A LinearRing is a LineString which is both closed and simple.
+ * In other words,
+ * the first and last coordinate in the ring must be equal,
+ * and the interior of the ring must not self-intersect.
  * Either orientation of the ring is allowed.
- * A valid ring must not self-intersect.
- *
+ * 
+ * A ring must have either 0 or 4 or more points.
+ * The first and last points must be equal (in 2D).
+ * If these conditions are not met, the constructors throw
+ * an {@link IllegalArgumentException}
  */
 class LinearRing : public LineString {
 
@@ -70,13 +80,37 @@
 			const GeometryFactory *newFactory);
 
 	virtual Geometry *clone() const { return new LinearRing(*this); }
+
 	virtual ~LinearRing();
+
+	/** \brief
+	 * Returns <code>Dimension.FALSE</code>, since by definition
+	 * LinearRings do not have a boundary.
+	 *
+	 * @return Dimension::False
+	 */
+	int getBoundaryDimension() const;
+
+	/** \brief
+	 * Returns <code>true</code>, since by definition LinearRings
+	 * are always simple.
+	 *
+	 * @return <code>true</code>
+	 *
+	 * @see Geometry::isSimple
+	 */
 	bool isSimple() const;
+
 	std::string getGeometryType() const;
+
 	virtual GeometryTypeId getGeometryTypeId() const;
-	bool isClosed() const;
+
 	void setPoints(CoordinateSequence* cl);
+
+  	Geometry* reverse() const;
+
 private:
+
 	void validateConstruction();
 };
 

Modified: trunk/tests/unit/geom/LinearRingTest.cpp
===================================================================
--- trunk/tests/unit/geom/LinearRingTest.cpp	2009-04-21 14:03:45 UTC (rev 2400)
+++ trunk/tests/unit/geom/LinearRingTest.cpp	2009-04-21 15:12:20 UTC (rev 2401)
@@ -136,7 +136,7 @@
 	template<>
 	void object::test<4>()
 	{
-		ensure( empty_ring_.isClosed() );
+		ensure( ! empty_ring_.isClosed() );
 	}
 
 	// Test of isRing() for empty LinearRing
@@ -144,7 +144,7 @@
 	template<>
 	void object::test<5>()
 	{
-		ensure( empty_ring_.isRing() );
+		ensure( ! empty_ring_.isRing() );
 	}
 
 	// Test of isSimple() for empty LinearRing



More information about the geos-commits mailing list