bool MgArc::_hitTestBox(const Box2d& rect) const { if (!getExtent().isIntersect(rect)) return false; Point2d points[16]; int n = mgcurv::arcToBezier(points, getCenter(), getRadius(), 0, getStartAngle(), getSweepAngle()); return rect.contains(getCenter()) || mgnear::beziersIntersectBox(rect, n, points); }
bool MgPath::crossWithPath(const MgPath& p, const Box2d& box, Point2d& ptCross) const { MgPathCrossCallback cc(box, ptCross); if (isLine() && p.isLine()) { return (mglnrel::cross2Line(getPoint(0), getPoint(1), p.getPoint(0), p.getPoint(1), ptCross) && box.contains(ptCross)); } if (isLines() && p.isLines()) { for (int m = getCount() - (isClosed() ? 0 : 1), i = 0; i < m; i++) { Point2d a(getPoint(i)), b(getPoint(i + 1)); for (int n = p.getCount() - (p.isClosed() ? 0 : 1), j = 0; j < n; j++) { Point2d c(p.getPoint(j)), d(p.getPoint(j + 1)); if (mglnrel::cross2Line(a, b, c, d, cc.tmpcross) && box.contains(cc.tmpcross)) { float dist = cc.tmpcross.distanceTo(box.center()); if (cc.mindist > dist) { cc.mindist = dist; ptCross = cc.tmpcross; } } } } } else if (isLine() && p.getSubPathCount() == 1) { cc.a = getPoint(0); cc.b = getPoint(1); p.scanSegments(cc); } else if (p.isLine() && getSubPathCount() == 1) { cc.a = p.getPoint(0); cc.b = p.getPoint(1); scanSegments(cc); } return cc.mindist < box.width(); }