DVUI

addArc

Add line segments creating an arc to path.

start >= end, both are radians that go clockwise from the positive x axis.

If skip_end, the final point will not be added. Useful if the next addition to path would duplicate the end of the arc.

Parameters

#
path:*Builder
*Builder
center:Point.Physical
Point.Physical
radius:f32
f32
start:f32
f32
end:f32
f32
skip_end:bool
bool

Source

Implementation

#
pub fn addArc(path: *Builder, center: Point.Physical, radius: f32, start: f32, end: f32, skip_end: bool) void {
        if (radius == 0) {
            path.addPoint(center);
            return;
        }

        // how close our points will be to the perfect circle
        const err = 0.5;

        // angle that has err error between circle and segments
        const theta = math.acos(radius / (radius + err));

        var a: f32 = start;
        path.addPoint(.{ .x = center.x + radius * @cos(a), .y = center.y + radius * @sin(a) });

        while (a - end > theta) {
            // move to next fixed theta, this prevents shimmering on things like a spinner
            a = @floor((a - 0.001) / theta) * theta;
            path.addPoint(.{ .x = center.x + radius * @cos(a), .y = center.y + radius * @sin(a) });
        }

        if (!skip_end) {
            a = end;
            path.addPoint(.{ .x = center.x + radius * @cos(a), .y = center.y + radius * @sin(a) });
        }
    }