@Test public void extractPartTest() { Point point1 = new Point(0, 0); Point point2 = new Point(1, 0); Point point3 = new Point(1, 1); LineString lineString = new LineString(); lineString.segments.add(new LineSegment(point1, point2)); lineString.segments.add(new LineSegment(point2, point3)); LineString extract1 = new LineString(); extract1.segments.add(new LineSegment(new Point(0, 0), new Point(0.5, 0))); LineString extract2 = new LineString(); extract2.segments.add(new LineSegment(new Point(0.5, 0), new Point(1, 0))); extract2.segments.add(new LineSegment(new Point(1, 0), new Point(1, 0.5))); LineString extract3 = new LineString(); extract3.segments.add(new LineSegment(new Point(1, 0.5), new Point(1, 1))); Assert.assertEquals(extract1, lineString.extractPart(0, 0.5)); Assert.assertEquals(extract2, lineString.extractPart(0.5, 1.5)); Assert.assertEquals(extract3, lineString.extractPart(1.5, 2)); }
public LineString extractPart(double startDistance, double endDistance) { LineString result = new LineString(); for (int i = 0; i < this.segments.size(); startDistance -= this.segments.get(i).length(), endDistance -= this.segments.get(i).length(), i++) { LineSegment segment = this.segments.get(i); double length = segment.length(); if (length < startDistance) { continue; } Point startPoint = null, endPoint = null; if (startDistance >= 0) { startPoint = segment.pointAlongLineSegment(startDistance); } if (endDistance < length) { endPoint = segment.pointAlongLineSegment(endDistance); } if (startPoint != null && endPoint == null) { result.segments.add(new LineSegment(startPoint, segment.end)); } else if (startPoint == null && endPoint == null) { result.segments.add(segment); } else if (startPoint == null && endPoint != null) { result.segments.add(new LineSegment(segment.start, endPoint)); } else if (startPoint != null && endPoint != null) { result.segments.add(new LineSegment(startPoint, endPoint)); } if (endPoint != null) break; } return result; }
LineString { public LineString extractPart(double startDistance, double endDistance) { LineString result = new LineString(); for (int i = 0; i < this.segments.size(); startDistance -= this.segments.get(i).length(), endDistance -= this.segments.get(i).length(), i++) { LineSegment segment = this.segments.get(i); double length = segment.length(); if (length < startDistance) { continue; } Point startPoint = null, endPoint = null; if (startDistance >= 0) { startPoint = segment.pointAlongLineSegment(startDistance); } if (endDistance < length) { endPoint = segment.pointAlongLineSegment(endDistance); } if (startPoint != null && endPoint == null) { result.segments.add(new LineSegment(startPoint, segment.end)); } else if (startPoint == null && endPoint == null) { result.segments.add(segment); } else if (startPoint == null && endPoint != null) { result.segments.add(new LineSegment(segment.start, endPoint)); } else if (startPoint != null && endPoint != null) { result.segments.add(new LineSegment(startPoint, endPoint)); } if (endPoint != null) break; } return result; } }
LineString { public LineString extractPart(double startDistance, double endDistance) { LineString result = new LineString(); for (int i = 0; i < this.segments.size(); startDistance -= this.segments.get(i).length(), endDistance -= this.segments.get(i).length(), i++) { LineSegment segment = this.segments.get(i); double length = segment.length(); if (length < startDistance) { continue; } Point startPoint = null, endPoint = null; if (startDistance >= 0) { startPoint = segment.pointAlongLineSegment(startDistance); } if (endDistance < length) { endPoint = segment.pointAlongLineSegment(endDistance); } if (startPoint != null && endPoint == null) { result.segments.add(new LineSegment(startPoint, segment.end)); } else if (startPoint == null && endPoint == null) { result.segments.add(segment); } else if (startPoint == null && endPoint != null) { result.segments.add(new LineSegment(segment.start, endPoint)); } else if (startPoint != null && endPoint != null) { result.segments.add(new LineSegment(startPoint, endPoint)); } if (endPoint != null) break; } return result; }  }
LineString { public LineString extractPart(double startDistance, double endDistance) { LineString result = new LineString(); for (int i = 0; i < this.segments.size(); startDistance -= this.segments.get(i).length(), endDistance -= this.segments.get(i).length(), i++) { LineSegment segment = this.segments.get(i); double length = segment.length(); if (length < startDistance) { continue; } Point startPoint = null, endPoint = null; if (startDistance >= 0) { startPoint = segment.pointAlongLineSegment(startDistance); } if (endDistance < length) { endPoint = segment.pointAlongLineSegment(endDistance); } if (startPoint != null && endPoint == null) { result.segments.add(new LineSegment(startPoint, segment.end)); } else if (startPoint == null && endPoint == null) { result.segments.add(segment); } else if (startPoint == null && endPoint != null) { result.segments.add(new LineSegment(segment.start, endPoint)); } else if (startPoint != null && endPoint != null) { result.segments.add(new LineSegment(startPoint, endPoint)); } if (endPoint != null) break; } return result; }  void LineString(); @Override boolean equals(Object obj); LineString extractPart(double startDistance, double endDistance); Rectangle getBounds(); Point interpolate(double distance); double length(); }
LineString { public LineString extractPart(double startDistance, double endDistance) { LineString result = new LineString(); for (int i = 0; i < this.segments.size(); startDistance -= this.segments.get(i).length(), endDistance -= this.segments.get(i).length(), i++) { LineSegment segment = this.segments.get(i); double length = segment.length(); if (length < startDistance) { continue; } Point startPoint = null, endPoint = null; if (startDistance >= 0) { startPoint = segment.pointAlongLineSegment(startDistance); } if (endDistance < length) { endPoint = segment.pointAlongLineSegment(endDistance); } if (startPoint != null && endPoint == null) { result.segments.add(new LineSegment(startPoint, segment.end)); } else if (startPoint == null && endPoint == null) { result.segments.add(segment); } else if (startPoint == null && endPoint != null) { result.segments.add(new LineSegment(segment.start, endPoint)); } else if (startPoint != null && endPoint != null) { result.segments.add(new LineSegment(startPoint, endPoint)); } if (endPoint != null) break; } return result; }  void LineString(); @Override boolean equals(Object obj); LineString extractPart(double startDistance, double endDistance); Rectangle getBounds(); Point interpolate(double distance); double length(); final List<LineSegment> segments; }