Skip to content

nvgArc does some ugly overdraw #659

@mulle-nat

Description

@mulle-nat

I suspect, that when the area to fill gets less than a pixel, something goes awry at the very top of the circle hole:

image

In this special case, it can be mitigated with nvgIntersectScissor.

For reference this is how it's drawn (it uses a few "UIKit"isms, that should be easy to understand)

void drawSplitRectWithHole(NVGcontext* vg, CGRect rect, CGFloat x, CGFloat radius)
{
    CGFloat y = CGRectGetMidY( rect);
    CGFloat angle = asinf( rect.size.height / (2 * radius));

    nvgSave( vg);
    //nvgIntersectScissor( vg, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);

    // Draw the left part
    nvgBeginPath(vg);
    nvgMoveTo(vg, CGRectGetMinX( rect), CGRectGetMinY( rect));
    nvgLineTo(vg, x - radius * cosf(angle), CGRectGetMinY( rect));
    nvgArc(vg, x, y, radius, M_PI_f + angle, M_PI_f - angle, NVG_CCW);
    nvgLineTo(vg, CGRectGetMinX( rect), CGRectGetMaxY( rect));
    nvgClosePath(vg);
    nvgFillColor( vg, CGColorMakeIndigo());
    nvgFill(vg);

    // Draw the right part 
    nvgBeginPath(vg);
    nvgMoveTo(vg, x + radius * cosf(angle), CGRectGetMinY( rect));
    nvgLineTo(vg, CGRectGetMaxX( rect), CGRectGetMinY( rect));
    nvgLineTo(vg, CGRectGetMaxX( rect), CGRectGetMaxY( rect));
    nvgLineTo(vg, x + radius * cosf(angle), CGRectGetMaxY( rect));
    nvgArc(vg, x, y, radius, angle, -angle, NVG_CCW);
    nvgClosePath(vg);
    nvgFillColor( vg, CGColorMakeOrange());
    nvgFill(vg);

    nvgRestore( vg);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions