[geos-commits] r2477 - in trunk/source: algorithm
headers/geos/algorithm headers/geos/index/chain index/chain
noding/snapround
svn_geos at osgeo.org
svn_geos at osgeo.org
Wed May 6 13:10:01 EDT 2009
Author: strk
Date: 2009-05-06 13:10:01 -0400 (Wed, 06 May 2009)
New Revision: 2477
Modified:
trunk/source/algorithm/MCPointInRing.cpp
trunk/source/headers/geos/algorithm/MCPointInRing.h
trunk/source/headers/geos/index/chain/MonotoneChainSelectAction.h
trunk/source/index/chain/MonotoneChain.cpp
trunk/source/index/chain/MonotoneChainSelectAction.cpp
trunk/source/noding/snapround/MCIndexPointSnapper.cpp
Log:
MonotoneChainSelectAction port review, heap allocation reduced, const-corrected.
Modified: trunk/source/algorithm/MCPointInRing.cpp
===================================================================
--- trunk/source/algorithm/MCPointInRing.cpp 2009-05-06 16:44:06 UTC (rev 2476)
+++ trunk/source/algorithm/MCPointInRing.cpp 2009-05-06 17:10:01 UTC (rev 2477)
@@ -36,15 +36,18 @@
MCPointInRing::MCSelecter::MCSelecter(const Coordinate& newP,
MCPointInRing *prt)
+ :
+ MonotoneChainSelectAction()
{
p=newP;
parent=prt;
}
+/* public overridden */
void
-MCPointInRing::MCSelecter::select(LineSegment *ls)
+MCPointInRing::MCSelecter::select(const LineSegment& ls)
{
- parent->testLineSegment(p,ls);
+ parent->testLineSegment(p, ls);
}
MCPointInRing::MCPointInRing(const LinearRing *newRing)
@@ -138,7 +141,7 @@
}
void
-MCPointInRing::testLineSegment(Coordinate& p,LineSegment *seg)
+MCPointInRing::testLineSegment(const Coordinate& p, const LineSegment& seg)
{
double xInt; // x intersection of segment with ray
double x1; // translated coordinates
@@ -147,23 +150,26 @@
double y2;
/*
- * Test if segment crosses ray from test point in positive x direction.
- */
- Coordinate& p1=seg->p0;
- Coordinate& p2=seg->p1;
- x1=p1.x-p.x;
- y1=p1.y-p.y;
- x2=p2.x-p.x;
- y2=p2.y-p.y;
- if (((y1>0)&&(y2<=0)) || ((y2>0)&&(y1<=0))) {
+ * Test if segment crosses ray from test point in positive x direction.
+ */
+ const Coordinate& p1 = seg.p0;
+ const Coordinate& p2 = seg.p1;
+ x1 = p1.x - p.x;
+ y1 = p1.y - p.y;
+ x2 = p2.x - p.x;
+ y2 = p2.y - p.y;
+
+ if (((y1>0)&&(y2<=0)) || ((y2>0)&&(y1<=0)))
+ {
+
/*
- * segment straddles x axis, so compute intersection.
- */
+ * segment straddles x axis, so compute intersection.
+ */
xInt=RobustDeterminant::signOfDet2x2(x1,y1,x2,y2)/(y2-y1);
- //xsave=xInt;
+
/*
- * crosses ray if strictly positive intersection.
- */
+ * crosses ray if strictly positive intersection.
+ */
if (0.0<xInt) {
crossings++;
}
Modified: trunk/source/headers/geos/algorithm/MCPointInRing.h
===================================================================
--- trunk/source/headers/geos/algorithm/MCPointInRing.h 2009-05-06 16:44:06 UTC (rev 2476)
+++ trunk/source/headers/geos/algorithm/MCPointInRing.h 2009-05-06 17:10:01 UTC (rev 2477)
@@ -52,8 +52,10 @@
MCPointInRing(const geom::LinearRing *newRing);
~MCPointInRing();
bool isInside(const geom::Coordinate& pt);
- void testLineSegment(geom::Coordinate& p, geom::LineSegment *seg);
+ void testLineSegment(const geom::Coordinate& p,
+ const geom::LineSegment& seg);
+
class MCSelecter: public index::chain::MonotoneChainSelectAction {
using MonotoneChainSelectAction::select;
private:
@@ -61,7 +63,7 @@
MCPointInRing *parent;
public:
MCSelecter(const geom::Coordinate& newP, MCPointInRing *prt);
- void select(geom::LineSegment *ls);
+ void select(const geom::LineSegment& ls);
};
private:
Modified: trunk/source/headers/geos/index/chain/MonotoneChainSelectAction.h
===================================================================
--- trunk/source/headers/geos/index/chain/MonotoneChainSelectAction.h 2009-05-06 16:44:06 UTC (rev 2476)
+++ trunk/source/headers/geos/index/chain/MonotoneChainSelectAction.h 2009-05-06 17:10:01 UTC (rev 2477)
@@ -11,18 +11,21 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: index/chain/MonotoneChainSelectAction.java rev. 1.6 (JTS-1.10)
+ *
**********************************************************************/
#ifndef GEOS_IDX_CHAIN_MONOTONECHAINSELECTACTION_H
#define GEOS_IDX_CHAIN_MONOTONECHAINSELECTACTION_H
+#include <geos/geom/LineSegment.h> // composition
+#include <geos/geom/Envelope.h> // composition
+
// Forward declarations
namespace geos {
- namespace geom {
- class Envelope;
- class LineSegment;
- }
namespace index {
namespace chain {
class MonotoneChain;
@@ -38,32 +41,33 @@
* The action for the internal iterator for performing
* Envelope select queries on a MonotoneChain
*
- * Last port: index/chain/MonotoneChainSelectAction.java rev. 1.6 (JTS-1.7)
*/
class MonotoneChainSelectAction {
protected:
- geom::LineSegment* selectedSegment;
+ geom::LineSegment selectedSegment;
public:
- MonotoneChainSelectAction();
+ MonotoneChainSelectAction() {}
- virtual ~MonotoneChainSelectAction();
+ virtual ~MonotoneChainSelectAction() {}
/// This function can be overridden if the original chain is needed
virtual void select(MonotoneChain& mc, unsigned int start);
/**
- * This is a convenience function which can be overridden to obtain the actual
- * line segment which is selected
+ * This is a convenience function which can be overridden
+ * to obtain the actual line segment which is selected
+ *
* @param seg
*/
- virtual void select(geom::LineSegment* newSeg)=0;
+ virtual void select(const geom::LineSegment& seg) = 0;
// these envelopes are used during the MonotoneChain search process
- geom::Envelope* tempEnv1;
+ // should only be visible by classes in this package
+ geom::Envelope tempEnv1;
};
Modified: trunk/source/index/chain/MonotoneChain.cpp
===================================================================
--- trunk/source/index/chain/MonotoneChain.cpp 2009-05-06 16:44:06 UTC (rev 2476)
+++ trunk/source/index/chain/MonotoneChain.cpp 2009-05-06 17:10:01 UTC (rev 2477)
@@ -86,7 +86,7 @@
{
const Coordinate& p0=pts[start0];
const Coordinate& p1=pts[end0];
- mcs.tempEnv1->init(p0,p1);
+ mcs.tempEnv1.init(p0,p1);
//Debug.println("trying:"+p0+p1+" [ "+start0+","+end0+" ]");
// terminating condition for the recursion
Modified: trunk/source/index/chain/MonotoneChainSelectAction.cpp
===================================================================
--- trunk/source/index/chain/MonotoneChainSelectAction.cpp 2009-05-06 16:44:06 UTC (rev 2476)
+++ trunk/source/index/chain/MonotoneChainSelectAction.cpp 2009-05-06 17:10:01 UTC (rev 2477)
@@ -12,6 +12,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: index/chain/MonotoneChainSelectAction.java rev. 1.6 (JTS-1.10)
+ *
**********************************************************************/
#include <geos/index/chain/MonotoneChainSelectAction.h>
@@ -24,22 +28,11 @@
namespace index { // geos.index
namespace chain { // geos.index.chain
-MonotoneChainSelectAction::MonotoneChainSelectAction()
-{
- selectedSegment=new geom::LineSegment();
- tempEnv1=new geom::Envelope();
-}
-
-MonotoneChainSelectAction::~MonotoneChainSelectAction()
-{
- delete selectedSegment;
- delete tempEnv1;
-}
-
void
MonotoneChainSelectAction::select(MonotoneChain& mc, unsigned int start)
{
- mc.getLineSegment(start, *selectedSegment);
+ mc.getLineSegment(start, selectedSegment);
+
select(selectedSegment);
}
Modified: trunk/source/noding/snapround/MCIndexPointSnapper.cpp
===================================================================
--- trunk/source/noding/snapround/MCIndexPointSnapper.cpp 2009-05-06 16:44:06 UTC (rev 2476)
+++ trunk/source/noding/snapround/MCIndexPointSnapper.cpp 2009-05-06 17:10:01 UTC (rev 2477)
@@ -51,6 +51,7 @@
SegmentString* nParentEdge,
unsigned int nVertexIndex)
:
+ MonotoneChainSelectAction(),
hotPixel(nHotPixel),
parentEdge(nParentEdge),
vertexIndex(nVertexIndex),
@@ -74,10 +75,10 @@
isNodeAddedVar = hotPixel.addSnappedNode(ss, startIndex);
}
- void select(LineSegment* ls)
- {
- UNREFERENCED_PARAMETER(ls);
- }
+ void select(const LineSegment& ls)
+ {
+ UNREFERENCED_PARAMETER(ls);
+ }
};
More information about the geos-commits
mailing list