Refine search
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(); }
final DotPath result = new DotPath(); int idx = 0; while (idx + 1 < this.beziers.size() && clusterPosition.contains(this.beziers.get(idx).getP2())) { if (clusterPosition.contains(this.beziers.get(idx).getP1()) == false) { throw new IllegalStateException(); if (clusterPosition.contains(this.beziers.get(idx).getP2())) { assert clusterPosition.contains(this.beziers.get(idx).getP1()); assert clusterPosition.contains(this.beziers.get(idx).getP2()) == false; CubicCurve2D current = this.beziers.get(idx); for (int k = 0; k < 8; k++) { final CubicCurve2D.Double part1 = new CubicCurve2D.Double(); final CubicCurve2D.Double part2 = new CubicCurve2D.Double(); current.subdivide(part1, part2); assert part1.getP2().equals(part2.getP1()); if (clusterPosition.contains(part1.getP2())) { current = part2; } else { if (clusterPosition.contains(getEndPoint())) { for (CubicCurve2D.Double current : me.beziers) { if (clusterPosition.contains(current.getP2()) == false) { result.beziers.add(current); } else { if (clusterPosition.contains(current.getP1())) { assert clusterPosition.contains(current.getP1()) == false;
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(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)); } }
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 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 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()); }
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); }
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 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); }
static void shorten(CubicCurve2D.Double bez, Shape shape) { final boolean contains1 = shape.contains(bez.x1, bez.y1); final boolean contains2 = shape.contains(bez.x2, bez.y2); if (contains1 ^ contains2 == false) { throw new IllegalArgumentException(); } if (contains1 == false) { bez.setCurve(bez.x2, bez.y2, bez.ctrlx2, bez.ctrly2, bez.ctrlx1, bez.ctrly1, bez.x1, bez.y1); } assert shape.contains(bez.x1, bez.y1) && shape.contains(bez.x2, bez.y2) == false; final CubicCurve2D.Double left = new CubicCurve2D.Double(); final CubicCurve2D.Double right = new CubicCurve2D.Double(); subdivide(bez, left, right, 0.5); if (isCutting(left, shape) ^ isCutting(right, shape) == false) { throw new IllegalArgumentException(); } if (isCutting(left, shape)) { bez.setCurve(left); } else { bez.setCurve(right); } }
private Point2D getFrontierIntersection(Shape shape, Rectangle2D... notIn) { final List<CubicCurve2D.Double> all = new ArrayList<CubicCurve2D.Double>(beziers); for (int i = 0; i < 8; i++) { for (CubicCurve2D.Double immutable : all) { if (contains(immutable, notIn)) { continue; } final CubicCurve2D.Double bez = new CubicCurve2D.Double(); bez.setCurve(immutable); if (BezierUtils.isCutting(bez, shape)) { while (BezierUtils.dist(bez) > 1.0) { BezierUtils.shorten(bez, shape); } final Point2D.Double result = new Point2D.Double((bez.x1 + bez.x2) / 2, (bez.y1 + bez.y2) / 2); if (contains(result, notIn) == false) { return result; } } } cutAllCubic(all); } throw new IllegalArgumentException("shape=" + shape); }
public void drawRoute(Graphics2D g, double lon1, double lat1, double lon2, double lat2, boolean straight, boolean dashed) { int x1 = translateLongitudeToX(lon1); int y1 = translateLatitudeToY(lat1); int x2 = translateLongitudeToX(lon2); int y2 = translateLatitudeToY(lat2); if (dashed) { g.setStroke(TangoColorFactory.FAT_DASHED_STROKE); } if (straight) { g.drawLine(x1, y1, x2, y2); } else { double xDistPart = (x2 - x1) / 3.0; double yDistPart = (y2 - y1) / 3.0; double ctrlx1 = x1 + xDistPart + yDistPart; double ctrly1 = y1 - xDistPart + yDistPart; double ctrlx2 = x2 - xDistPart - yDistPart; double ctrly2 = y2 + xDistPart - yDistPart; g.draw(new CubicCurve2D.Double(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2)); } if (dashed) { g.setStroke(TangoColorFactory.NORMAL_STROKE); } }
public PointAndAngle getMiddle() { Point2D result = null; double angle = 0; for (CubicCurve2D.Double bez : beziers) { final CubicCurve2D.Double left = new CubicCurve2D.Double(); final CubicCurve2D.Double right = new CubicCurve2D.Double(); bez.subdivide(left, right); final Point2D p1 = left.getP1(); final Point2D p2 = left.getP2(); final Point2D p3 = right.getP1(); final Point2D p4 = right.getP2(); if (result == null || getCost(p1) < getCost(result)) { result = p1; angle = BezierUtils.getStartingAngle(left); } if (getCost(p2) < getCost(result)) { result = p2; angle = BezierUtils.getEndingAngle(left); } if (getCost(p3) < getCost(result)) { result = p3; angle = BezierUtils.getStartingAngle(right); } if (getCost(p4) < getCost(result)) { result = p4; angle = BezierUtils.getEndingAngle(right); } } return new PointAndAngle(result, angle); }
public MyCurve getCubicCurve2D() { MyCurve result = new MyCurve(new CubicCurve2D.Double(start.getX(), start.getY(), start.getX(), start.getY(), end.getX(), end.getY(), end.getX(), end.getY())); if (result.intersects(forbiddenRect) || result.intersects(forbiddenCurves)) { for (Point2D.Double p1 : all) { for (Point2D.Double p2 : all) { final MyCurve me = new MyCurve(new CubicCurve2D.Double(start.getX(), start.getY(), p1.getX(), p1 .getY(), p2.getX(), p2.getY(), end.getX(), end.getY())); if (me.getLenght() < min && me.intersects(forbiddenRect) == false
/**Splits a cubic Bézier curve in half. * @param c A cubic Bézier curve to be divided * @return an array with the left and right cubic Bézier subcurves * */ CubicCurve2D.Double[] cBezSplit(CubicCurve2D.Double c) { CubicCurve2D.Double[] cc = new CubicCurve2D.Double[2]; for (int i=0; i<2 ; i++) cc[i] = new CubicCurve2D.Double(); c.subdivide(cc[0],cc[1]); return cc; }
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); } }