@Override public void mouseDragged(MouseEvent e) { double zoomFactor = getZoomFactor(); example.digitized.lineTo(e.getX() / zoomFactor, e.getY() / zoomFactor); example.invalidate(); canvas.repaint(); }
public static void main(final String[] args) { BezierPath path1 = new BezierPath(); path1.moveTo(0, 0); path1.lineTo(100, 0); path1.lineTo(100, 100); path1.lineTo(0, 0); final GeneralPath path2 = new GeneralPath(); path2.moveTo(0, 0); path2.lineTo(100, 0); path2.lineTo(100, 100); path2.closePath(); // path1 = toBezierPath(path2.getPathIterator(new AffineTransform())); final BezierPath path3 = new BezierPath(); path3.moveTo(0, 100); path3.lineTo(100, 0); path3.lineTo(100, 100); path3.lineTo(0, 100); path1 = subtract(path1, path3); show(path1.toGeneralPath()); }
default : triangle.moveTo((float) (r.x + r.width / 2), (float) r.y); triangle.lineTo((float) (r.x + r.width), (float) (r.y + r.height)); triangle.lineTo((float) r.x, (float) (r.y + r.height)); break; case NORTH_EAST : triangle.moveTo((float) (r.x), (float) r.y); triangle.lineTo((float) (r.x + r.width), (float) (r.y)); triangle.lineTo((float) (r.x + r.width), (float) (r.y + r.height)); break; case EAST : triangle.moveTo((float) (r.x), (float) (r.y)); triangle.lineTo((float) (r.x + r.width), (float) (r.y + r.height / 2d)); triangle.lineTo((float) r.x, (float) (r.y + r.height)); break; case SOUTH_EAST : triangle.moveTo((float) (r.x + r.width), (float) (r.y)); triangle.lineTo((float) (r.x + r.width), (float) (r.y + r.height)); triangle.lineTo((float) (r.x), (float) (r.y + r.height)); break; case SOUTH : triangle.moveTo((float) (r.x + r.width / 2), (float) (r.y + r.height)); triangle.lineTo((float) r.x, (float) r.y); triangle.lineTo((float) (r.x + r.width), (float) r.y); break; case SOUTH_WEST : triangle.moveTo((float) (r.x + r.width), (float) (r.y + r.height)); triangle.lineTo((float) (r.x), (float) (r.y + r.height)); triangle.lineTo((float) (r.x), (float) (r.y));
public static BezierPath toBezierPath(final PathIterator iterator) { final BezierPath path = new BezierPath(); final double[] segment = new double[6]; for (; !iterator.isDone(); iterator.next()) { final int type = iterator.currentSegment(segment); switch (type) { case PathIterator.SEG_MOVETO: path.moveTo(segment[0], segment[1]); break; case PathIterator.SEG_LINETO: path.lineTo(segment[0], segment[1]); break; case PathIterator.SEG_QUADTO: path.quadTo(segment[0], segment[1], segment[2], segment[3]); break; case PathIterator.SEG_CUBICTO: path.curveTo(segment[0], segment[1], segment[2], segment[3], segment[4], segment[5]); break; case PathIterator.SEG_CLOSE: path.setClosed(true); break; } } return path; }
/** * Adds the curve to the bezier path. * * @param bezCurve * @param bezierPath */ private static void addCurveTo(Point2D.Double[] bezCurve, BezierPath bezierPath, double errorSquared, boolean connectsCorners) { BezierPath.Node lastNode = bezierPath.get(bezierPath.size() - 1); double error = Math.sqrt(errorSquared); if (connectsCorners && Geom.lineContainsPoint(lastNode.x[0], lastNode.y[0], bezCurve[3].x, bezCurve[3].y, bezCurve[1].x, bezCurve[1].y, error) && Geom.lineContainsPoint(lastNode.x[0], lastNode.y[0], bezCurve[3].x, bezCurve[3].y, bezCurve[2].x, bezCurve[2].y, error)) { bezierPath.lineTo( bezCurve[3].x, bezCurve[3].y); } else { bezierPath.curveTo( bezCurve[1].x, bezCurve[1].y, bezCurve[2].x, bezCurve[2].y, bezCurve[3].x, bezCurve[3].y); } }
break; case PathIterator.SEG_LINETO: bezierPath.lineTo(segment[0], segment[1]); break; case PathIterator.SEG_QUADTO:
break; case PathIterator.SEG_LINETO: bezierPath.lineTo(segment[0], segment[1]); break; case PathIterator.SEG_QUADTO:
fittedPath.add(new BezierPath.Node(seg.get(0))); fittedPath.lineTo(seg.get(1).x, seg.get(1).y); break; default:
if (coords[0] != bp.get(bp.size() - 1).x[0] || coords[1] != bp.get(bp.size() - 1).y[0]) { bp.lineTo(coords[0], coords[1]);
if (coords[0] != bp.get(bp.size() - 1).x[0] || coords[1] != bp.get(bp.size() - 1).y[0]) { bp.lineTo(coords[0], coords[1]);