int segType; segments.add(new PathSegment(PathIterator.SEG_MOVETO, 0f, 0f, 0f, origIndex)); switch (segType) { case PathIterator.SEG_MOVETO: segments.add(new PathSegment(segType, seg[0], seg[1], pathLength, origIndex)); currentX = seg[0]; pathLength += Point2D.distance(currentX, currentY, seg[0], seg[1]); segments.add(new PathSegment(segType, seg[0], seg[1], pathLength, origIndex)); currentX = seg[0]; pathLength += Point2D.distance(currentX, currentY, lastMoveX, lastMoveY); segments.add(new PathSegment(PathIterator.SEG_LINETO, lastMoveX, lastMoveY, pathLength, origIndex)); pathLength += Point2D.distance(currentX, currentY, seg[0], seg[1]); segments.add(new PathSegment(segType, seg[0], seg[1], pathLength, origIndex));
/** * Returns the index of the segment at the given distance along the path. */ public int segmentAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return -1; } if (upperIndex == 0) { // Length was probably zero, so return the upper segment. PathSegment upper = (PathSegment) segments.get(upperIndex); return upper.getIndex(); } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); return lower.getIndex(); }
int curr = (lb + ub) >> 1; PathSegment ps = (PathSegment) segments.get(curr); if (ps.getLength() >= length) { ub = curr; } else { if (ps.getSegType() != PathIterator.SEG_MOVETO || ub == segments.size() - 1) { break; while (upperIndex <= 0 && currentIndex < numSegments) { PathSegment ps = (PathSegment) segments.get(currentIndex); if (ps.getLength() >= length && ps.getSegType() != PathIterator.SEG_MOVETO) { upperIndex = currentIndex;
int segType; segments.add(new PathSegment(PathIterator.SEG_MOVETO, 0f, 0f, 0f, origIndex)); switch (segType) { case PathIterator.SEG_MOVETO: segments.add(new PathSegment(segType, seg[0], seg[1], pathLength, origIndex)); currentX = seg[0]; pathLength += Point2D.distance(currentX, currentY, seg[0], seg[1]); segments.add(new PathSegment(segType, seg[0], seg[1], pathLength, origIndex)); currentX = seg[0]; pathLength += Point2D.distance(currentX, currentY, lastMoveX, lastMoveY); segments.add(new PathSegment(PathIterator.SEG_LINETO, lastMoveX, lastMoveY, pathLength, origIndex)); pathLength += Point2D.distance(currentX, currentY, seg[0], seg[1]); segments.add(new PathSegment(segType, seg[0], seg[1], pathLength, origIndex));
int segType; segments.add(new PathSegment(PathIterator.SEG_MOVETO, 0f, 0f, 0f, origIndex)); switch (segType) { case PathIterator.SEG_MOVETO: segments.add(new PathSegment(segType, seg[0], seg[1], pathLength, origIndex)); currentX = seg[0]; pathLength += Point2D.distance(currentX, currentY, seg[0], seg[1]); segments.add(new PathSegment(segType, seg[0], seg[1], pathLength, origIndex)); currentX = seg[0]; pathLength += Point2D.distance(currentX, currentY, lastMoveX, lastMoveY); segments.add(new PathSegment(PathIterator.SEG_LINETO, lastMoveX, lastMoveY, pathLength, origIndex)); pathLength += Point2D.distance(currentX, currentY, seg[0], seg[1]); segments.add(new PathSegment(segType, seg[0], seg[1], pathLength, origIndex));
int curr = (lb + ub) >> 1; PathSegment ps = (PathSegment) segments.get(curr); if (ps.getLength() >= length) { ub = curr; } else { if (ps.getSegType() != PathIterator.SEG_MOVETO || ub == segments.size() - 1) { break; while (upperIndex <= 0 && currentIndex < numSegments) { PathSegment ps = (PathSegment) segments.get(currentIndex); if (ps.getLength() >= length && ps.getSegType() != PathIterator.SEG_MOVETO) { upperIndex = currentIndex;
int curr = (lb + ub) >> 1; PathSegment ps = (PathSegment) segments.get(curr); if (ps.getLength() >= length) { ub = curr; } else { if (ps.getSegType() != PathIterator.SEG_MOVETO || ub == segments.size() - 1) { break; while (upperIndex <= 0 && currentIndex < numSegments) { PathSegment ps = (PathSegment) segments.get(currentIndex); if (ps.getLength() >= length && ps.getSegType() != PathIterator.SEG_MOVETO) { upperIndex = currentIndex;
/** * Returns the slope of the path at the specified length. * @param index The segment number * @param proportion The proportion along the given segment * @return the angle in radians, in the range [-{@link Math#PI}, * {@link Math#PI}]. */ public float angleAtLength(int index, float proportion) { if (!initialised) { initialise(); } if (index < 0 || index >= segmentIndexes.length) { return 0f; } PathSegment seg = (PathSegment) segments.get(segmentIndexes[index]); float start = seg.getLength(); float end; if (index == segmentIndexes.length - 1) { end = pathLength; } else { seg = (PathSegment) segments.get(segmentIndexes[index + 1]); end = seg.getLength(); } return angleAtLength(start + (end - start) * proportion); }
/** * Returns the point that is at the given length along the path. * @param length The length along the path * @return The point at the given length */ public Point2D pointAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return null; } PathSegment upper = (PathSegment) segments.get(upperIndex); if (upperIndex == 0) { // Length was probably zero, so return the upper point. return new Point2D.Float(upper.getX(), upper.getY()); } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); // Now work out where along the line would be the length. float offset = length - lower.getLength(); // Compute the slope. double theta = Math.atan2(upper.getY() - lower.getY(), upper.getX() - lower.getX()); float xPoint = (float) (lower.getX() + offset * Math.cos(theta)); float yPoint = (float) (lower.getY() + offset * Math.sin(theta)); return new Point2D.Float(xPoint, yPoint); }
/** * Returns the slope of the path at the specified length. * @param length The length along the path * @return the angle in radians, in the range [-{@link Math#PI}, * {@link Math#PI}]. */ public float angleAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return 0f; } PathSegment upper = (PathSegment) segments.get(upperIndex); if (upperIndex == 0) { // Length was probably zero, so return the angle between the first // and second segments. upperIndex = 1; } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); // Compute the slope. return (float) Math.atan2(upper.getY() - lower.getY(), upper.getX() - lower.getX()); }
/** * Returns the point that is the given proportion along the path segment * given by the specified index. */ public Point2D pointAtLength(int index, float proportion) { if (!initialised) { initialise(); } if (index < 0 || index >= segmentIndexes.length) { return null; } PathSegment seg = (PathSegment) segments.get(segmentIndexes[index]); float start = seg.getLength(); float end; if (index == segmentIndexes.length - 1) { end = pathLength; } else { seg = (PathSegment) segments.get(segmentIndexes[index + 1]); end = seg.getLength(); } return pointAtLength(start + (end - start) * proportion); }
/** * Returns the slope of the path at the specified length. * @param index The segment number * @param proportion The proportion along the given segment * @return the angle in radians, in the range [-{@link Math#PI}, * {@link Math#PI}]. */ public float angleAtLength(int index, float proportion) { if (!initialised) { initialise(); } if (index < 0 || index >= segmentIndexes.length) { return 0f; } PathSegment seg = (PathSegment) segments.get(segmentIndexes[index]); float start = seg.getLength(); float end; if (index == segmentIndexes.length - 1) { end = pathLength; } else { seg = (PathSegment) segments.get(segmentIndexes[index + 1]); end = seg.getLength(); } return angleAtLength(start + (end - start) * proportion); }
/** * Returns the point that is the given proportion along the path segment * given by the specified index. */ public Point2D pointAtLength(int index, float proportion) { if (!initialised) { initialise(); } if (index < 0 || index >= segmentIndexes.length) { return null; } PathSegment seg = (PathSegment) segments.get(segmentIndexes[index]); float start = seg.getLength(); float end; if (index == segmentIndexes.length - 1) { end = pathLength; } else { seg = (PathSegment) segments.get(segmentIndexes[index + 1]); end = seg.getLength(); } return pointAtLength(start + (end - start) * proportion); }
/** * Returns the slope of the path at the specified length. * @param length The length along the path * @return the angle in radians, in the range [-{@link Math#PI}, * {@link Math#PI}]. */ public float angleAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return 0f; } PathSegment upper = (PathSegment) segments.get(upperIndex); if (upperIndex == 0) { // Length was probably zero, so return the angle between the first // and second segments. upperIndex = 1; } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); // Compute the slope. return (float) Math.atan2(upper.getY() - lower.getY(), upper.getX() - lower.getX()); }
/** * Returns the point that is at the given length along the path. * @param length The length along the path * @return The point at the given length */ public Point2D pointAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return null; } PathSegment upper = (PathSegment) segments.get(upperIndex); if (upperIndex == 0) { // Length was probably zero, so return the upper point. return new Point2D.Float(upper.getX(), upper.getY()); } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); // Now work out where along the line would be the length. float offset = length - lower.getLength(); // Compute the slope. double theta = Math.atan2(upper.getY() - lower.getY(), upper.getX() - lower.getX()); float xPoint = (float) (lower.getX() + offset * Math.cos(theta)); float yPoint = (float) (lower.getY() + offset * Math.sin(theta)); return new Point2D.Float(xPoint, yPoint); }
/** * Returns the point that is the given proportion along the path segment * given by the specified index. */ public Point2D pointAtLength(int index, float proportion) { if (!initialised) { initialise(); } if (index < 0 || index >= segmentIndexes.length) { return null; } PathSegment seg = (PathSegment) segments.get(segmentIndexes[index]); float start = seg.getLength(); float end; if (index == segmentIndexes.length - 1) { end = pathLength; } else { seg = (PathSegment) segments.get(segmentIndexes[index + 1]); end = seg.getLength(); } return pointAtLength(start + (end - start) * proportion); }
/** * Returns the point that is at the given length along the path. * @param length The length along the path * @return The point at the given length */ public Point2D pointAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return null; } PathSegment upper = (PathSegment) segments.get(upperIndex); if (upperIndex == 0) { // Length was probably zero, so return the upper point. return new Point2D.Float(upper.getX(), upper.getY()); } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); // Now work out where along the line would be the length. float offset = length - lower.getLength(); // Compute the slope. double theta = Math.atan2(upper.getY() - lower.getY(), upper.getX() - lower.getX()); float xPoint = (float) (lower.getX() + offset * Math.cos(theta)); float yPoint = (float) (lower.getY() + offset * Math.sin(theta)); return new Point2D.Float(xPoint, yPoint); }
/** * Returns the slope of the path at the specified length. * @param index The segment number * @param proportion The proportion along the given segment * @return the angle in radians, in the range [-{@link Math#PI}, * {@link Math#PI}]. */ public float angleAtLength(int index, float proportion) { if (!initialised) { initialise(); } if (index < 0 || index >= segmentIndexes.length) { return 0f; } PathSegment seg = (PathSegment) segments.get(segmentIndexes[index]); float start = seg.getLength(); float end; if (index == segmentIndexes.length - 1) { end = pathLength; } else { seg = (PathSegment) segments.get(segmentIndexes[index + 1]); end = seg.getLength(); } return angleAtLength(start + (end - start) * proportion); }
/** * Returns the slope of the path at the specified length. * @param length The length along the path * @return the angle in radians, in the range [-{@link Math#PI}, * {@link Math#PI}]. */ public float angleAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return 0f; } PathSegment upper = (PathSegment) segments.get(upperIndex); if (upperIndex == 0) { // Length was probably zero, so return the angle between the first // and second segments. upperIndex = 1; } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); // Compute the slope. return (float) Math.atan2(upper.getY() - lower.getY(), upper.getX() - lower.getX()); }
/** * Returns the length at the start of the segment given by the specified * index. */ public float getLengthAtSegment(int index) { if (!initialised) { initialise(); } if (index <= 0) { return 0; } if (index >= segmentIndexes.length) { return pathLength; } PathSegment seg = (PathSegment) segments.get(segmentIndexes[index]); return seg.getLength(); }