Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/path_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,19 @@ impl PathBuilder {
/// For a positive `sweep_angle` the sweep is done clockwise, for a negative
/// `sweep_angle` the sweep is done counterclockwise.
pub fn arc(&mut self, x: f32, y: f32, r: f32, start_angle: f32, sweep_angle: f32) {
self.ellipse(x, y, r, r, start_angle, sweep_angle);
}

/// Adds an arc approximated by quadratic beziers with center `x`, `y`
/// and radius components `x_radius`, `y_radius` starting at `start_angle`
/// and sweeping by `sweep_angle`. For a positive `sweep_angle` the sweep
/// is done clockwise, for a negative `sweep_angle` the sweep is done
/// counterclockwise.
pub fn ellipse(&mut self, x: f32, y: f32, radius_x: f32, radius_y: f32, start_angle: f32, sweep_angle: f32) {
//XXX: handle the current point being the wrong spot
let a: Arc<f32> = Arc {
center: Point::new(x, y),
radii: Vector::new(r, r),
radii: Vector::new(radius_x, radius_y),
start_angle: Angle::radians(start_angle),
sweep_angle: Angle::radians(sweep_angle),
x_rotation: Angle::zero(),
Expand Down
18 changes: 18 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,24 @@ mod tests {
assert!(!path.contains_point(0.1, 70., 30.));
}

#[test]
fn ellipse_contains() {
let mut pb = PathBuilder::new();
pb.ellipse(50., 25., 10., 20., 0., std::f32::consts::PI);
let path = pb.finish();
assert!(!path.contains_point(0.1, 50., 10.));
assert!(!path.contains_point(0.1, 50., 20.));
assert!(path.contains_point(0.1, 50., 30.));
assert!(path.contains_point(0.1, 50., 40.));
assert!(!path.contains_point(0.1, 30., 20.));
assert!(!path.contains_point(0.1, 70., 20.));
assert!(!path.contains_point(0.1, 30., 30.));
assert!(!path.contains_point(0.1, 70., 30.));
assert!(!path.contains_point(0.1, 30., 40.));
assert!(!path.contains_point(0.1, 50., 50.));
assert!(!path.contains_point(0.1, 70., 40.));
}

#[test]
fn new_linear_gradient_zerosize() {
let source = Source::new_linear_gradient(
Expand Down