[geos-commits] r2312 - in trunk/source: algorithm
headers/geos/algorithm
svn_geos at osgeo.org
svn_geos at osgeo.org
Tue Apr 7 04:14:25 EDT 2009
Author: strk
Date: 2009-04-07 04:14:25 -0400 (Tue, 07 Apr 2009)
New Revision: 2312
Modified:
trunk/source/algorithm/HCoordinate.cpp
trunk/source/headers/geos/algorithm/HCoordinate.h
Log:
Sync HCoordinate class to JTS-1.9 (rev 1.18)
Modified: trunk/source/algorithm/HCoordinate.cpp
===================================================================
--- trunk/source/algorithm/HCoordinate.cpp 2009-04-03 15:27:05 UTC (rev 2311)
+++ trunk/source/algorithm/HCoordinate.cpp 2009-04-07 08:14:25 UTC (rev 2312)
@@ -14,7 +14,7 @@
*
**********************************************************************
*
- * Last port: algorithm/HCoordinate.java rev. 1.17 (JTS-1.7)
+ * Last port: algorithm/HCoordinate.java rev. 1.18 (JTS-1.9)
*
**********************************************************************/
@@ -42,6 +42,74 @@
namespace geos {
namespace algorithm { // geos.algorithm
+///*public static*/
+//void
+//HCoordinate::OLDintersection(const Coordinate &p1, const Coordinate &p2,
+// const Coordinate &q1, const Coordinate &q2, Coordinate &ret)
+//{
+//
+//#if GEOS_DEBUG
+// cerr << __FUNCTION__ << ":" << endl
+// << setprecision(20)
+// << " p1: " << p1 << endl
+// << " p2: " << p2 << endl
+// << " q1: " << q1 << endl
+// << " q2: " << q2 << endl;
+//#endif
+//
+// HCoordinate hc1p1(p1);
+//
+//#if GEOS_DEBUG
+// cerr << "HCoordinate(p1): "
+// << hc1p1 << endl;
+//#endif
+//
+// HCoordinate hc1p2(p2);
+//
+//#if GEOS_DEBUG
+// cerr << "HCoordinate(p2): "
+// << hc1p2 << endl;
+//#endif
+//
+// HCoordinate l1(hc1p1, hc1p2);
+//
+//#if GEOS_DEBUG
+// cerr << "L1 - HCoordinate(HCp1, HCp2): "
+// << l1 << endl;
+//#endif
+//
+// HCoordinate hc2q1(q1);
+//
+//#if GEOS_DEBUG
+// cerr << "HCoordinate(q1): "
+// << hc2q1 << endl;
+//#endif
+//
+// HCoordinate hc2q2(q2);
+//
+//#if GEOS_DEBUG
+// cerr << "HCoordinate(q2): "
+// << hc2q2 << endl;
+//#endif
+//
+// HCoordinate l2(hc2q1, hc2q2);
+//
+//#if GEOS_DEBUG
+// cerr << "L2 - HCoordinate(HCq1, HCq2): "
+// << l2 << endl;
+//#endif
+//
+// HCoordinate intHCoord(l1, l2);
+//
+//#if GEOS_DEBUG
+// cerr << "HCoordinate(L1, L2): "
+// << intHCoord << endl;
+//#endif
+//
+// intHCoord.getCoordinate(ret);
+//
+//}
+
/*public static*/
void
HCoordinate::intersection(const Coordinate &p1, const Coordinate &p2,
@@ -57,57 +125,29 @@
<< " q2: " << q2 << endl;
#endif
- HCoordinate hc1p1(p1);
+ // unrolled computation
-#if GEOS_DEBUG
- cerr << "HCoordinate(p1): "
- << hc1p1 << endl;
-#endif
+ double px = p1.y - p2.y;
+ double py = p2.x - p1.x;
+ double pw = p1.x * p2.y - p2.x * p1.y;
- HCoordinate hc1p2(p2);
+ double qx = q1.y - q2.y;
+ double qy = q2.x - q1.x;
+ double qw = q1.x * q2.y - q2.x * q1.y;
-#if GEOS_DEBUG
- cerr << "HCoordinate(p2): "
- << hc1p2 << endl;
-#endif
+ double x = py * qw - qy * pw;
+ double y = qx * pw - px * qw;
+ double w = px * qy - qx * py;
- HCoordinate l1(hc1p1, hc1p2);
+ double xInt = x/w;
+ double yInt = y/w;
-#if GEOS_DEBUG
- cerr << "L1 - HCoordinate(HCp1, HCp2): "
- << l1 << endl;
-#endif
+ if ( (!FINITE(xInt)) || (!FINITE(yInt)) )
+ {
+ throw new NotRepresentableException();
+ }
- HCoordinate hc2q1(q1);
-
-#if GEOS_DEBUG
- cerr << "HCoordinate(q1): "
- << hc2q1 << endl;
-#endif
-
- HCoordinate hc2q2(q2);
-
-#if GEOS_DEBUG
- cerr << "HCoordinate(q2): "
- << hc2q2 << endl;
-#endif
-
- HCoordinate l2(hc2q1, hc2q2);
-
-#if GEOS_DEBUG
- cerr << "L2 - HCoordinate(HCq1, HCq2): "
- << l2 << endl;
-#endif
-
- HCoordinate intHCoord(l1, l2);
-
-#if GEOS_DEBUG
- cerr << "HCoordinate(L1, L2): "
- << intHCoord << endl;
-#endif
-
- intHCoord.getCoordinate(ret);
-
+ ret = Coordinate(xInt, yInt);
}
/*public*/
@@ -138,6 +178,34 @@
}
/*public*/
+HCoordinate::HCoordinate(const Coordinate& p1, const Coordinate& p2)
+ :
+ // optimization when it is known that w = 1
+ x ( p1.y - p2.y ),
+ y ( p2.x - p1.x ),
+ w ( p1.x * p2.y - p2.x * p1.y )
+{
+}
+
+/*public*/
+HCoordinate::HCoordinate(const Coordinate& p1, const Coordinate& p2,
+ const Coordinate& q1, const Coordinate& q2)
+{
+ // unrolled computation
+ double px = p1.y - p2.y;
+ double py = p2.x - p1.x;
+ double pw = p1.x * p2.y - p2.x * p1.y;
+
+ double qx = q1.y - q2.y;
+ double qy = q2.x - q1.x;
+ double qw = q1.x * q2.y - q2.x * q1.y;
+
+ x = py * qw - qy * pw;
+ y = qx * pw - px * qw;
+ w = px * qy - qx * py;
+}
+
+/*public*/
#ifndef STORE_INTERMEDIATE_COMPUTATION_VALUES
HCoordinate::HCoordinate(const HCoordinate &p1, const HCoordinate &p2)
@@ -185,7 +253,8 @@
{
long double a = x/w;
- if (std::fabs(a) > std::numeric_limits<double>::max())
+ //if (std::fabs(a) > std::numeric_limits<double>::max())
+ if ( !FINITE(a) )
{
throw NotRepresentableException();
}
@@ -198,7 +267,8 @@
{
long double a = y/w;
- if (std::fabs(a) > std::numeric_limits<double>::max())
+ //if (std::fabs(a) > std::numeric_limits<double>::max())
+ if ( !FINITE(a) )
{
throw NotRepresentableException();
}
Modified: trunk/source/headers/geos/algorithm/HCoordinate.h
===================================================================
--- trunk/source/headers/geos/algorithm/HCoordinate.h 2009-04-03 15:27:05 UTC (rev 2311)
+++ trunk/source/headers/geos/algorithm/HCoordinate.h 2009-04-07 08:14:25 UTC (rev 2312)
@@ -14,7 +14,7 @@
*
**********************************************************************
*
- * Last port: algorithm/HCoordinate.java rev. 1.17 (JTS-1.7)
+ * Last port: algorithm/HCoordinate.java rev. 1.18 (JTS-1.9)
*
**********************************************************************/
@@ -47,17 +47,20 @@
friend std::ostream& operator<< (std::ostream& o, const HCoordinate& c);
/** \brief
- * Computes the (approximate) intersection point between two line segments
- * using homogeneous coordinates.
+ * Computes the (approximate) intersection point between two line
+ * segments using homogeneous coordinates.
*
* Note that this algorithm is
* not numerically stable; i.e. it can produce intersection points which
* lie outside the envelope of the line segments themselves. In order
- * to increase the precision of the calculation input points should be normalized
- * before passing them to this routine.
+ * to increase the precision of the calculation input points should be
+ * normalized before passing them to this routine.
*/
- static void intersection(const geom::Coordinate &p1, const geom::Coordinate &p2,
- const geom::Coordinate &q1, const geom::Coordinate &q2, geom::Coordinate &ret);
+ static void intersection(const geom::Coordinate &p1,
+ const geom::Coordinate &p2,
+ const geom::Coordinate &q1,
+ const geom::Coordinate &q2,
+ geom::Coordinate &ret);
long double x,y,w;
@@ -67,6 +70,19 @@
HCoordinate(const geom::Coordinate& p);
+ /** \brief
+ * Constructs a homogeneous coordinate which is the intersection
+ * of the lines define by the homogenous coordinates represented
+ * by two {@link Coordinate}s.
+ *
+ * @param p1
+ * @param p2
+ */
+ HCoordinate(const geom::Coordinate& p1, const geom::Coordinate& p2);
+
+ HCoordinate(const geom::Coordinate& p1, const geom::Coordinate& p2,
+ const geom::Coordinate& q1, const geom::Coordinate& q2);
+
HCoordinate(const HCoordinate &p1, const HCoordinate &p2);
long double getX() const;
More information about the geos-commits
mailing list