@Test public void interpolateTest() { 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)); Assert.assertEquals(point1, lineString.interpolate(0)); Assert.assertEquals(new Point(0.5, 0), lineString.interpolate(0.5)); Assert.assertEquals(point2, lineString.interpolate(1)); Assert.assertEquals(new Point(1, 0.5), lineString.interpolate(1.5)); Assert.assertEquals(point3, lineString.interpolate(2)); }
public Point interpolate(double distance) { if (distance < 0) { return null; } for (LineSegment segment : this.segments) { double length = segment.length(); if (distance <= length) { return segment.pointAlongLineSegment(distance); } distance -= length; } return null; }
LineString { public Point interpolate(double distance) { if (distance < 0) { return null; } for (LineSegment segment : this.segments) { double length = segment.length(); if (distance <= length) { return segment.pointAlongLineSegment(distance); } distance -= length; } return null; } }
LineString { public Point interpolate(double distance) { if (distance < 0) { return null; } for (LineSegment segment : this.segments) { double length = segment.length(); if (distance <= length) { return segment.pointAlongLineSegment(distance); } distance -= length; } return null; }  }
LineString { public Point interpolate(double distance) { if (distance < 0) { return null; } for (LineSegment segment : this.segments) { double length = segment.length(); if (distance <= length) { return segment.pointAlongLineSegment(distance); } distance -= length; } return null; }  void LineString(); @Override boolean equals(Object obj); LineString extractPart(double startDistance, double endDistance); Rectangle getBounds(); Point interpolate(double distance); double length(); }
LineString { public Point interpolate(double distance) { if (distance < 0) { return null; } for (LineSegment segment : this.segments) { double length = segment.length(); if (distance <= length) { return segment.pointAlongLineSegment(distance); } distance -= length; } return null; }  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; }