[geos-commits] r3444 - in trunk: include/geos/algorithm
src/algorithm
svn_geos at osgeo.org
svn_geos at osgeo.org
Wed Jul 20 11:40:27 EDT 2011
Author: strk
Date: 2011-07-20 08:40:27 -0700 (Wed, 20 Jul 2011)
New Revision: 3444
Modified:
trunk/include/geos/algorithm/ConvexHull.h
trunk/include/geos/algorithm/ConvexHull.inl
trunk/src/algorithm/ConvexHull.cpp
Log:
Port JTS robustness fix for ConvexHull (ticket #457)
Modified: trunk/include/geos/algorithm/ConvexHull.h
===================================================================
--- trunk/include/geos/algorithm/ConvexHull.h 2011-07-20 14:32:26 UTC (rev 3443)
+++ trunk/include/geos/algorithm/ConvexHull.h 2011-07-20 15:40:27 UTC (rev 3444)
@@ -4,6 +4,7 @@
* GEOS - Geometry Engine Open Source
* http://geos.refractions.net
*
+ * Copyright (C) 2011 Sandro Santilli <strk at keybit.net>
* Copyright (C) 2005-2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
@@ -12,6 +13,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: algorithm/ConvexHull.java r407 (JTS-1.12+)
+ *
**********************************************************************/
#ifndef GEOS_ALGORITHM_CONVEXHULL_H
@@ -85,15 +90,19 @@
* vertices is not 100% robust, this does not affect the
* robustness of the convex hull.
*
+ * To satisfy the requirements of the Graham Scan algorithm,
+ * the resulting array has at least 3 entries.
+ *
* @param pts The vector of const Coordinate pointers
- * to be reduced
+ * to be reduced (to at least 3 elements)
*
- *
* WARNING: the parameter will be modified
*
*/
void reduce(geom::Coordinate::ConstVect &pts);
+ /// parameter will be modified
+ void padArray3(geom::Coordinate::ConstVect &pts);
/// parameter will be modified
void preSort(geom::Coordinate::ConstVect &pts);
Modified: trunk/include/geos/algorithm/ConvexHull.inl
===================================================================
--- trunk/include/geos/algorithm/ConvexHull.inl 2011-07-20 14:32:26 UTC (rev 3443)
+++ trunk/include/geos/algorithm/ConvexHull.inl 2011-07-20 15:40:27 UTC (rev 3444)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: algorithm/ConvexHull.java r407 (JTS-1.12+)
+ *
**********************************************************************/
#ifndef GEOS_ALGORITHM_CONVEXHULL_INL
Modified: trunk/src/algorithm/ConvexHull.cpp
===================================================================
--- trunk/src/algorithm/ConvexHull.cpp 2011-07-20 14:32:26 UTC (rev 3443)
+++ trunk/src/algorithm/ConvexHull.cpp 2011-07-20 15:40:27 UTC (rev 3444)
@@ -4,8 +4,9 @@
* GEOS - Geometry Engine Open Source
* http://geos.refractions.net
*
+ * Copyright (C) 2011 Sandro Santilli <strk at keybit.net>
+ * Copyright (C) 2005-2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions Inc.
- * Copyright (C) 2005 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
@@ -14,7 +15,7 @@
*
**********************************************************************
*
- * Last port: algorithm/ConvexHull.java rev. 1.26 (JTS-1.7)
+ * Last port: algorithm/ConvexHull.java r407 (JTS-1.12+)
*
**********************************************************************/
@@ -208,9 +209,19 @@
}
inputPts.assign(reducedSet.begin(), reducedSet.end());
-
+
+ if ( inputPts.size() < 3 ) padArray3(inputPts);
}
+/* private */
+void
+ConvexHull::padArray3(geom::Coordinate::ConstVect &pts)
+{
+ for (size_t i = pts.size(); i < 3; ++i) {
+ pts.push_back(pts[0]);
+ }
+}
+
Geometry*
ConvexHull::getConvexHull()
{
@@ -284,8 +295,9 @@
for(size_t i=3, n=c.size(); i<n; ++i)
{
const Coordinate *p = ps.back(); ps.pop_back();
- while (CGAlgorithms::computeOrientation(*(ps.back()),
- *p, *(c[i])) > 0)
+ while (!ps.empty() &&
+ CGAlgorithms::computeOrientation(
+ *(ps.back()), *p, *(c[i])) > 0)
{
p = ps.back(); ps.pop_back();
}
More information about the geos-commits
mailing list