bool MgDiamond::_draw(GiGraphics& gs, const GiContext& ctx) const { Point2d pts[] = { _getHandlePoint(0), _getHandlePoint(1), _getHandlePoint(2), _getHandlePoint(3) }; bool ret = gs.drawPolygon(&ctx, 4, pts); return __super::_draw(gs, ctx) || ret; }
float MgDiamond::_hitTest(const Point2d& pt, float tol, Point2d& nearpt, Int32& segment) const { Point2d pts[] = { _getHandlePoint(0), _getHandlePoint(1), _getHandlePoint(2), _getHandlePoint(3) }; return mgLinesHit(4, pts, true, pt, tol, nearpt, segment); }
void MgDiamond::_update() { __super::_update(); Point2d pts[] = { _getHandlePoint(0), _getHandlePoint(1), _getHandlePoint(2), _getHandlePoint(3) }; _extent.set(4, pts); }
bool MgDiamond::_hitTestBox(const Box2d& rect) const { if (!__super::_hitTestBox(rect)) return false; for (int i = 0; i < 3; i++) { if (Box2d(_getHandlePoint(i), _getHandlePoint(i + 1)).isIntersect(rect)) return true; } return false; }
bool MgBaseRect::_setHandlePoint(int index, const Point2d& pt, float) { if (getFlag(kMgSquare)) { if (isCurve() && !isEmpty(_MGZERO)) { float olddist = _getHandlePoint(index).distanceTo(getCenter()); transform(Matrix2d::scaling(pt.distanceTo(getCenter()) / olddist, getCenter())); } else { Matrix2d mat(Matrix2d::rotation(-getAngle(), getCenter())); Point2d pt2(pt * mat); Box2d rect(getRect()); mgnear::moveRectHandle(rect, index, pt2); if (4 == index || 6 == index) { rect = Box2d(rect.center(), rect.height(), rect.height()); } else { rect = Box2d(rect.center(), rect.width(), rect.width()); } setRectWithAngle(rect.leftTop(), rect.rightBottom(), getAngle(), rect.center() * mat.inverse()); } } else { int index2 = index / 4 * 4 + (index % 4 + 2) % 4; Point2d corner(_getHandlePoint(index2)); Matrix2d mat(Matrix2d::rotation(-getAngle(), corner)); Box2d rect(_getHandlePoint(0) * mat, _getHandlePoint(2) * mat); Point2d pt2(pt * mat); mgnear::moveRectHandle(rect, index, pt2); setRectWithAngle(rect.leftTop(), rect.rightBottom(), getAngle(), corner); } update(); return true; }
Point2d MgBaseShape::getHandlePoint(int index) const { return _getHandlePoint(index); }
bool MgComposite::_setHandlePoint(int index, const Point2d& pt, float) { return _offset(pt - _getHandlePoint(index), -1); }