[geos-commits] [SCM] GEOS branch master updated. 72662a8a10e408f1ccadfe9ed6f90d4572c24bdb

git at osgeo.org git at osgeo.org
Wed Dec 19 08:52:35 PST 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, master has been updated
       via  72662a8a10e408f1ccadfe9ed6f90d4572c24bdb (commit)
      from  7b90ad43631f53174b4e8113ccbc2b51c9dbb2d7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 72662a8a10e408f1ccadfe9ed6f90d4572c24bdb
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Wed Dec 19 08:52:21 2018 -0800

    Refactor CGAlgorithms distance functions into Distance class
    JTS 6103203279ec05e43c625d4f1b4377c93ff52934

diff --git a/include/geos/algorithm/Distance.h b/include/geos/algorithm/Distance.h
new file mode 100644
index 0000000..34e2373
--- /dev/null
+++ b/include/geos/algorithm/Distance.h
@@ -0,0 +1,110 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2018 Paul Ramsey <pramsey at cleverlephant.ca>
+ *
+ * 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: algorithm/Distance.java @ 2017-09-04
+ *
+ **********************************************************************/
+
+#ifndef GEOS_ALGORITHM_DISTANCE_H
+#define GEOS_ALGORITHM_DISTANCE_H
+
+#include <geos/export.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequence.h>
+
+namespace geos {
+namespace algorithm { // geos::algorithm
+
+/**
+ * Functions to compute distance between basic geometric structures.
+ *
+ * @author Martin Davis
+ *
+ */
+class GEOS_DLL Distance {
+public:
+
+    /**
+    * Computes the distance from a line segment AB to a line segment CD
+    *
+    * Note: NON-ROBUST!
+    *
+    * @param A
+    *          a point of one line
+    * @param B
+    *          the second point of (must be different to A)
+    * @param C
+    *          one point of the line
+    * @param D
+    *          another point of the line (must be different to A)
+    */
+    // formerly distanceLineLine
+    static double segmentToSegment(const geom::Coordinate& A,
+                                   const geom::Coordinate& B,
+                                   const geom::Coordinate& C,
+                                   const geom::Coordinate& D);
+
+    /**
+    * Computes the distance from a point to a sequence of line segments.
+    *
+    * @param p
+    *          a point
+    * @param line
+    *          a sequence of contiguous line segments defined by their vertices
+    * @return the minimum distance between the point and the line segments
+    */
+    static double pointToSegmentString(const geom::Coordinate& p,
+        const geom::CoordinateSequence *seq);
+
+    /**
+    * Computes the distance from a point p to a line segment AB
+    *
+    * Note: NON-ROBUST!
+    *
+    * @param p
+    *          the point to compute the distance for
+    * @param A
+    *          one point of the line
+    * @param B
+    *          another point of the line (must be different to A)
+    * @return the distance from p to line segment AB
+    */
+    // formerly distancePointLine
+    static double pointToSegment(const geom::Coordinate& p,
+                                 const geom::Coordinate& A,
+                                 const geom::Coordinate& B);
+
+    /**
+    * Computes the perpendicular distance from a point p to the (infinite) line
+    * containing the points AB
+    *
+    * @param p
+    *          the point to compute the distance for
+    * @param A
+    *          one point of the line
+    * @param B
+    *          another point of the line (must be different to A)
+    * @return the distance from p to line AB
+    */
+    // formerly distancePointLinePerpendicular
+    static double pointToLinePerpendicular(const geom::Coordinate& p,
+                                           const geom::Coordinate& A,
+                                           const geom::Coordinate& B);
+
+};
+
+} // namespace geos::algorithm
+} // namespace geos
+
+#endif // GEOS_ALGORITHM_DISTANCE_H
diff --git a/include/geos/algorithm/Makefile.am b/include/geos/algorithm/Makefile.am
index 0906469..77232f4 100644
--- a/include/geos/algorithm/Makefile.am
+++ b/include/geos/algorithm/Makefile.am
@@ -19,6 +19,7 @@ geos_HEADERS = \
 	CGAlgorithms.h \
 	ConvexHull.h \
 	ConvexHull.inl \
+	Distance.h \
 	HCoordinate.h \
 	InteriorPointArea.h \
 	InteriorPointLine.h \
