Skip to content

Arcs not drawn correctly when start angle less than end angle #960

@corranwebster

Description

@corranwebster

Observed behaviour

Drawing from π/2 to 0 (it might be arguable that Agg is correct here):
Agg
image

Quartz
image

Drawing from π/2 to 0 with clockwise True (Agg is clearly not right, Quartz is at least consistent):
Agg
image

Quartz
image

To reproduce

Add these to enable.gcbench.suite and run:

class draw_arc_backwards:
    def __init__(self, gc, module):
        self.gc = gc
    
    def __call__(self):
        with self.gc:
            self.gc.begin_path()
            self.gc.arc(100.0, 100.0, 30.0, np.pi / 2, 0.0)
            self.gc.set_fill_color((0.33, 0.66, 0.99, 1.0))
            self.gc.fill_path()


class draw_arc_backwards_clockwise:
    def __init__(self, gc, module):
        self.gc = gc
    
    def __call__(self):
        with self.gc:
            self.gc.begin_path()
            self.gc.arc(100.0, 100.0, 30.0, np.pi / 2, 0.0, True)
            self.gc.set_fill_color((0.33, 0.66, 0.99, 1.0))
            self.gc.fill_path()

Expected behaviour

Not entirely sure.

Quartz is consistent, but has a significant discontinuity when the end angle sweeps over start angle, which may be problematic for plotting sectors and arcs (need to adjust cw flag appropriately when drawing). Agg avoids this, but the result when drawing "clockwise" doesn't make any sense at all. I suspect that the way that Quartz does it will be similar in other 2D libraries, since the Quartz call is a straight-through call to the underlying CoreGraphics routines.

A different possible interpretation is that an arc from one angle to another should be the path swept out between the angles, including windings (with associated effects on EOF vs. winding number fill, so 0 to 4π would be EOF empty), but then the purpose of the cw flag is unclear (one interpretation would be that it means angles are treated as clockwise from the x-axis).

In the end, I would be happy with being consistent with Quartz or HTML Canvas behaviour.

Whatever fix is put in place, it may impact rendering in downstream libraries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions