[geos-commits] r3333 - in trunk: include/geos/geomgraph src/geomgraph

svn_geos at osgeo.org svn_geos at osgeo.org
Fri May 6 14:51:56 EDT 2011


Author: strk
Date: 2011-05-06 11:51:56 -0700 (Fri, 06 May 2011)
New Revision: 3333

Removed:
   trunk/src/geomgraph/EdgeIntersection.cpp
Modified:
   trunk/include/geos/geomgraph/EdgeIntersection.h
   trunk/src/geomgraph/Makefile.am
Log:
Turn EdgeIntersection into a concrete, fully-inlined, C++ class.

Modified: trunk/include/geos/geomgraph/EdgeIntersection.h
===================================================================
--- trunk/include/geos/geomgraph/EdgeIntersection.h	2011-05-06 18:51:46 UTC (rev 3332)
+++ trunk/include/geos/geomgraph/EdgeIntersection.h	2011-05-06 18:51:56 UTC (rev 3333)
@@ -1,10 +1,9 @@
 /**********************************************************************
- * $Id$
  *
  * GEOS - Geometry Engine Open Source
  * http://geos.refractions.net
  *
- * Copyright (C) 2009      Sandro Santilli <strk at keybit.net>
+ * Copyright (C) 2009-2011 Sandro Santilli <strk at keybit.net>
  * Copyright (C) 2005-2006 Refractions Research Inc.
  * Copyright (C) 2001-2002 Vivid Solutions Inc.
  *
@@ -24,19 +23,19 @@
 #define GEOS_GEOMGRAPH_EDGEINTERSECTION_H
 
 #include <geos/export.h>
-#include <string>
 
-#include <geos/geom/Coordinate.h> // for CoordinateLessThen
+#include <geos/geom/Coordinate.h> // for composition and inlines
 
 #include <geos/inline.h>
 
+#include <ostream>
 
+
 namespace geos {
 namespace geomgraph { // geos.geomgraph
 
 /**
- * Represents a point on an
- * edge which intersects with another edge.
+ * Represents a point on an edge which intersects with another edge.
  * 
  * The intersection may either be a single point, or a line segment
  * (in which case this point is the start of the line segment)
@@ -49,62 +48,72 @@
 	// the point of intersection
 	geom::Coordinate coord;
 
+	// the edge distance of this point along the containing line segment
+	double dist;
+
 	// the index of the containing line segment in the parent edge
 	int segmentIndex;
 
-	// the edge distance of this point along the containing line segment
-	double dist;
-
 	EdgeIntersection(const geom::Coordinate& newCoord,
-	                 int newSegmentIndex, double newDist);
+	                 int newSegmentIndex, double newDist)
+	  :
+	  coord(newCoord),
+	  dist(newDist),
+	  segmentIndex(newSegmentIndex)
+	{}
 
-	virtual ~EdgeIntersection();
+	bool isEndPoint(int maxSegmentIndex) const {
+	  if (segmentIndex==0 && dist==0.0) return true;
+	  if (segmentIndex==maxSegmentIndex) return true;
+	  return false;
+	}
 
-	/**
-	 * @return -1 this EdgeIntersection is located before the
-	 *                 argument location
-	 * @return 0 this EdgeIntersection is at the argument location
-	 * @return 1 this EdgeIntersection is located after the argument
-	 *                location
-	 */
-	int compare(int newSegmentIndex, double newDist) const;
-
-	bool isEndPoint(int maxSegmentIndex);
-
-	std::string print() const;
-
-	int compareTo(const EdgeIntersection *) const;
-
 	const geom::Coordinate& getCoordinate() const {
 		return coord;
 	}
 
 	int getSegmentIndex() const { return segmentIndex; }
 
-	double getDistance() { return dist; }
+	double getDistance() const { return dist; }
 
 };
 
+/// Strict weak ordering operator for EdgeIntersection
+//
+/// This is the C++ equivalent of JTS's compareTo
+inline bool operator< (const EdgeIntersection& ei1, const EdgeIntersection& ei2)
+{
+		if ( ei1.segmentIndex < ei2.segmentIndex ) return true;
+		if ( ei1.segmentIndex == ei2.segmentIndex )
+    {
+      if ( ei1.dist < ei2.dist ) return true;
+
+      // TODO: check if the Coordinate matches, or this will
+      //       be a robustness issue in computin distance
+      //       See http://trac.osgeo.org/geos/ticket/350
+    }
+		return false;
+}
+
+// @deprecated, use strict weak ordering operator
 struct GEOS_DLL  EdgeIntersectionLessThen {
 	bool operator()(const EdgeIntersection *ei1,
 		const EdgeIntersection *ei2) const
 	{
-		if ( ei1->segmentIndex<ei2->segmentIndex ||
-			( ei1->segmentIndex==ei2->segmentIndex &&
-		     	ei1->dist<ei2->dist ) ) return true;
-		return false;
+    return *ei1 < *ei2;
 	}
 };
 