diff --git a/include/geos/geom/LineSegment.inl b/include/geos/geom/LineSegment.inl
index 1ee6ef5..5c43324 100644
--- a/include/geos/geom/LineSegment.inl
+++ b/include/geos/geom/LineSegment.inl
@@ -9,7 +9,7 @@
  *
  * 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. 
+ * by the Free Software Foundation.
  * See the COPYING file for more information.
  *
  **********************************************************************
@@ -21,8 +21,9 @@
 #ifndef GEOS_LINESEGMENT_INL
 #define GEOS_LINESEGMENT_INL
 
-#include <geos/geom/LineSegment.h> 
-#include <geos/algorithm/CGAlgorithms.h>
+#include <geos/geom/LineSegment.h>
+#include <geos/algorithm/Distance.h>
+#include <geos/algorithm/Orientation.h>
 
 #include <cassert>
 #include <cmath> // for atan2
@@ -67,7 +68,7 @@ LineSegment::~LineSegment()
 INLINE double
 LineSegment::distancePerpendicular(const Coordinate& p) const
 {
-	return algorithm::CGAlgorithms::distancePointLinePerpendicular(p, p0, p1);
+	return algorithm::Distance::pointToLinePerpendicular(p, p0, p1);
 }
 
 INLINE void
@@ -81,14 +82,14 @@ LineSegment::pointAlong(double segmentLengthFraction, Coordinate& ret) const
 INLINE double
 LineSegment::distance(const LineSegment& ls) const
 {
-	return algorithm::CGAlgorithms::distanceLineLine(p0, p1, ls.p0, ls.p1);
+	return algorithm::Distance::segmentToSegment(p0, p1, ls.p0, ls.p1);
 }
 
 /*public*/
 INLINE double
 LineSegment::distance(const Coordinate& p) const
 {
-	return algorithm::CGAlgorithms::distancePointLine(p, p0, p1);
+	return algorithm::Distance::pointToSegment(p, p0, p1);
 }
 
 INLINE void
@@ -113,7 +114,7 @@ LineSegment::operator[](std::size_t i) const
 }
 
 INLINE Coordinate&
