[geos-commits] r3257 - in trunk: . include/geos/geom include/geos/util src/geom

svn_geos at osgeo.org svn_geos at osgeo.org
Wed Mar 2 07:46:57 EST 2011


Author: strk
Date: 2011-03-02 04:46:57 -0800 (Wed, 02 Mar 2011)
New Revision: 3257

Added:
   trunk/include/geos/util/IllegalStateException.h
Modified:
   trunk/NEWS
   trunk/include/geos/geom/LineSegment.h
   trunk/include/geos/geom/LineSegment.inl
   trunk/include/geos/util/Makefile.am
   trunk/src/geom/LineSegment.cpp
Log:
Added check for illegal state in offsetPoint method

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2011-03-02 09:24:02 UTC (rev 3256)
+++ trunk/NEWS	2011-03-02 12:46:57 UTC (rev 3257)
@@ -37,6 +37,7 @@
   - Fix NodedSegmentString to handle zero-length line segments correctly
     (via safeOctant)
   - Fixed buffer OffsetCurveSetBuilder to handle "flat" rings correctly
+  - Added illegal state check in LineSegment::pointAlongOffset() 
 
 Changes in 3.2.0 
 2009-12-14

Modified: trunk/include/geos/geom/LineSegment.h
===================================================================
--- trunk/include/geos/geom/LineSegment.h	2011-03-02 09:24:02 UTC (rev 3256)
+++ trunk/include/geos/geom/LineSegment.h	2011-03-02 12:46:57 UTC (rev 3257)
@@ -4,8 +4,9 @@
  * GEOS - Geometry Engine Open Source
  * http://geos.refractions.net
  *
- * Copyright (C) 2009  Sandro Santilli <strk at keybit.net>
- * Copyright (C) 2006 Refractions Research Inc.
+ * Copyright (C) 2009 2011 Sandro Santilli <strk at keybit.net>
+ * Copyright (C) 2005-2006 Refractions Research Inc.
+ * 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
@@ -14,7 +15,7 @@
  *
  **********************************************************************
  *
- * Last port: geom/LineSegment.java rev. 1.30 (JTS-1.9)
+ * Last port: geom/LineSegment.java r18 (JTS-1.11)
  *
  **********************************************************************/
 
@@ -211,6 +212,8 @@
 	 *         (positive is to the left, negative is to the right)
 	 *
 	 * @param ret will be set to the point at that distance and offset
+	 * 
+	 * @throws IllegalStateException if the segment has zero length
 	 */
 	void pointAlongOffset(double segmentLengthFraction,
 	                      double offsetDistance,

Modified: trunk/include/geos/geom/LineSegment.inl
===================================================================
--- trunk/include/geos/geom/LineSegment.inl	2011-03-02 09:24:02 UTC (rev 3256)
+++ trunk/include/geos/geom/LineSegment.inl	2011-03-02 12:46:57 UTC (rev 3257)
@@ -4,8 +4,9 @@
  * 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.
  *
  * This is free software; you can redistribute and/or modify it under
  * the terms of the GNU Lesser General Public Licence as published
@@ -14,7 +15,7 @@
  *
  **********************************************************************
  *
- * Last port: geom/LineSegment.java rev. 1.30 (JTS-1.9)
+ * Last port: geom/LineSegment.java r18 (JTS-1.11)
  *
  **********************************************************************/
 

Added: trunk/include/geos/util/IllegalStateException.h
===================================================================
--- trunk/include/geos/util/IllegalStateException.h	                        (rev 0)
+++ trunk/include/geos/util/IllegalStateException.h	2011-03-02 12:46:57 UTC (rev 3257)
@@ -0,0 +1,47 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2011 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.
+ *
+ **********************************************************************/
+
+#ifndef GEOS_UTIL_ILLEGALSTATEEXCEPTION_H
+#define GEOS_UTIL_ILLEGALSTATEEXCEPTION_H
+
+#include <geos/export.h>
+#include <string>
+
+#include <geos/util/GEOSException.h>
+
+namespace geos {
+namespace util { // geos::util
+
+/// Indicates an illegal state
+class GEOS_DLL IllegalStateException: public GEOSException {
+public:
+	IllegalStateException()
+		:
+		GEOSException("IllegalStateException", "")
+	{}
+
+	IllegalStateException(const std::string& msg)
+		:
+		GEOSException("IllegalStateException", msg)
+	{}
+
+	~IllegalStateException() throw() {};
+};
+
+} // namespace geos::util
+} // namespace geos
+
+
+#endif // GEOS_UTIL_ILLEGALSTATEEXCEPTION_H

Modified: trunk/include/geos/util/Makefile.am
===================================================================
--- trunk/include/geos/util/Makefile.am	2011-03-02 09:24:02 UTC (rev 3256)
+++ trunk/include/geos/util/Makefile.am	2011-03-02 12:46:57 UTC (rev 3257)
@@ -15,6 +15,7 @@
     GeometricShapeFactory.h \
     GEOSException.h \
     IllegalArgumentException.h \
+    IllegalStateException.h \
     math.h \
     Machine.h \
     TopologyException.h \

Modified: trunk/src/geom/LineSegment.cpp
===================================================================
--- trunk/src/geom/LineSegment.cpp	2011-03-02 09:24:02 UTC (rev 3256)
+++ trunk/src/geom/LineSegment.cpp	2011-03-02 12:46:57 UTC (rev 3257)
@@ -4,7 +4,7 @@
  * 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.
  *
@@ -15,7 +15,7 @@
  *
  **********************************************************************
  *
- * Last port: geom/LineSegment.java rev. 1.30 (JTS-1.9)
+ * Last port: geom/LineSegment.java r18 (JTS-1.11)
  *
  **********************************************************************/
 
@@ -29,6 +29,7 @@
 #include <geos/algorithm/LineIntersector.h>
 #include <geos/algorithm/HCoordinate.h>
 #include <geos/algorithm/NotRepresentableException.h>
+#include <geos/util/IllegalStateException.h>
 #include <geos/profiler.h>
 #include <geos/inline.h>
 
@@ -279,11 +280,20 @@
 	double dx = p1.x - p0.x;
 	double dy = p1.y - p0.y;
 	double len = sqrt(dx * dx + dy * dy);
-	// u is the vector that is the length of the offset,
-	// in the direction of the segment
-	double ux = offsetDistance * dx / len;
-	double uy = offsetDistance * dy / len;
 
+	double ux = 0.0;
+	double uy = 0.0;
+	if (offsetDistance != 0.0) {
+		if (len <= 0.0) {
+			throw util::IllegalStateException("Cannot compute offset from zero-length line segment");
+		}
+
+		// u is the vector that is the length of the offset,
+		// in the direction of the segment
+		ux = offsetDistance * dx / len;
+		uy = offsetDistance * dy / len;
+	}
+
 	// the offset point is the seg point plus the offset
 	// vector rotated 90 degrees CCW
 	double offsetx = segx - uy;



More information about the geos-commits mailing list