/** Creates a new instance. */ public LineFigure() { addNode(new BezierPath.Node(new Point2D.Double(0,0))); addNode(new BezierPath.Node(new Point2D.Double(0,0))); setConnectable(false); }
@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(); }
/** * Creates a Polygon figure. */ private ODGFigure createPolygonFigure( Point2D.Double[] points, Map<AttributeKey, Object> a) throws IOException { ODGPathFigure figure = new ODGPathFigure(); ODGBezierFigure bezier = new ODGBezierFigure(); for (Point2D.Double p : points) { bezier.addNode(new BezierPath.Node(p.x, p.y)); } bezier.setClosed(true); figure.removeAllChildren(); figure.add(bezier); figure.setAttributes(a); return figure; }
/** * Adds a (at least) quadratic curve to the bezier path. * <p> * If the previous node has no C2 control point the line will be quadratic * otherwise the line will be cubic. * <p> * This is a convenience method for adding a node with control point C0 and * C1 (incoming curve) to the bezier path. * <p> * The bezier path must already have at least one node. */ public void quadTo(double x1, double y1, double x2, double y2) { if (size() == 0) { throw new IllegalPathStateException("quadTo only allowed when not empty"); } add(new Node(C1_MASK, x2, y2, x1, y1, x2, y2)); }
/** * Creates a Polyline figure. */ private ODGFigure createPolylineFigure( Point2D.Double[] points, Map<AttributeKey, Object> a) throws IOException { ODGPathFigure figure = new ODGPathFigure(); ODGBezierFigure bezier = new ODGBezierFigure(); for (Point2D.Double p : points) { bezier.addNode(new BezierPath.Node(p.x, p.y)); } figure.removeAllChildren(); figure.add(bezier); figure.setAttributes(a); return figure; }
/** * Adds a (at least) linear 'curve' to the bezier path. * <p> * If the previous node has no C2 control point the line will be straight * (linear), otherwise the line will be quadratic. * <p> * This is a convenience method for adding a node with a single control * point C0. * <p> * The bezier path must already have at least one node. */ public void lineTo(double x1, double y1) { if (size() == 0) { throw new IllegalPathStateException("lineTo only allowed when not empty"); } get(size() - 1).keepColinear = false; add(new Node(x1, y1)); }
/** * Adds a node to the path. * <p> * This is a convenience method for adding a node with three control points * C0, C1 and C2, and a mask. * * @param ctrlMask An or-combination of C0_MASK,C1_MASK and C2_MASK. * @param c0 The coordinates of the C0 control point. * @param c1 The coordinates of the C1 control point. * @param c2 The coordinates of the C2 control point. */ public void add(int ctrlMask, Point2D.Double c0, Point2D.Double c1, Point2D.Double c2) { add(new Node(ctrlMask, c0, c1, c2)); }
/** * 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; }
@Override public Figure createPolygon(Point2D.Double[] points, Map<AttributeKey, Object> a) { SVGPathFigure figure = new SVGPathFigure(); figure.removeAllChildren(); SVGBezierFigure bf = new SVGBezierFigure(); for (int i=0; i < points.length; i++) { bf.addNode(new BezierPath.Node(points[i].x, points[i].y)); } bf.setClosed(true); figure.add(bf); figure.setAttributes(a); return figure; } @Override
@Override public Figure createLine( double x1, double y1, double x2, double y2, Map<AttributeKey,Object> a) { SVGPathFigure figure = new SVGPathFigure(); figure.removeAllChildren(); SVGBezierFigure bf = new SVGBezierFigure(); bf.addNode(new BezierPath.Node(x1, y1)); bf.addNode(new BezierPath.Node(x2, y2)); figure.add(bf); figure.setAttributes(a); return figure; }
/** * Adds the first node to the bezier path. * <p> * This is a convenience method for adding the first node with a single * control point C0 to the bezier path. */ public void moveTo(double x1, double y1) { if (size() != 0) { throw new IllegalPathStateException("moveTo only allowed when empty"); } Node node = new Node(x1, y1); node.keepColinear = false; add(node); }
@Override public Figure createPolyline(Point2D.Double[] points, Map<AttributeKey, Object> a) { SVGPathFigure figure = new SVGPathFigure(); figure.removeAllChildren(); SVGBezierFigure bf = new SVGBezierFigure(); for (int i=0; i < points.length; i++) { bf.addNode(new BezierPath.Node(points[i].x, points[i].y)); } figure.add(bf); figure.setAttributes(a); return figure; }
/** * 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); }
/** * Adds a set of nodes to the path. * <p> * Convenience method for adding multiple nodes with a single control point * C0. */ public void addPolyline(Collection<Point2D.Double> points) { for (Point2D.Double c0 : points) { add(new Node(0, c0, c0, c0)); } }
/** * Adds a node to the path. * <p> * This is a convenience method for adding a node with a single control * point C0 to the path. */ public void add(double x, double y) { add(new Node(0, x, y, x, y, x, y)); }
/** * Sets the point coordinate of a control point. */ public void setPoint(int index, int coord, Point2D.Double p) { BezierPath.Node cp = new BezierPath.Node(path.get(index)); cp.setControlPoint(coord, p); setNode(index, cp); }
public AngleFigure() { // coords have no effect on initial placement in window addNode(new BezierPath.Node(6, 1)); addNode(new BezierPath.Node(1, 1)); addNode(new BezierPath.Node(1, 6)); setConnectable(false); }
/** * 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); }
/** * Adds a node to the path. * <p> * This is a convenience method for adding a node with a single control * point C0 to the path. */ public void add(Point2D.Double c0) { add(new Node(0, c0, c0, c0)); }