public DotPath addCurve(Point2D pt1, Point2D pt2, Point2D pt3, Point2D pt4) { final List<CubicCurve2D.Double> beziersNew = new ArrayList<CubicCurve2D.Double>(beziers); beziersNew.add(new CubicCurve2D.Double(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY(), pt3.getX(), pt3.getY(), pt4.getX(), pt4.getY())); return new DotPath(beziersNew); }
private CubicCurve2D.Double getLine(final Point2D p1, Point2D p2) { return new CubicCurve2D.Double(p1.getX(), p1.getY(), p1.getX(), p1.getY(), p2.getX(), p2.getY(), p2.getX(), p2.getY()); }
public void moveSvek(double deltaX, double deltaY) { for (int i = 0; i < beziers.size(); i++) { final CubicCurve2D.Double c = beziers.get(i); beziers.set(i, new CubicCurve2D.Double(c.x1 + deltaX, c.y1 + deltaY, c.ctrlx1 + deltaX, c.ctrly1 + deltaY, c.ctrlx2 + deltaX, c.ctrly2 + deltaY, c.x2 + deltaX, c.y2 + deltaY)); } }
public PointDirected getIntersection(CubicCurve2D.Double bez) { if (contains(bez.x1, bez.y1) == contains(bez.x2, bez.y2)) { return null; } final double dist = bez.getP1().distance(bez.getP2()); if (dist < 2) { final double angle = BezierUtils.getStartingAngle(bez); return new PointDirected(bez.getP1(), angle); } final CubicCurve2D.Double left = new CubicCurve2D.Double(); final CubicCurve2D.Double right = new CubicCurve2D.Double(); bez.subdivide(left, right); final PointDirected int1 = getIntersection(left); if (int1 != null) { return int1; } final PointDirected int2 = getIntersection(right); if (int2 != null) { return int2; } throw new IllegalStateException(); }
public DotPath getRacordIn(Rectangle2D rect, Line2D tangeante) { // Log.println("rect x=" + rect.getX() + " y=" + rect.getY() + " w=" + rect.getWidth() + " h=" // + rect.getHeight()); // Log.println("tangeante (" + tangeante.getX1() + "," + tangeante.getY1() + ") (" + tangeante.getX2() // + "," + tangeante.getY2() + ")"); final DotPath result = new DotPath(); // final Point2D inter = BezierUtils.intersect((Line2D.Double) // tangeante, rect); Point2D inter = new LineRectIntersection(tangeante, rect).getIntersection(); // Log.println("inter=" + inter); if (inter == null) { final Point2D p1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); final Point2D p2 = new Point2D.Double(rect.getMaxX(), rect.getMinY()); final Point2D p3 = new Point2D.Double(rect.getMaxX(), rect.getMaxY()); final Point2D p4 = new Point2D.Double(rect.getMinX(), rect.getMaxY()); inter = LineRectIntersection.getCloser(tangeante.getP1(), p1, p2, p3, p4); } final CubicCurve2D.Double curv = new CubicCurve2D.Double(tangeante.getX1(), tangeante.getY1(), tangeante.getX1(), tangeante.getY1(), inter.getX(), inter.getY(), inter.getX(), inter.getY()); return result.addAfter(curv); }
private DotPath manageRect(Rectangle2D start, Rectangle2D end) { final List<CubicCurve2D.Double> list = new ArrayList<CubicCurve2D.Double>(this.beziers); while (true) { if (BezierUtils.isCutting(list.get(0), start) == false) { throw new IllegalStateException(); } if (BezierUtils.dist(list.get(0)) <= 1.0) { break; } final CubicCurve2D.Double left = new CubicCurve2D.Double(); final CubicCurve2D.Double right = new CubicCurve2D.Double(); list.get(0).subdivide(left, right); list.set(0, left); list.add(1, right); if (BezierUtils.isCutting(list.get(1), start)) { list.remove(0); } } return new DotPath(list); }
public void draw(EpsGraphics eps, double x, double y) { eps.newpathDot(); final boolean dashed = false; boolean first = true; for (CubicCurve2D.Double bez : beziers) { bez = new CubicCurve2D.Double(x + bez.x1, y + bez.y1, x + bez.ctrlx1, y + bez.ctrly1, x + bez.ctrlx2, y + bez.ctrly2, x + bez.x2, y + bez.y2); if (first) { eps.movetoNoMacro(bez.x1, bez.y1); first = dashed; } eps.curvetoNoMacro(bez.ctrlx1, bez.ctrly1, bez.ctrlx2, bez.ctrly2, bez.x2, bez.y2); } eps.closepathDot(); }
private void addCurve(CubicCurve2D.Double peace) { final Rectangle2D bounds = peace.getBounds2D(); final double flat = peace.getFlatness(); if (flat < 10) { lines.add(new Line2D.Double(peace.getP1(), peace.getP2())); lenght += Math.sqrt(bounds.getWidth() * bounds.getWidth() + bounds.getHeight() * bounds.getHeight()); return; } final CubicCurve2D.Double left = new CubicCurve2D.Double(); final CubicCurve2D.Double right = new CubicCurve2D.Double(); peace.subdivide(left, right); addCurve(left); addCurve(right); }
private DotPath addVertical(double x, double y, DotPath path) { double lastx = 0; double lasty = 0; for (Point2D p : points) { final double x1 = lastx + x; final double y1 = lasty + y; final double x2 = p.getY() + x; final double y2 = p.getX() + y; path = path.addAfter(new CubicCurve2D.Double(x1, y1, x1, y1, x2, y2, x2, y2)); lastx = p.getY(); lasty = p.getX(); } return path; }
private DotPath addHorizontal(double x, double y, DotPath path) { double lastx = 0; double lasty = 0; for (Point2D p : points) { final double x1 = lastx + x; final double y1 = lasty + y; final double x2 = p.getX() + x; final double y2 = p.getY() + y; path = path.addAfter(new CubicCurve2D.Double(x1, y1, x1, y1, x2, y2, x2, y2)); lastx = p.getX(); lasty = p.getY(); } return path; }
public Map<Point2D, Double> somePoints() { final Map<Point2D, Double> result = new HashMap<Point2D, Double>(); for (CubicCurve2D.Double bez : beziers) { final CubicCurve2D.Double left = new CubicCurve2D.Double(); final CubicCurve2D.Double right = new CubicCurve2D.Double(); bez.subdivide(left, right); result.put(left.getP1(), BezierUtils.getStartingAngle(left)); result.put(left.getP2(), BezierUtils.getEndingAngle(left)); result.put(right.getP1(), BezierUtils.getStartingAngle(right)); result.put(right.getP2(), BezierUtils.getEndingAngle(right)); } return result; }
public static CubicCurve2D.Double reverse(CubicCurve2D curv) { return new CubicCurve2D.Double(curv.getX2(), curv.getY2(), curv.getCtrlX2(), curv.getCtrlY2(), curv.getCtrlX1(), curv.getCtrlY1(), curv.getX1(), curv.getY1()); }
public void curveTo(CubicCurve2D curve) { final double flatness = curve.getFlatness(); final double dist = curve.getP1().distance(curve.getP2()); if (flatness > 0.1 && dist > 20) { final CubicCurve2D left = new CubicCurve2D.Double(); final CubicCurve2D right = new CubicCurve2D.Double(); curve.subdivide(left, right); curveTo(left); curveTo(right); return; } lineTo(curve.getP2()); }
public void draw(Graphics2D g2d, double x, double y) { final GeneralPath p = new GeneralPath(); for (CubicCurve2D.Double bez : beziers) { bez = new CubicCurve2D.Double(x + bez.x1, y + bez.y1, x + bez.ctrlx1, y + bez.ctrly1, x + bez.ctrlx2, y + bez.ctrly2, x + bez.x2, y + bez.y2); p.append(bez, true); } g2d.draw(p); }
public DotPath(DotPath other) { this(new ArrayList<CubicCurve2D.Double>()); for (CubicCurve2D.Double c : other.beziers) { this.beziers.add(new CubicCurve2D.Double(c.x1, c.y1, c.ctrlx1, c.ctrly1, c.ctrlx2, c.ctrly2, c.x2, c.y2)); } }
private void drawCubic(double x, double y, CubicCurve2D.Double bez) { drawPointInternal(x, y, bez.getP1()); drawPointInternal(x, y, bez.getP2()); if (bez.getP1().distance(bez.getP2()) > quanta) { final CubicCurve2D.Double part1 = new CubicCurve2D.Double(); final CubicCurve2D.Double part2 = new CubicCurve2D.Double(); bez.subdivide(part1, part2); drawCubic(x, y, part1); drawCubic(x, y, part2); } }
public DotPath getRacordIn(Rectangle2D rect, Line2D tangeante) { final DotPath result = new DotPath(); final Point2D center = new Point2D.Double(rect.getCenterX(), rect.getCenterY()); final Line2D.Double line = new Line2D.Double(tangeante.getP1(), center); final Point2D inter = BezierUtils.intersect(line, rect); final CubicCurve2D.Double curv = new CubicCurve2D.Double(tangeante.getX1(), tangeante.getY1(), tangeante .getX2(), tangeante.getY2(), tangeante.getX2(), tangeante.getY2(), inter.getX(), inter.getY()); return result.addAfter(curv); }
private void cutAllCubic(List<CubicCurve2D.Double> all) { final List<CubicCurve2D.Double> tmp = new ArrayList<CubicCurve2D.Double>(all); all.clear(); for (CubicCurve2D.Double bez : tmp) { final CubicCurve2D.Double left = new CubicCurve2D.Double(); final CubicCurve2D.Double right = new CubicCurve2D.Double(); bez.subdivide(left, right); all.add(left); all.add(right); } }
public void drawOk(EpsGraphics eps, double x, double y) { // boolean first = true; for (CubicCurve2D.Double bez : beziers) { bez = new CubicCurve2D.Double(x + bez.x1, y + bez.y1, x + bez.ctrlx1, y + bez.ctrly1, x + bez.ctrlx2, y + bez.ctrly2, x + bez.x2, y + bez.y2); eps.epsLine(bez.x1, bez.y1, bez.x2, bez.y2); } }
public DotPath getRacordIn(Rectangle2D rect, Line2D tangeante) { final DotPath result = new DotPath(); final Point2D center = new Point2D.Double(rect.getCenterX(), rect.getCenterY()); final Line2D.Double line = new Line2D.Double(tangeante.getP1(), center); final Point2D inter = BezierUtils.intersect(line, rect); final CubicCurve2D.Double curv = new CubicCurve2D.Double(line.getX1(), line.getY1(), line.getX1(), line.getY1(), inter.getX(), inter.getY(), inter.getX(), inter.getY()); return result.addAfter(curv); }