protected static boolean retrievePoints(float length, LinkedList points,
LinkedList polysegment) {
polysegment.clear();
// first point
Point2D point = (Point2D) points.removeFirst();
;
polysegment.add(point);
double consumedLength = 0.0;
double norm = 0.0;
Point2D nextPoint = null;
while (consumedLength < length && points.size() > 0) {
// consume points while distance is not reached
nextPoint = (Point2D) points.removeFirst();
polysegment.add(nextPoint);
norm = LineUtil.norm(point, nextPoint);
consumedLength += norm;
point = nextPoint;
}
if (consumedLength == length) {
// we got the exact distance with an existing point.
// we need to copy the last point back: it will be the
// first for the next call
points.addFirst(point);
return true;
} else {
if (consumedLength > length) {
// we went too far, we need to put back the last point
points.addFirst(polysegment.removeLast());
consumedLength -= norm;
// and interpolate a new point
point = (Point2D) polysegment.getLast();
double d = length - consumedLength;
// between point and nextPoint at distance d
Point2D interp = LineUtil.interpolatedPoint(point, nextPoint, d);
polysegment.add(interp);
points.addFirst(interp);
return true;
} else {
// no more points !