/** * Adds the subpath to this path. * * @param subpath The subpath to be added to this path. */ public void addSubpath(Subpath subpath) { subpaths.add(subpath); currentPoint = subpath.getLastPoint(); }
/** * Adds the subpaths to this path. * * @param subpaths {@link java.util.List} of subpaths to be added to this path. */ public void addSubpaths(List<? extends Subpath> subpaths) { if (subpaths.size() > 0) { for (Subpath subpath : subpaths) { this.subpaths.add(new Subpath(subpath)); } currentPoint = this.subpaths.get(subpaths.size() - 1).getLastPoint(); } }
/** * 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; }