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;
    }
@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));
    }