Exemplo n.º 1
0
bool MgEllipse::setCircle(const Point2d& center, float radius)
{
    if (radius < _MGZERO)
        return false;
    Box2d rect(center, radius * 2, 0);
    setRectWithAngle(rect.leftTop(), rect.rightBottom(), getAngle(), center);
    return true;
}
Exemplo n.º 2
0
void MgBaseRect::_transform(const Matrix2d& mat)
{
    for (int i = 0; i < 4; i++)
        _points[i] *= mat;
    Box2d rect(getRect());
    setRectWithAngle(rect.leftTop(), rect.rightBottom(), getAngle(), rect.center());
    __super::_transform(mat);
}
Exemplo n.º 3
0
void MgEllipse::setRadius(float rx, float ry)
{
    rx = fabsf(rx);
    ry = fabsf(ry);
    if (ry < _MGZERO)
        ry = rx;

    Box2d rect(getCenter(), rx * 2, ry * 2);
    setRectWithAngle(rect.leftTop(), rect.rightBottom(), getAngle(), getCenter());
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
void MgBaseRect::setRect2P(const Point2d& pt1, const Point2d& pt2)
{
    setRectWithAngle(pt1, pt2, 0, pt1);
}