/** * Adds a control point. */ public void addNode(BezierPath.Node p) { addNode(getNodeCount(), p); }
/** * Splits the segment at the given Point2D.Double if a segment was hit. * @return the index of the segment or -1 if no segment was hit. * * @param split a Point on (or near) a line segment on the bezier path * @param tolerance a tolerance, tolerance should take into account * the line width, plus 2 divided by the zoom factor. */ public int splitSegment(Point2D.Double split, double tolerance) { int i = findSegment(split, tolerance); if (i != -1) { addNode(i + 1, new BezierPath.Node(split)); } return i + 1; }
/** * Convenience method for setting the point coordinate of the start point. * If the BezierFigure has not at least two nodes, nodes are added * to the figure until the BezierFigure has at least two nodes. */ public void setStartPoint(Point2D.Double p) { // Add two nodes if we haven't at least two nodes for (int i = getNodeCount(); i < 2; i++) { addNode(0, new BezierPath.Node(p.x, p.y)); } setPoint(0, p); }
@Override public void redo() throws CannotRedoException { super.redo(); willChange(); addNode(index, newNode); changed(); }
/** * Convenience method for setting the point coordinate of the end point. * If the BezierFigure has not at least two nodes, nodes are added * to the figure until the BezierFigure has at least two nodes. */ public void setEndPoint(Point2D.Double p) { // Add two nodes if we haven't at least two nodes for (int i = getNodeCount(); i < 2; i++) { addNode(0, new BezierPath.Node(p.x, p.y)); } setPoint(getNodeCount() - 1, p); }
@Override public void undo() throws CannotUndoException { super.undo(); view.removeFromSelection(f); f.willChange(); f.addNode(index, removedNode); f.changed(); view.addToSelection(f); } });
@Override public void undo() throws CannotUndoException { super.undo(); view.removeFromSelection(f); f.willChange(); f.addNode(index, removedNode); f.changed(); view.addToSelection(f); } });
@Override public void updateFigure(final OverlayView view, final BezierFigure figure) { super.updateFigure(view, figure); assert view.getData() instanceof GeneralPathOverlay; final GeneralPathOverlay gpo = (GeneralPathOverlay) view.getData(); final GeneralPathRegionOfInterest gpr = gpo.getRegionOfInterest(); final PathIterator pi = gpr.getGeneralPath().getPathIterator(null); final int nCount = figure.getNodeCount(); int i = 0; final double[] pos = new double[6]; while (!pi.isDone()) { pi.currentSegment(pos); final Node n = new Node(pos[0], pos[1]); if (i < nCount) figure.getNode(i).setTo(n); else figure.addNode(n); pi.next(); i++; } while (i < figure.getNodeCount()) figure.removeNode(i); }
protected void addPointToFigure(Point2D.Double newPoint) { int pointCount = createdFigure.getNodeCount(); createdFigure.willChange(); if (pointCount < 2) { createdFigure.addNode(new BezierPath.Node(newPoint)); } else { Point2D.Double endPoint = createdFigure.getEndPoint(); Point2D.Double secondLastPoint = (pointCount <= 1) ? endPoint : createdFigure.getPoint(pointCount - 2, 0); if (newPoint.equals(endPoint)) { // nothing to do } else if (pointCount > 1 && Geom.lineContainsPoint(newPoint.x, newPoint.y, secondLastPoint.x, secondLastPoint.y, endPoint.x, endPoint.y, 0.9f / getView().getScaleFactor())) { createdFigure.setPoint(pointCount - 1, 0, newPoint); } else { createdFigure.addNode(new BezierPath.Node(newPoint)); } } createdFigure.changed(); }
@Override public void updateFigure(final OverlayView view, final BezierFigure figure) { super.updateFigure(view, figure); final PolygonOverlay polygonOverlay = downcastOverlay(view.getData()); final PolygonRegionOfInterest roi = polygonOverlay.getRegionOfInterest(); final int vertexCount = roi.getVertexCount(); while (figure.getNodeCount() > vertexCount) { figure.removeNode(vertexCount); } for (int i = 0; i < vertexCount; i++) { final RealLocalizable vertex = roi.getVertex(i); final double x = vertex.getDoublePosition(0); final double y = vertex.getDoublePosition(1); if (figure.getNodeCount() == i) { figure.addNode(new Node(x, y)); } else { final Node node = figure.getNode(i); node.mask = 0; Arrays.fill(node.x, x); Arrays.fill(node.y, y); } } }
createdFigure.addNode(new BezierPath.Node( creationView.getConstrainer().constrainPoint( creationView.viewToDrawing(anchor))));