private IShape transformSegment(IShape segment, Matrix newCtm) { IShape newSegment; List<Point> segBasePts = segment.getBasePoints(); Point[] transformedPoints = transformPoints(newCtm, segBasePts.toArray(new Point[segBasePts.size()])); if (segment instanceof BezierCurve) { newSegment = new BezierCurve(Arrays.asList(transformedPoints)); } else { newSegment = new Line(transformedPoints[0], transformedPoints[1]); } return newSegment; }
/** * Appends a straight line segment from the current point to the point <CODE>(x, y)</CODE>. * @param x x-coordinate of the new point * @param y y-coordinate of the new point */ public void lineTo(float x, float y) { if (currentPoint == null) { throw new RuntimeException(START_PATH_ERR_MSG); } Point targetPoint = new Point(x, y); getLastSubpath().addSegment(new Line(currentPoint, targetPoint)); currentPoint = targetPoint; }
/** * Adds additional line to each closed subpath and makes the subpath unclosed. * The line connects the last and the first points of the subpaths. * * @return Indices of modified subpaths. */ public List<Integer> replaceCloseWithLine() { List<Integer> modifiedSubpathsIndices = new ArrayList<>(); int i = 0; /* It could be replaced with "for" cycle, because IList in C# provides effective * access by index. In Java List interface has at least one implementation (LinkedList) * which is "bad" for access elements by index. */ for (Subpath subpath : subpaths) { if (subpath.isClosed()) { subpath.setClosed(false); subpath.addSegment(new Line(subpath.getLastPoint(), subpath.getStartPoint())); modifiedSubpathsIndices.add(i); } ++i; } return modifiedSubpathsIndices; }