-std::ostream& operator<< (std::ostream&, const EdgeIntersection&);
+/// Output operator
+inline std::ostream& operator<< (std::ostream& os, const EdgeIntersection& e)
+{
+  os << e.coord << " seg # = " << e.segmentIndex << " dist = " << e.dist;
+	return os;
+}
 
 } // namespace geos.geomgraph
 } // namespace geos
 
-//#ifdef GEOS_INLINE
-//# include "geos/geomgraph/EdgeIntersection.inl"
-//#endif
-
 #endif // ifndef GEOS_GEOMGRAPH_EDGEINTERSECTION_H
 
 

Deleted: trunk/src/geomgraph/EdgeIntersection.cpp
===================================================================
--- trunk/src/geomgraph/EdgeIntersection.cpp	2011-05-06 18:51:46 UTC (rev 3332)
+++ trunk/src/geomgraph/EdgeIntersection.cpp	2011-05-06 18:51:56 UTC (rev 3333)
@@ -1,89 +0,0 @@
-/**********************************************************************
- * $Id$
- *
- * GEOS - Geometry Engine Open Source
- * http://geos.refractions.net
- *
- * Copyright (C) 2009      Sandro Santilli <strk at keybit.net>
- * Copyright (C) 2001-2002 Vivid Solutions Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU Lesser General Public Licence as published
- * by the Free Software Foundation. 
- * See the COPYING file for more information.
- *
- **********************************************************************
- *
- * Last port: geomgraph/EdgeIntersection.java rev. 1.5 (JTS-1.10)
- *
- **********************************************************************/
-
-#include <sstream>
-#include <string>
-
-#include <geos/geomgraph/EdgeIntersection.h>
-#include <geos/geom/Coordinate.h>
-
-using namespace std;
-using namespace geos::geom;
-
-namespace geos {
-namespace geomgraph { // geos.geomgraph
-
-EdgeIntersection::EdgeIntersection(const Coordinate& newCoord,
-		int newSegmentIndex, double newDist)
-	:
-	coord(newCoord),
-	segmentIndex(newSegmentIndex),
-	dist(newDist)
-{
-}
-
-EdgeIntersection::~EdgeIntersection()
-{
-}
-
-int
-EdgeIntersection::compare(int newSegmentIndex, double newDist) const
-{
-	if (segmentIndex<newSegmentIndex) return -1;
-	if (segmentIndex>newSegmentIndex) return 1;
-	if (dist<newDist) return -1;
-	if (dist>newDist) return 1;
-	return 0;
-}
-
-bool
-EdgeIntersection::isEndPoint(int maxSegmentIndex)
-{
-	if (segmentIndex==0 && dist==0.0) return true;
-	if (segmentIndex==maxSegmentIndex) return true;
-	return false;
-}
-
-string
-EdgeIntersection::print() const
-{
-	ostringstream s;
-	s << *this;
-	return s.str();
-
-}
-
-std::ostream&
-operator<< (std::ostream&os, const EdgeIntersection& e)
-{
-	os << e.coord << " seg # = " << e.segmentIndex << " dist = " << e.dist;
-	return os;
-}
-
-int
-EdgeIntersection::compareTo(const EdgeIntersection *other) const
-{
-	return compare(other->segmentIndex, other->dist);
-}
-
-} // namespace geos.geomgraph
-} // namespace geos
-
-

Modified: trunk/src/geomgraph/Makefile.am
===================================================================
--- trunk/src/geomgraph/Makefile.am	2011-05-06 18:51:46 UTC (rev 3332)
+++ trunk/src/geomgraph/Makefile.am	2011-05-06 18:51:56 UTC (rev 3333)
@@ -15,7 +15,6 @@
 	Edge.cpp \
 	EdgeEnd.cpp \
 	EdgeEndStar.cpp \
-	EdgeIntersection.cpp \
 	EdgeIntersectionList.cpp \
 	EdgeNodingValidator.cpp \
 	EdgeList.cpp \



More information about the geos-commits mailing list