Example #1
0
bool GiGraphics::drawRect(const GiContext* ctx, const Box2d& rect, 
                          bool modelUnit)
{
    if (rect.isEmpty() && ctx && m_impl->canvas) {
        rawRect(ctx, 0, 0, 0, 0);
        return false;
    }
    Point2d points[4] = {
        rect.leftBottom(), rect.rightBottom(), 
        rect.rightTop(), rect.leftTop()
    };
    return !rect.isEmpty() && drawPolygon(ctx, 4, points, modelUnit);
}
Example #2
0
bool GiGraphics::_drawPolygon(const GiContext* ctx, int count, const Point2d* points,
                              bool m2d, bool fill, bool edge, bool modelUnit)
{
    GiContext context (ctx ? *ctx : m_impl->ctx);
    if (!edge)
        context.setNullLine();
    if (!fill)
        context.setNoFillColor();
    
    if (context.isNullLine() && !context.hasFillColor())
        return false;

    vector<Point2d> pxpoints;
    Point2d pt1, pt2;
    Matrix2d matD(S2D(xf(), modelUnit));

    pxpoints.resize(count);
    Point2d *pxs = &pxpoints.front();
    int n = 0;
    for (int i = 0; i < count; i++) {
        pt2 = points[i];
        if (m2d)
            pt2 *= matD;
        if (i == 0 || count <= 4
            || fabsf(pt1.x - pt2.x) > 2
            || fabsf(pt1.y - pt2.y) > 2) {
            pt1 = pt2;
            pxs[n++] = pt1;
        }
    }

    if (n == 4 && m2d
        && mgEquals(pxs[0].x, pxs[3].x) && mgEquals(pxs[1].x, pxs[2].x)
        && mgEquals(pxs[0].y, pxs[1].y) && mgEquals(pxs[2].y, pxs[3].y))
    {
        Box2d rc(pxs[0].x, pxs[0].y, pxs[2].x, pxs[2].y, true);
        return rawRect(&context, rc.xmin, rc.ymin, rc.width(), rc.height());
    }

    return rawPolygon(&context, pxs, n);
}