1616 *
1717 **********************************************************************/
1818
19+ #include < geos/geom/Geometry.h>
20+ #include < geos/geom/LineSegment.h>
1921#include < geos/algorithm/Distance.h>
2022#include < geos/operation/distance/FacetSequence.h>
2123
@@ -25,20 +27,11 @@ using namespace geos::geom;
2527using namespace geos ::operation::distance;
2628using namespace geos ::algorithm;
2729
28- FacetSequence::FacetSequence (const Geometry *p_geom, const CoordinateSequence* p_pts, std::size_t p_start, std::size_t p_end) :
29- pts(p_pts),
30- start(p_start),
31- end(p_end),
32- geom(p_geom)
33- {
34- computeEnvelope ();
35- }
3630
37- FacetSequence::FacetSequence (const CoordinateSequence* p_pts, std::size_t p_start, std::size_t p_end) :
38- pts(p_pts),
39- start(p_start),
40- end(p_end),
41- geom(nullptr )
31+ FacetSequence::FacetSequence (const CoordinateSequence* p_pts, std::size_t p_start, std::size_t p_end)
32+ : pts(p_pts)
33+ , start(p_start)
34+ , end(p_end)
4235{
4336 computeEnvelope ();
4437}
@@ -61,16 +54,16 @@ FacetSequence::distance(const FacetSequence& facetSeq) const
6154 bool isPointThis = isPoint ();
6255 bool isPointOther = facetSeq.isPoint ();
6356
64- if (isPointThis && isPointOther) {
57+ if (isPointThis && isPointOther) {
6558 const Coordinate& pt = pts->getAt (start);
6659 const Coordinate& seqPt = facetSeq.pts ->getAt (facetSeq.start );
6760 return pt.distance (seqPt);
6861 }
69- else if (isPointThis) {
62+ else if (isPointThis) {
7063 const Coordinate& pt = pts->getAt (start);
7164 return computeDistancePointLine (pt, facetSeq, nullptr );
7265 }
73- else if (isPointOther) {
66+ else if (isPointOther) {
7467 const Coordinate& seqPt = facetSeq.pts ->getAt (facetSeq.start );
7568 return computeDistancePointLine (seqPt, *this , nullptr );
7669 }
@@ -84,20 +77,18 @@ FacetSequence::distance(const FacetSequence& facetSeq) const
8477* just return the whole mess, since it only ends up holding two
8578* locations.
8679*/
87- std::vector<GeometryLocation >
80+ std::vector<Coordinate >
8881FacetSequence::nearestLocations (const FacetSequence& facetSeq) const
8982{
9083 bool isPointThis = isPoint ();
9184 bool isPointOther = facetSeq.isPoint ();
92- std::vector<GeometryLocation > locs;
85+ std::vector<Coordinate > locs;
9386 if (isPointThis && isPointOther) {
9487 const Coordinate& pt = pts->getAt (start);
9588 const Coordinate& seqPt = facetSeq.pts ->getAt (facetSeq.start );
96- GeometryLocation gl1 (geom, start, pt);
97- GeometryLocation gl2 (facetSeq.geom , facetSeq.start , seqPt);
9889 locs.clear ();
99- locs.push_back (gl1 );
100- locs.push_back (gl2 );
90+ locs.push_back (pt );
91+ locs.push_back (seqPt );
10192 }
10293 else if (isPointThis) {
10394 const Coordinate& pt = pts->getAt (start);
@@ -107,7 +98,7 @@ FacetSequence::nearestLocations(const FacetSequence& facetSeq) const
10798 const Coordinate& seqPt = facetSeq.pts ->getAt (facetSeq.start );
10899 computeDistancePointLine (seqPt, *this , &locs);
109100 // unflip the locations
110- GeometryLocation tmp = locs[0 ];
101+ Coordinate tmp = locs[0 ];
111102 locs[0 ] = locs[1 ];
112103 locs[1 ] = tmp;
113104 }
@@ -120,20 +111,20 @@ FacetSequence::nearestLocations(const FacetSequence& facetSeq) const
120111double
121112FacetSequence::computeDistancePointLine (const Coordinate& pt,
122113 const FacetSequence& facetSeq,
123- std::vector<GeometryLocation > *locs) const
114+ std::vector<Coordinate > *locs) const
124115{
125116 double minDistance = DoubleInfinity;
126117
127- for (std::size_t i = facetSeq.start ; i < facetSeq.end - 1 ; i++) {
118+ for (std::size_t i = facetSeq.start ; i < facetSeq.end - 1 ; i++) {
128119 const Coordinate& q0 = facetSeq.pts ->getAt (i);
129120 const Coordinate& q1 = facetSeq.pts ->getAt (i + 1 );
130121 double dist = Distance::pointToSegment (pt, q0, q1);
131- if (dist < minDistance || (locs != nullptr && locs->empty ())) {
122+ if (dist < minDistance || (locs != nullptr && locs->empty ())) {
132123 minDistance = dist;
133124 if (locs != nullptr ) {
134- updateNearestLocationsPointLine (pt, facetSeq, i, q0, q1, locs);
125+ updateNearestLocationsPointLine (pt, q0, q1, locs);
135126 }
136- if (minDistance <= 0.0 ) {
127+ if (minDistance <= 0.0 ) {
137128 return minDistance;
138129 }
139130 }
@@ -143,22 +134,21 @@ FacetSequence::computeDistancePointLine(const Coordinate& pt,
143134}
144135
145136void
146- FacetSequence::updateNearestLocationsPointLine (const Coordinate& pt,
147- const FacetSequence& facetSeq, std::size_t i,
148- const Coordinate& q0, const Coordinate &q1,
149- std::vector<GeometryLocation> *locs) const
137+ FacetSequence::updateNearestLocationsPointLine (
138+ const Coordinate& pt, const Coordinate& q0, const Coordinate &q1,
139+ std::vector<Coordinate> *locs) const
150140{
151- geom:: LineSegment seg (q0, q1);
141+ LineSegment seg (q0, q1);
152142 Coordinate segClosestPoint;
153143 seg.closestPoint (pt, segClosestPoint);
154144 locs->clear ();
155- locs->emplace_back (geom, start, pt);
156- locs->emplace_back (facetSeq. geom , i, segClosestPoint);
145+ locs->push_back ( pt);
146+ locs->push_back ( segClosestPoint);
157147 return ;
158148}
159149
160150double
161- FacetSequence::computeDistanceLineLine (const FacetSequence& facetSeq, std::vector<GeometryLocation > *locs) const
151+ FacetSequence::computeDistanceLineLine (const FacetSequence& facetSeq, std::vector<Coordinate > *locs) const
162152{
163153 double minDistance = DoubleInfinity;
164154
@@ -192,7 +182,7 @@ FacetSequence::computeDistanceLineLine(const FacetSequence& facetSeq, std::vecto
192182 if (dist <= minDistance) {
193183 minDistance = dist;
194184 if (locs != nullptr ) {
195- updateNearestLocationsLineLine (i, p0, p1, facetSeq, j , q0, q1, locs);
185+ updateNearestLocationsLineLine (p0, p1, q0, q1, locs);
196186 }
197187 if (minDistance <= 0.0 ) return minDistance;
198188 }
@@ -203,19 +193,19 @@ FacetSequence::computeDistanceLineLine(const FacetSequence& facetSeq, std::vecto
203193}
204194
205195void
206- FacetSequence::updateNearestLocationsLineLine (std:: size_t i, const Coordinate& p0, const Coordinate& p1,
207- const FacetSequence& facetSeq ,
208- std:: size_t j, const Coordinate& q0, const Coordinate &q1,
209- std::vector<GeometryLocation > *locs) const
196+ FacetSequence::updateNearestLocationsLineLine (
197+ const Coordinate& p0, const Coordinate& p1 ,
198+ const Coordinate& q0, const Coordinate &q1,
199+ std::vector<Coordinate > *locs) const
210200{
211201 LineSegment seg0 (p0, p1);
212202 LineSegment seg1 (q0, q1);
213203
214204 auto closestPts = seg0.closestPoints (seg1);
215205
216206 locs->clear ();
217- locs->emplace_back (geom, i, closestPts[0 ]);
218- locs->emplace_back (facetSeq. geom , j, closestPts[1 ]);
207+ locs->push_back ( closestPts[0 ]);
208+ locs->push_back ( closestPts[1 ]);
219209}
220210
221211void
0 commit comments