/** * Gets the segment of the polyline that is hit by * the given Point2D.Double. * * @param find a Point on the bezier path * @param tolerance a tolerance, tolerance should take into account * the line width, plus 2 divided by the zoom factor. * @return the index of the segment or -1 if no segment was hit. */ public int findSegment(Point2D.Double find, double tolerance) { return getBezierPath().findSegment(find, tolerance); }
/** * Gets the segment of the polyline that is hit by * the given Point2D.Double. * @return the index of the segment or -1 if no segment was hit. */ @Override public int findSegment(Point2D.Double find, double tolerance) { // Apply inverse of transform to point if (get(TRANSFORM) != null) { try { find = (Point2D.Double) get(TRANSFORM).inverseTransform(find, new Point2D.Double()); } catch (NoninvertibleTransformException ex) { System.err.println("Warning: SVGBezierFigure.findSegment. Figure has noninvertible Transform."); } } return getBezierPath().findSegment(find, tolerance); }
/** * Handles a mouse click. */ @Override public boolean handleMouseClick(Point2D.Double p, MouseEvent evt, DrawingView view) { if (evt.getClickCount() == 2 && view.getHandleDetailLevel() % 2 == 0) { for (Figure child : getChildren()) { ODGBezierFigure bf = (ODGBezierFigure) child; int index = bf.getBezierPath().findSegment(p, 5f / view.getScaleFactor()); if (index != -1) { bf.handleMouseClick(p, evt, view); evt.consume(); return true; } } } return false; }
/** * Joins two segments into one if the given Point2D.Double hits a node * of the polyline. * @return true if the two segments were joined. * * @param join a Point at a node on the bezier path * @param tolerance a tolerance, tolerance should take into account * the line width, plus 2 divided by the zoom factor. */ @Override public boolean joinSegments(Point2D.Double join, double tolerance) { // Apply inverse of transform to point if (get(TRANSFORM) != null) { try { join = (Point2D.Double) get(TRANSFORM).inverseTransform(join, new Point2D.Double()); } catch (NoninvertibleTransformException ex) { System.err.println("Warning: SVGBezierFigure.findSegment. Figure has noninvertible Transform."); } } int i = getBezierPath().findSegment(join, tolerance); if (i != -1 && i > 1) { removeNode(i); return true; } return false; }
/** * 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 segment of the bezier path * @param tolerance a tolerance, tolerance should take into account * the line width, plus 2 divided by the zoom factor. */ @Override public int splitSegment(Point2D.Double split, double tolerance) { // Apply inverse of transform to point if (get(TRANSFORM) != null) { try { split = (Point2D.Double) get(TRANSFORM).inverseTransform(split, new Point2D.Double()); } catch (NoninvertibleTransformException ex) { System.err.println("Warning: SVGBezierFigure.findSegment. Figure has noninvertible Transform."); } } int i = getBezierPath().findSegment(split, tolerance); if (i != -1) { addNode(i + 1, new BezierPath.Node(split)); } return i + 1; }
/** * 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. */ public int splitSegment(Point2D.Double split, double tolerance) { int i = findSegment(split, tolerance); int nextI = (i + 1) % size(); if (i != -1) { if ((get(i).mask & C2_MASK) == C2_MASK && (get(nextI).mask & C1_MASK) == 0) { // quadto add(i + 1, new Node(C2_MASK, split, split, split)); } else if ((get(i).mask & C2_MASK) == 0 && (get(nextI).mask & C1_MASK) == C1_MASK) { // quadto add(i + 1, new Node(C1_MASK, split, split, split)); } else if ((get(i).mask & C2_MASK) == C2_MASK && (get(nextI).mask & C1_MASK) == C1_MASK) { // cubicto add(i + 1, new Node(C1_MASK | C2_MASK, split, split, split)); } else { // lineto add(i + 1, new Node(split)); } } return i + 1; }