提交 ee1a5ea8 编写于 作者: D dlila

4724552: CubicCurve2D.contains(Rectangle2D) returns true when only partially contained.

Summary: Now using subdivision code in sun.awt.geom.Curve.
Reviewed-by: flar
上级 de4c501d
...@@ -1602,20 +1602,32 @@ public abstract class CubicCurve2D implements Shape, Cloneable { ...@@ -1602,20 +1602,32 @@ public abstract class CubicCurve2D implements Shape, Cloneable {
if (w <= 0 || h <= 0) { if (w <= 0 || h <= 0) {
return false; return false;
} }
// Assertion: Cubic curves closed by connecting their
// endpoints form either one or two convex halves with int numCrossings = rectCrossings(x, y, w, h);
// the closing line segment as an edge of both sides. return !(numCrossings == 0 || numCrossings == Curve.RECT_INTERSECTS);
if (!(contains(x, y) && }
contains(x + w, y) &&
contains(x + w, y + h) && private int rectCrossings(double x, double y, double w, double h) {
contains(x, y + h))) { int crossings = 0;
return false; if (!(getX1() == getX2() && getY1() == getY2())) {
crossings = Curve.rectCrossingsForLine(crossings,
x, y,
x+w, y+h,
getX1(), getY1(),
getX2(), getY2());
if (crossings == Curve.RECT_INTERSECTS) {
return crossings;
}
} }
// Either the rectangle is entirely inside one of the convex // we call this with the curve's direction reversed, because we wanted
// halves or it crosses from one to the other, in which case // to call rectCrossingsForLine first, because it's cheaper.
// it must intersect the closing line segment. return Curve.rectCrossingsForCubic(crossings,
Rectangle2D rect = new Rectangle2D.Double(x, y, w, h); x, y,
return !rect.intersectsLine(getX1(), getY1(), getX2(), getY2()); x+w, y+h,
getX2(), getY2(),
getCtrlX2(), getCtrlY2(),
getCtrlX1(), getCtrlY1(),
getX1(), getY1(), 0);
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册