-LineSegment::operator[](std::size_t i) 
+LineSegment::operator[](std::size_t i)
 {
 	if (i==0) return p0;
 	assert(i==1);
@@ -154,7 +155,7 @@ LineSegment::orientationIndex(const LineSegment* seg) const
 INLINE int
 LineSegment::orientationIndex(const Coordinate& p) const
 {
-	return algorithm::CGAlgorithms::orientationIndex(p0, p1, p);
+	return algorithm::Orientation::index(p0, p1, p);
 }
 
 INLINE CoordinateSequence*
diff --git a/include/geos/operation/buffer/BufferBuilder.h b/include/geos/operation/buffer/BufferBuilder.h
index 9bcd3ca..2f9480d 100644
--- a/include/geos/operation/buffer/BufferBuilder.h
+++ b/include/geos/operation/buffer/BufferBuilder.h
@@ -42,7 +42,6 @@ namespace geos {
 		class GeometryFactory;
 	}
 	namespace algorithm {
-		class CGAlgorithms;
 		class LineIntersector;
 	}
 	namespace noding {
diff --git a/include/geos/operation/overlay/MinimalEdgeRing.h b/include/geos/operation/overlay/MinimalEdgeRing.h
index 6571241..d80b70e 100644
--- a/include/geos/operation/overlay/MinimalEdgeRing.h
+++ b/include/geos/operation/overlay/MinimalEdgeRing.h
@@ -57,7 +57,6 @@ class GEOS_DLL MinimalEdgeRing: public geomgraph::EdgeRing {
 
 public:
 
-	// CGAlgorithms argument obsoleted
 	MinimalEdgeRing(geomgraph::DirectedEdge *start,
 		const geom::GeometryFactory *geometryFactory);
 
diff --git a/src/algorithm/ConvexHull.cpp b/src/algorithm/ConvexHull.cpp
index 80a634b..40cb11b 100644
--- a/src/algorithm/ConvexHull.cpp
+++ b/src/algorithm/ConvexHull.cpp
@@ -65,7 +65,6 @@ private:
 
 		int orient = Orientation::index(*o, *p, *q);
 
-
 		if (orient == Orientation::COUNTERCLOCKWISE) return 1;
 		if (orient == Orientation::CLOCKWISE) return -1;
 
@@ -315,106 +314,6 @@ ConvexHull::grahamScan(const Coordinate::ConstVect &c,
 }
 
 
-///*
-// * Returns a pointer to input, modifying input
-// */
-//CoordinateSequence*
-//ConvexHull::preSort(CoordinateSequence *pts)
-//{
-//	Coordinate t;
-//
-//	// find the lowest point in the set. If two or more points have
-//	// the same minimum y coordinate choose the one with the minimu x.
-//	// This focal point is put in array location pts[0].
-//	size_t npts=pts->getSize();
-//	for(size_t i=1; i<npts; ++i)
-//	{
-//		const Coordinate &p0=pts->getAt(0); // this will change
-//		const Coordinate &pi=pts->getAt(i);
-//		if ( (pi.y<p0.y) || ((pi.y==p0.y) && (pi.x<p0.x)) )
-//		{
-//			t=p0;
-//			pts->setAt(pi, 0);
-//			pts->setAt( t, i);
-//		}
-//	}
-//	// sort the points radially around the focal point.
-//	radialSort(pts);
-//	return pts;
-//}
-
-///*
-// * Returns a newly allocated CoordinateSequence object
-// */
-//CoordinateSequence*
-//ConvexHull::grahamScan(const CoordinateSequence *c)
-//{
-//	const Coordinate *p;
-//
-//	vector<Coordinate> *ps=new vector<Coordinate>();
-//	ps->push_back(c->getAt(0));
-//	ps->push_back(c->getAt(1));
-//	ps->push_back(c->getAt(2));
-//
-//	p=&(c->getAt(2));
-//	size_t npts=c->getSize();
-//	for(size_t i=3; i<npts; ++i)
-//	{
-//		p=&(ps->back());
-//		ps->pop_back();
-//		while (CGAlgorithms::computeOrientation(ps->back(), *p, c->getAt(i)) > 0)
-//		{
-//			p=&(ps->back());
-//			ps->pop_back();
-//		}
-//		ps->push_back(*p);
-//		ps->push_back(c->getAt(i));
-//	}
-//	ps->push_back(c->getAt(0));
-//
-//	return geomFactory->getCoordinateSequenceFactory()->create(ps);
-//}
-
-//void
-//ConvexHull::radialSort(CoordinateSequence *p)
-//{
-//	// A selection sort routine, assumes the pivot point is
-//	// the first point (i.e., p[0]).
-//
-//	const Coordinate &p0=p->getAt(0); // the pivot point
-//
-//	Coordinate t;
-//	size_t npts=p->getSize();
-//	for(size_t i=1; i<npts-1; ++i)
-//	{
-//		size_t min=i;
-//
-//		for(size_t j=i+1; j<npts; ++j)
-//		{
-//			const Coordinate &pj=p->getAt(j);
-//
-//			if ( polarCompare(p0, pj, p->getAt(min)) < 0 )
-//			{
-//				min=j;
-//			}
-//		}
-//
-//		/*
-//		 * Swap point[i] and point[min]
-//		 * We can skip this if they have
-//		 * the same value
-//		 */
-//		if ( i != min )
-//		{
-//			t=p->getAt(i);
-//			p->setAt(p->getAt(min), i);
-//			p->setAt(t, min);
-//		}
-//	}
-//}
-
-
-
 /*private*/
 bool
 ConvexHull::isBetween(const Coordinate &c1, const Coordinate &c2, const Coordinate &c3)
@@ -441,30 +340,6 @@ ConvexHull::isBetween(const Coordinate &c1, const Coordinate &c2, const Coordina
 	return false;
 }
 
-//void
-//ConvexHull::makeBigQuad(const CoordinateSequence *pts, BigQuad &bigQuad)
-//{
-//	bigQuad.northmost=bigQuad.southmost=
-//		bigQuad.westmost=bigQuad.eastmost=pts->getAt(0);
-//
-//	size_t npts=pts->getSize();
-//	for (size_t i=1; i<npts; ++i)
-//	{
-//		const Coordinate &pi=pts->getAt(i);
-//
-//		if (pi.x<bigQuad.westmost.x)
-//			bigQuad.westmost=pi;
-//
-//		if (pi.x>bigQuad.eastmost.x)
-//			bigQuad.eastmost=pi;
-//
-//		if (pi.y<bigQuad.southmost.y)
-//			bigQuad.southmost=pi;
-//
-//		if (pi.y>bigQuad.northmost.y)
-//			bigQuad.northmost=pi;
-//	}
-//}
 
 /* private */
 Geometry*
diff --git a/src/algorithm/Distance.cpp b/src/algorithm/Distance.cpp
new file mode 100644
index 0000000..e8a9fbb
--- /dev/null
+++ b/src/algorithm/Distance.cpp
@@ -0,0 +1,188 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2018 Paul Ramsey <pramsey at cleverlephant.ca>
+ *
+ * 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: algorithm/Distance.java @ 2017-09-04
+ *
+ **********************************************************************/
+
+#include <cmath>
+#include <vector>
+
+#include <geos/algorithm/Distance.h>
+#include <geos/util/IllegalArgumentException.h>
+
+namespace geos {
+namespace algorithm { // geos.algorithm
+
+/*public static*/
+double
+Distance::pointToSegment(const geom::Coordinate& p,
+    const geom::Coordinate& A,
+    const geom::Coordinate& B)
+{
+    /* if start==end, then use pt distance */
+    if (A == B) {
+        return p.distance(A);
+    }
+
+    /*
+        otherwise use comp.graphics.algorithms method:
+        (1)
+                        AC dot AB
+                    r = ---------
+                        ||AB||^2
+
+        r has the following meaning:
+        r=0 P = A
+        r=1 P = B
+        r<0 P is on the backward extension of AB
+        r>1 P is on the forward extension of AB
+        0<r<1 P is interior to AB
+    */
+
+    double r = ((p.x-A.x)*(B.x-A.x)+(p.y-A.y)*(B.y-A.y))/
+               ((B.x-A.x)*(B.x-A.x)+(B.y-A.y)*(B.y-A.y));
+
+    if (r <= 0.0) return p.distance(A);
+    if (r >= 1.0) return p.distance(B);
+
+    /*
+        (2)
+                (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)
+            s = -----------------------------
+                            L^2
+
+        Then the distance from C to P = |s|*L.
+    */
+
+    double s=((A.y-p.y)*(B.x-A.x)-(A.x-p.x)*(B.y-A.y))/
+             ((B.x-A.x)*(B.x-A.x)+(B.y-A.y)*(B.y-A.y));
+
+    return fabs(s)*sqrt(((B.x-A.x)*(B.x-A.x)+(B.y-A.y)*(B.y-A.y)));
+}
+
+/*public static*/
+double
+Distance::pointToLinePerpendicular(const geom::Coordinate& p,
+    const geom::Coordinate& A, const geom::Coordinate& B)
+{
+    /*
+        use comp.graphics.algorithms method
+
+        (2)
+                (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)
+            s = -----------------------------
+                                 L^2
+
+            Then the distance from C to P = |s|*L.
+    */
+
+    double s = ((A.y - p.y) *(B.x - A.x) - (A.x - p.x)*(B.y - A.y))
+              /
+               ((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y));
+    return fabs(s)*sqrt(((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y)));
+}
+
+/*public static*/
+double
+Distance::segmentToSegment(const geom::Coordinate& A,
+    const geom::Coordinate& B, const geom::Coordinate& C,
+    const geom::Coordinate& D)
+{
+    /* Check for zero-length segments */
+    if (A == B) return pointToSegment(A,C,D);
+    if (C == D) return pointToSegment(D,A,B);
+
+    /* AB and CD are line segments */
+    /*
+        From comp.graphics.algo
+
+        Solving the above for r and s yields
+
+            (Ay-Cy)(Dx-Cx)-(Ax-Cx)(Dy-Cy)
+        r = ----------------------------- (eqn 1)
+            (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx)
+
+            (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)
+        s = ----------------------------- (eqn 2)
+            (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx)
+
+        Let P be the position vector of the intersection point, then
+
+            P=A+r(B-A) or
+            Px=Ax+r(Bx-Ax)
+            Py=Ay+r(By-Ay)
+
+        By examining the values of r & s, you can also determine some other
+        limiting conditions:
+
+        If 0<=r<=1 & 0<=s<=1, intersection exists;
+        If r<0 or r>1 or s<0 or s>1, line segments do not intersect;
+        If the denominator in eqn 1 is zero, AB & CD are parallel;
+        If the numerator in eqn 1 is also zero, AB & CD are collinear.
+    */
+
+    double r_top=(A.y-C.y)*(D.x-C.x)-(A.x-C.x)*(D.y-C.y);
+    double r_bot=(B.x-A.x)*(D.y-C.y)-(B.y-A.y)*(D.x-C.x);
+    double s_top=(A.y-C.y)*(B.x-A.x)-(A.x-C.x)*(B.y-A.y);
+    double s_bot=(B.x-A.x)*(D.y-C.y)-(B.y-A.y)*(D.x-C.x);
+
+    if ((r_bot==0) || (s_bot==0)) {
+        return std::min(pointToSegment(A,C,D),
+               std::min(pointToSegment(B,C,D),
+               std::min(pointToSegment(C,A,B), pointToSegment(D,A,B))));
+    }
+
+    double s=s_top/s_bot;
+    double r=r_top/r_bot;
+
+    if ((r<0) || (r>1) || (s<0) || (s>1)) {
+        /* no intersection */
+        return std::min(pointToSegment(A,C,D),
+               std::min(pointToSegment(B,C,D),
+               std::min(pointToSegment(C,A,B), pointToSegment(D,A,B))));
+    }
+
+    return 0.0; /* intersection exists */
+}
+
+/*public static*/
+double
+Distance::pointToSegmentString(const geom::Coordinate& p,
+    const geom::CoordinateSequence *seq)
+{
+    if (seq->size() == 0) {
+        throw new util::IllegalArgumentException(
+            "Line array must contain at least one vertex");
+    }
+
+    /* this handles the case of length = 1 */
+    double minDistance = p.distance(seq->getAt(0));
+    for (std::size_t i = 0; i < seq->size()-1; i++) {
+        const geom::Coordinate& si = seq->getAt(i);
+        const geom::Coordinate& si1 = seq->getAt(i+1);
+        double dist = pointToSegment(p, si, si1);
+
+        if (dist < minDistance) {
+            minDistance = dist;
+        }
+    }
+
+    return minDistance;
+}
+
+
+} // namespace geos.algorithm
+} //namespace geos
+
diff --git a/src/algorithm/LineIntersector.cpp b/src/algorithm/LineIntersector.cpp
index 61b7a47..89b7219 100644
--- a/src/algorithm/LineIntersector.cpp
+++ b/src/algorithm/LineIntersector.cpp
@@ -19,18 +19,14 @@
 
 #include <geos/platform.h>
 #include <geos/algorithm/LineIntersector.h>
-#include <geos/algorithm/CGAlgorithms.h>
+#include <geos/algorithm/Distance.h>
 #include <geos/algorithm/Orientation.h>
 #include <geos/algorithm/HCoordinate.h>
 #include <geos/algorithm/NotRepresentableException.h>
-//#include <geos/algorithm/CentralEndpointIntersector.h>
 #include <geos/geom/Coordinate.h>
 #include <geos/geom/PrecisionModel.h>
 #include <geos/geom/Envelope.h>
 
-//#include <geos/util/Assert.h> // changed to TopologyException
-//#include <geos/util/TopologyException.h> // we don't throw anymore
-
 #include <algorithm> // for max()
 #include <string>
 #include <cmath> // for fabs()
@@ -81,19 +77,19 @@ Coordinate nearestEndpoint(const Coordinate& p1, const Coordinate& p2,
     const Coordinate& q1, const Coordinate& q2)
 {
   Coordinate nearestPt = p1;
-  double minDist = CGAlgorithms::distancePointLine(p1, q1, q2);
+  double minDist = Distance::pointToSegment(p1, q1, q2);
 
-  double dist = CGAlgorithms::distancePointLine(p2, q1, q2);
+  double dist = Distance::pointToSegment(p2, q1, q2);
   if (dist < minDist) {
     minDist = dist;
     nearestPt = p2;
   }
-  dist = CGAlgorithms::distancePointLine(q1, p1, p2);
+  dist = Distance::pointToSegment(q1, p1, p2);
   if (dist < minDist) {
     minDist = dist;
     nearestPt = q1;
   }
-  dist = CGAlgorithms::distancePointLine(q2, p1, p2);
+  dist = Distance::pointToSegment(q2, p1, p2);
   if (dist < minDist) {
     minDist = dist;
     nearestPt = q2;
diff --git a/src/algorithm/Makefile.am b/src/algorithm/Makefile.am
index fc1a1bb..520364e 100644
--- a/src/algorithm/Makefile.am
+++ b/src/algorithm/Makefile.am
@@ -17,6 +17,7 @@ libalgorithm_la_SOURCES = \
 	CGAlgorithms.cpp \
 	CGAlgorithmsDD.cpp \
 	ConvexHull.cpp \
+	Distance.cpp \
 	HCoordinate.cpp \
 	InteriorPointArea.cpp \
 	InteriorPointLine.cpp \
diff --git a/src/operation/buffer/BufferBuilder.cpp b/src/operation/buffer/BufferBuilder.cpp
index bdea573..636011f 100644
--- a/src/operation/buffer/BufferBuilder.cpp
+++ b/src/operation/buffer/BufferBuilder.cpp
@@ -116,9 +116,6 @@ BufferBuilder::depthDelta(const Label& label)
 	return 0;
 }
 
-//static CGAlgorithms rCGA;
-//CGAlgorithms *BufferBuilder::cga=&rCGA;
-
 BufferBuilder::~BufferBuilder()
 {
 	delete li; // could be NULL
diff --git a/src/operation/buffer/BufferInputLineSimplifier.cpp b/src/operation/buffer/BufferInputLineSimplifier.cpp
index 4772794..259fa94 100644
--- a/src/operation/buffer/BufferInputLineSimplifier.cpp
+++ b/src/operation/buffer/BufferInputLineSimplifier.cpp
@@ -19,7 +19,7 @@
 #include <geos/operation/buffer/BufferInputLineSimplifier.h>
 #include <geos/geom/CoordinateSequence.h> // for inlines
 #include <geos/geom/CoordinateArraySequence.h> // for constructing the return
-#include <geos/algorithm/CGAlgorithms.h> // for use
+#include <geos/algorithm/Distance.h> // for use
 #include <geos/algorithm/Orientation.h> // for use
 
 #include <memory>
@@ -166,7 +166,7 @@ BufferInputLineSimplifier::isShallowConcavity(const geom::Coordinate& p0,
 	if (! isAngleToSimplify)
 		return false;
 
-	double dist = CGAlgorithms::distancePointLine(p1, p0, p2);
+	double dist = Distance::pointToSegment(p1, p0, p2);
 	return dist < p_distanceTol;
 }
 
@@ -195,7 +195,7 @@ BufferInputLineSimplifier::isShallow(const geom::Coordinate& p0,
                                      const geom::Coordinate& p2,
                                      double p_distanceTol) const
 {
-	double dist = CGAlgorithms::distancePointLine(p1, p0, p2);
+	double dist = Distance::pointToSegment(p1, p0, p2);
 	return dist < p_distanceTol;
 }
 
diff --git a/src/operation/buffer/OffsetCurveSetBuilder.cpp b/src/operation/buffer/OffsetCurveSetBuilder.cpp
index 1e365f5..44b758b 100644
--- a/src/operation/buffer/OffsetCurveSetBuilder.cpp
+++ b/src/operation/buffer/OffsetCurveSetBuilder.cpp
@@ -19,7 +19,7 @@
  **********************************************************************/
 
 #include <geos/platform.h>
-#include <geos/algorithm/CGAlgorithms.h>
+#include <geos/algorithm/Distance.h>
 #include <geos/algorithm/Orientation.h>
 #include <geos/algorithm/MinimumDiameter.h>
 #include <geos/util/UnsupportedOperationException.h>
@@ -373,7 +373,7 @@ OffsetCurveSetBuilder::isTriangleErodedCompletely(
 
 	Coordinate inCentre;
 	tri.inCentre(inCentre);
-	double distToCentre=CGAlgorithms::distancePointLine(inCentre, tri.p0, tri.p1);
+	double distToCentre = Distance::pointToSegment(inCentre, tri.p0, tri.p1);
 	bool ret = distToCentre < std::fabs(bufferDistance);
 	return ret;
 }
diff --git a/src/operation/distance/DistanceOp.cpp b/src/operation/distance/DistanceOp.cpp
index 0a62068..a1db735 100644
--- a/src/operation/distance/DistanceOp.cpp
+++ b/src/operation/distance/DistanceOp.cpp
@@ -22,7 +22,7 @@
 #include <geos/operation/distance/GeometryLocation.h>
 #include <geos/operation/distance/ConnectedElementLocationFilter.h>
 #include <geos/algorithm/PointLocator.h>
-#include <geos/algorithm/CGAlgorithms.h>
+#include <geos/algorithm/Distance.h>
 #include <geos/geom/Coordinate.h>
 #include <geos/geom/CoordinateSequence.h>
 #include <geos/geom/CoordinateArraySequence.h>
@@ -537,7 +537,7 @@ DistanceOp::computeMinDistance(
 		const LineString *line1,
 		vector<GeometryLocation*>& locGeom)
 {
-	using geos::algorithm::CGAlgorithms;
+	using geos::algorithm::Distance;
 
 	const Envelope *env0=line0->getEnvelopeInternal();
 	const Envelope *env1=line1->getEnvelopeInternal();
@@ -555,7 +555,7 @@ DistanceOp::computeMinDistance(
 	{
 		for(size_t j=0; j<npts1-1; ++j)
 		{
-			double dist=CGAlgorithms::distanceLineLine(coord0->getAt(i),coord0->getAt(i+1),
+			double dist = Distance::segmentToSegment(coord0->getAt(i),coord0->getAt(i+1),
 				coord1->getAt(j),coord1->getAt(j+1));
 			if (dist < minDistance) {
 				minDistance = dist;
@@ -584,7 +584,7 @@ DistanceOp::computeMinDistance(const LineString *line,
 		const Point *pt,
 		vector<GeometryLocation*>& locGeom)
 {
-	using geos::algorithm::CGAlgorithms;
+	using geos::algorithm::Distance;
 
 	const Envelope *env0=line->getEnvelopeInternal();
 	const Envelope *env1=pt->getEnvelopeInternal();
@@ -599,7 +599,7 @@ DistanceOp::computeMinDistance(const LineString *line,
 	size_t npts0=coord0->getSize();
 	for(size_t i=0; i<npts0-1; ++i)
 	{
-		double dist=CGAlgorithms::distancePointLine(*coord,coord0->getAt(i),coord0->getAt(i+1));
+		double dist = Distance::pointToSegment(*coord, coord0->getAt(i), coord0->getAt(i+1));
         	if (dist < minDistance) {
           		minDistance = dist;
 			LineSegment seg(coord0->getAt(i), coord0->getAt(i + 1));
diff --git a/src/operation/distance/FacetSequence.cpp b/src/operation/distance/FacetSequence.cpp
index 72501d9..0ae949f 100644
--- a/src/operation/distance/FacetSequence.cpp
+++ b/src/operation/distance/FacetSequence.cpp
@@ -16,7 +16,7 @@
  *
  **********************************************************************/
 
-#include <geos/algorithm/CGAlgorithms.h>
+#include <geos/algorithm/Distance.h>
 #include <geos/operation/distance/FacetSequence.h>
 
 using namespace geos::geom;
@@ -67,7 +67,7 @@ double FacetSequence::computePointLineDistance(const Coordinate & pt, const Face
     for (size_t i = facetSeq.start; i < facetSeq.end - 1; i++) {
         facetSeq.pts->getAt(i, q0);
         facetSeq.pts->getAt(i + 1, q1);
-        dist = CGAlgorithms::distancePointLine(pt, q0, q1);
+        dist = Distance::pointToSegment(pt, q0, q1);
         if (dist == 0.0)
             return dist;
         if (dist < minDistance)
@@ -90,7 +90,7 @@ double FacetSequence::computeLineLineDistance(const FacetSequence & facetSeq) co
             facetSeq.pts->getAt(j, q0);
             facetSeq.pts->getAt(j + 1, q1);
 
-            dist = CGAlgorithms::distanceLineLine(p0, p1, q0, q1);
+            dist = Distance::segmentToSegment(p0, p1, q0, q1);
             if (dist == 0.0)
                 return dist;
             if (dist < minDistance)
diff --git a/src/operation/overlay/MaximalEdgeRing.cpp b/src/operation/overlay/MaximalEdgeRing.cpp
index e978c57..cb69c98 100644
--- a/src/operation/overlay/MaximalEdgeRing.cpp
+++ b/src/operation/overlay/MaximalEdgeRing.cpp
@@ -45,7 +45,6 @@ namespace operation { // geos.operation
 namespace overlay { // geos.operation.overlay
 
 /*public*/
-// CGAlgorithms obsoleted
 MaximalEdgeRing::MaximalEdgeRing(DirectedEdge *start,
 		const GeometryFactory *p_geometryFactory)
 	// throw(const TopologyException &)
diff --git a/src/operation/overlay/OverlayOp.cpp b/src/operation/overlay/OverlayOp.cpp
index 2f7ed87..e5a93c7 100644
--- a/src/operation/overlay/OverlayOp.cpp
+++ b/src/operation/overlay/OverlayOp.cpp
@@ -422,8 +422,7 @@ OverlayOp::labelIncompleteNode(Node *n, int targetIndex)
 	 * or BOUNDARY of a polygon we must merge
 	 * Z values of the intersected segment.
 	 * The intersection point has been already computed
-	 * by LineIntersector invoked by CGAlgorithms::isOnLine
-	 * invoked by PointLocator.
+	 * by LineIntersector invoked by PointLocator.
 	 */
 
 	// Only do this if input does have Z
diff --git a/src/precision/MinimumClearance.cpp b/src/precision/MinimumClearance.cpp
index 34e6b6a..efc8b13 100644
--- a/src/precision/MinimumClearance.cpp
+++ b/src/precision/MinimumClearance.cpp
@@ -16,7 +16,7 @@
  *
  **********************************************************************/
 
-#include <geos/algorithm/CGAlgorithms.h>
+#include <geos/algorithm/Distance.h>
 #include <geos/precision/MinimumClearance.h>
 #include <geos/index/strtree/STRtree.h>
 #include <geos/geom/GeometryFactory.h>
@@ -127,7 +127,7 @@ void MinimumClearance::compute() {
                     const Coordinate* seg1 = fs2->getCoordinate(i2);
 
                     if (! (p->equals2D(*seg0) || p->equals2D(*seg1))) {
-                        double d = geos::algorithm::CGAlgorithms::distancePointLine(*p, *seg0, *seg1);
+                        double d = geos::algorithm::Distance::pointToSegment(*p, *seg0, *seg1);
                         if (d < minDist) {
                             minDist = d;
                             updatePts(*p, *seg0, *seg1);
diff --git a/tests/unit/algorithm/CGAlgorithms/computeOrientationTest.cpp b/tests/unit/algorithm/CGAlgorithms/computeOrientationTest.cpp
index d403913..5590878 100644
--- a/tests/unit/algorithm/CGAlgorithms/computeOrientationTest.cpp
+++ b/tests/unit/algorithm/CGAlgorithms/computeOrientationTest.cpp
@@ -1,5 +1,5 @@
 //
-// Test Suite for CGAlgorithms::computeOrientation() function
+// Test Suite for Oriengation::index() function
 // Ported from JTS junit/algorithm/ComputeOrientationTest.java
 
 #include <tut/tut.hpp>

-----------------------------------------------------------------------

Summary of changes:
 include/geos/algorithm/Distance.h                  | 110 ++++++++++++
 include/geos/algorithm/Makefile.am                 |   1 +
 include/geos/geom/LineSegment.inl                  |  17 +-
 include/geos/operation/buffer/BufferBuilder.h      |   1 -
 include/geos/operation/overlay/MinimalEdgeRing.h   |   1 -
 src/algorithm/ConvexHull.cpp                       | 125 --------------
 src/algorithm/Distance.cpp                         | 188 +++++++++++++++++++++
 src/algorithm/LineIntersector.cpp                  |  14 +-
 src/algorithm/Makefile.am                          |   1 +
 src/operation/buffer/BufferBuilder.cpp             |   3 -
 src/operation/buffer/BufferInputLineSimplifier.cpp |   6 +-
 src/operation/buffer/OffsetCurveSetBuilder.cpp     |   4 +-
 src/operation/distance/DistanceOp.cpp              |  10 +-
 src/operation/distance/FacetSequence.cpp           |   6 +-
 src/operation/overlay/MaximalEdgeRing.cpp          |   1 -
 src/operation/overlay/OverlayOp.cpp                |   3 +-
 src/precision/MinimumClearance.cpp                 |   4 +-
 .../CGAlgorithms/computeOrientationTest.cpp        |   2 +-
 18 files changed, 331 insertions(+), 166 deletions(-)
 create mode 100644 include/geos/algorithm/Distance.h
 create mode 100644 src/algorithm/Distance.cpp


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list