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); }
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); }
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); } }