1616import org .locationtech .jts .geom .Coordinate ;
1717import org .locationtech .jts .geom .CoordinateSequence ;
1818import org .locationtech .jts .geom .Envelope ;
19- import org .locationtech .jts .geom .Geometry ;
2019import org .locationtech .jts .geom .LineSegment ;
2120
2221/**
2322 * Represents a sequence of facets (points or line segments)
24- * of a {@link Geometry}
2523 * specified by a subsequence of a {@link CoordinateSequence}.
2624 *
2725 * @author Martin Davis
2826 *
2927 */
3028public class FacetSequence
3129{
32- private Geometry geom = null ;
3330 private CoordinateSequence pts ;
3431 private int start ;
35- private int end ;
36-
37- /**
38- * Creates a new sequence of facets based on a {@link CoordinateSequence}
39- * contained in the given {@link Geometry}.
40- *
41- * @param geom the geometry containing the facets
42- * @param pts the sequence containing the facet points
43- * @param start the index of the start point
44- * @param end the index of the end point + 1
45- */
46- public FacetSequence (Geometry geom , CoordinateSequence pts , int start , int end )
47- {
48- this .geom = geom ;
49- this .pts = pts ;
50- this .start = start ;
51- this .end = end ;
52- }
32+ private int end ;
5333
5434 /**
5535 * Creates a new sequence of facets based on a {@link CoordinateSequence}.
@@ -139,19 +119,19 @@ else if (isPointOther) {
139119 * and another sequence.
140120 * The locations are presented in the same order as the input sequences.
141121 *
142- * @return a pair of {@link GeometryLocation }s for the nearest points
122+ * @return a pair of {@link Coordinate }s for the nearest points
143123 */
144- public GeometryLocation [] nearestLocations (FacetSequence facetSeq )
124+ public Coordinate [] nearestLocations (FacetSequence facetSeq )
145125 {
146126 boolean isPoint = isPoint ();
147127 boolean isPointOther = facetSeq .isPoint ();
148- GeometryLocation [] locs = new GeometryLocation [2 ];
128+ Coordinate [] locs = new Coordinate [2 ];
149129
150130 if (isPoint && isPointOther ) {
151131 Coordinate pt = pts .getCoordinate (start );
152132 Coordinate seqPt = facetSeq .pts .getCoordinate (facetSeq .start );
153- locs [0 ] = new GeometryLocation ( geom , start , new Coordinate ( pt ) );
154- locs [1 ] = new GeometryLocation ( facetSeq . geom , facetSeq . start , new Coordinate ( seqPt ) );
133+ locs [0 ] = pt . copy ( );
134+ locs [1 ] = seqPt . copy ( );
155135 }
156136 else if (isPoint ) {
157137 Coordinate pt = pts .getCoordinate (start );
@@ -161,7 +141,7 @@ else if (isPointOther) {
161141 Coordinate seqPt = facetSeq .pts .getCoordinate (facetSeq .start );
162142 computeDistancePointLine (seqPt , this , locs );
163143 // unflip the locations
164- GeometryLocation tmp = locs [0 ];
144+ Coordinate tmp = locs [0 ];
165145 locs [0 ] = locs [1 ];
166146 locs [1 ] = tmp ;
167147 }
@@ -171,7 +151,7 @@ else if (isPointOther) {
171151 return locs ;
172152 }
173153
174- private double computeDistanceLineLine (FacetSequence facetSeq , GeometryLocation [] locs )
154+ private double computeDistanceLineLine (FacetSequence facetSeq , Coordinate [] locs )
175155 {
176156 // both linear - compute minimum segment-segment distance
177157 double minDistance = Double .MAX_VALUE ;
@@ -195,15 +175,15 @@ private double computeDistanceLineLine(FacetSequence facetSeq, GeometryLocation[
195175 }
196176
197177 private void updateNearestLocationsLineLine (int i , Coordinate p0 , Coordinate p1 , FacetSequence facetSeq , int j ,
198- Coordinate q0 , Coordinate q1 , GeometryLocation [] locs ) {
178+ Coordinate q0 , Coordinate q1 , Coordinate [] locs ) {
199179 LineSegment seg0 = new LineSegment (p0 , p1 );
200180 LineSegment seg1 = new LineSegment (q0 , q1 );
201181 Coordinate [] closestPt = seg0 .closestPoints (seg1 );
202- locs [0 ] = new GeometryLocation ( geom , i , new Coordinate ( closestPt [0 ]) );
203- locs [1 ] = new GeometryLocation ( facetSeq . geom , j , new Coordinate ( closestPt [1 ]) );
182+ locs [0 ] = closestPt [0 ]. copy ( );
183+ locs [1 ] = closestPt [1 ]. copy ( );
204184 }
205185
206- private double computeDistancePointLine (Coordinate pt , FacetSequence facetSeq , GeometryLocation [] locs )
186+ private double computeDistancePointLine (Coordinate pt , FacetSequence facetSeq , Coordinate [] locs )
207187 {
208188 double minDistance = Double .MAX_VALUE ;
209189
@@ -222,11 +202,11 @@ private double computeDistancePointLine(Coordinate pt, FacetSequence facetSeq, G
222202
223203 private void updateNearestLocationsPointLine (Coordinate pt ,
224204 FacetSequence facetSeq , int i , Coordinate q0 , Coordinate q1 ,
225- GeometryLocation [] locs ) {
226- locs [0 ] = new GeometryLocation ( geom , start , new Coordinate ( pt ) );
205+ Coordinate [] locs ) {
206+ locs [0 ] = pt . copy ( );
227207 LineSegment seg = new LineSegment (q0 , q1 );
228208 Coordinate segClosestPoint = seg .closestPoint (pt );
229- locs [1 ] = new GeometryLocation ( facetSeq . geom , i , new Coordinate ( segClosestPoint ) );
209+ locs [1 ] = segClosestPoint . copy ( );
230210 }
231211
232212 public String toString ()
0 commit comments