nical / lyon

2D graphics rendering on the GPU in rust using path tessellation.
Other
2.28k stars 140 forks source link

Arc angle starting position is unusual #909

Open tgross35 opened 1 month ago

tgross35 commented 1 month ago

I am trying the following code:

let mut builder = Path::builder().with_svg();

builder.arc(
    lyon::math::point(1000.0, 1000.0),
    vector(500000.0, 500000.0),
    Angle::radians(std::f32::consts::PI * 3.0 / 2.0),
    Angle::radians(0.0),
);

let path = builder.build();

self.stroke_tess
    .tessellate_path(
        &path,
        &STROKE_OPTIONS
            .with_line_width(10000.0)
            .with_start_cap(lyon::path::LineCap::Square)
            .with_end_cap(lyon::path::LineCap::Round),
        &mut BuffersBuilder::new(
            &mut self.stroke_geometry,
            WithColor(item.color.as_float_rgba()),
        ),
    )
    .unwrap();

And it comes up with this result:

image

From this, it looks like the angle starts at -3π/4 and the angle increases counterclockwise. This seems weird to me instead of starting at 0 - is this correct?

nical commented 1 month ago

The reason the arc is angled this way in your example is that the original angle is defined by the angle between the center and the current position of the path builder. If there hasn't been any command in the path builder, the current position is (0, 0). If you try to use a move_to command before the arc it should affect the starting angle accordingly.

nical commented 1 month ago

I explained why arc is the way it is in lyon, I also think that this behavior is fine but that doesn't necessarily mean that it should be that way. I don't have the time right now to delve into the SVG specification and figure out whether another behavior for this special case would better match the spec, but feel free to make a case for it if you think that's the case.