@Override public double length(Polyline p) { double d = 0; for (int i = 1; i < p.getPointCount(); ++i) { d += distance(p.getPoint(i - 1), p.getPoint(i)); } return d; }
@Override public Point interpolate(Polyline p, double l, double f) { assert (f >= 0 && f <= 1); Point a = p.getPoint(0); double d = l * f; double s = 0, ds = 0; if (f < 0 + 1E-10) { return p.getPoint(0); } if (f > 1 - 1E-10) { return p.getPoint(p.getPointCount() - 1); } for (int i = 1; i < p.getPointCount(); ++i) { Point b = p.getPoint(i); ds = distance(a, b); if ((s + ds) >= d) { return interpolate(a, b, (d - s) / ds); } s = s + ds; a = b; } return null; }
@Override public double azimuth(Polyline p, double l, double f) { assert (f >= 0 && f <= 1); Point a = p.getPoint(0); double d = l * f; double s = 0, ds = 0; if (f < 0 + 1E-10) { return azimuth(p.getPoint(0), p.getPoint(1), 0); } if (f > 1 - 1E-10) { return azimuth(p.getPoint(p.getPointCount() - 2), p.getPoint(p.getPointCount() - 1), f); } for (int i = 1; i < p.getPointCount(); ++i) { Point b = p.getPoint(i); ds = distance(a, b); if ((s + ds) >= d) { return azimuth(a, b, (d - s) / ds); } s = s + ds; a = b; } return Double.NaN; }
static Polyline invert(Polyline geometry) { Polyline reverse = new Polyline(); int last = geometry.getPointCount() - 1; reverse.startPath(geometry.getPoint(last)); for (int i = last - 1; i >= 0; --i) { reverse.lineTo(geometry.getPoint(i)); } return reverse; }
@Override public double intercept(Polyline p, Point c) { double d = Double.MAX_VALUE; Point a = p.getPoint(0); double s = 0, sf = 0, ds = 0; for (int i = 1; i < p.getPointCount(); ++i) { Point b = p.getPoint(i); ds = distance(a, b); double f_ = intercept(a, b, c); f_ = (f_ > 1) ? 1 : (f_ < 0) ? 0 : f_; Point x = interpolate(a, b, f_); double d_ = distance(c, x); if (d_ < d) { sf = (f_ * ds) + s; d = d_; } s = s + ds; a = b; } return s == 0 ? 0 : sf / s; }
/** * Asserts that the given polyline contains the expected coordinate values. */ private static void assertPolylineEquals(final double[] trajectory, final Polyline polyline) { assertEquals("pointCount", trajectory.length / 2, polyline.getPointCount()); for (int i=0; i < trajectory.length;) { final Point2D xy = polyline.getXY(i / 2); assertEquals("x", trajectory[i++], xy.x, STRICT); assertEquals("y", trajectory[i++], xy.y, STRICT); } } }
private Polyline monitorRoute(MatcherCandidate candidate) { Polyline routes = new Polyline(); MatcherCandidate predecessor = candidate; while (predecessor != null) { MatcherTransition transition = predecessor.transition(); if (transition != null) { Polyline route = transition.route().geometry(); routes.startPath(route.getPoint(0)); for (int i = 1; i < route.getPointCount(); ++i) { routes.lineTo(route.getPoint(i)); } } predecessor = predecessor.predecessor(); } return routes; }
assertEquals("pointCount", 3, p.getPointCount()); assertEquals("point(0)", new Point(15, 10), p.getPoint(0)); assertEquals("point(1)", new Point(25, 20), p.getPoint(1));
assertEquals("pointCount", 3, p.getPointCount()); assertEquals("point(0)", new Point(15, 10), p.getPoint(0)); assertEquals("point(1)", new Point(25, 20), p.getPoint(1));
Point a = source().edge().geometry().getPoint(0); for (int i = 1; i < source().edge().geometry().getPointCount(); ++i) { Point b = source().edge().geometry().getPoint(i); s += spatial.distance(a, b); Polyline segment = path().get(i).geometry(); for (int j = 1; j < segment.getPointCount(); ++j) { geometry.lineTo(segment.getPoint(j)); Point a = target().edge().geometry().getPoint(0); for (int i = 1; i < target().edge().geometry().getPointCount() - 1; ++i) { Point b = target().edge().geometry().getPoint(i); s += spatial.distance(a, b); Point a = source().edge().geometry().getPoint(0); for (int i = 1; i < source().edge().geometry().getPointCount() - 1; ++i) { Point b = source().edge().geometry().getPoint(i); s += spatial.distance(a, b);
Polyline polyline = (Polyline) geom; if (polyline.getPathCount() == 1 && polyline.getPointCount() == 2) { if (!polyline.getXY(0).equals(polyline.getXY(1))) return true; // vacuously true
Polyline polyline = (Polyline) geom; if (polyline.getPathCount() == 1 && polyline.getPointCount() == 2) { if (!polyline.getXY(0).equals(polyline.getXY(1))) return true; // vacuously true
interior_a.add(polyline_a, 0, polyline_a.getPointCount()); boolean b_interior_equals_point = RelationalOperations.multiPointEqualsPoint_(interior_a, point_b, tolerance, progress_tracker); relOps.m_matrix[MatrixPredicate.InteriorExterior] = (b_interior_equals_point ? -1 : 0);
interior_a.add(polyline_a, 0, polyline_a.getPointCount()); boolean b_interior_equals_point = RelationalOperations.multiPointEqualsPoint_(interior_a, point_b, tolerance, progress_tracker); relOps.m_matrix[MatrixPredicate.InteriorExterior] = (b_interior_equals_point ? -1 : 0);
if (polyline_b.getPointCount() > 10) { _polylineB = (Polyline) Clipper.clip(polyline_b, envInter, tolerance, 0.0);
if (polyline_b.getPointCount() > 10) { _polylineB = (Polyline) Clipper.clip(polyline_b, envInter, tolerance, 0.0);
if (polyline_b.getPointCount() > 10) { _polylineB = (Polyline) (Clipper.clip(polyline_b, envInter, tolerance, 0.0));
if (polyline_b.getPointCount() > 10) { _polylineB = (Polyline) (Clipper.clip(polyline_b, envInter, tolerance, 0.0));