Add the `ellipse` method to canvas paths

This commit is contained in:
Patrick Walton 2019-05-30 17:24:03 -07:00
parent 9756aa89f9
commit 95f3337c6f
2 changed files with 20 additions and 1 deletions

View File

@ -25,6 +25,7 @@ use pathfinder_renderer::scene::{PathObject, Scene};
use pathfinder_text::{SceneExt, TextRenderMode};
use skribo::{FontCollection, FontFamily, Layout, TextStyle};
use std::default::Default;
use std::f32::consts::PI;
use std::mem;
use std::sync::Arc;
@ -325,6 +326,24 @@ impl Path2D {
self.current_contour.close();
}
pub fn ellipse(&mut self,
center: Point2DF,
axes: Point2DF,
rotation: f32,
start_angle: f32,
end_angle: f32) {
self.flush_current_contour();
let mut transform = Transform2DF::from_rotation(rotation);
transform = transform.post_mul(&Transform2DF::from_scale(axes));
transform = transform.post_mul(&Transform2DF::from_translation(center));
self.current_contour.push_arc(&transform, start_angle, end_angle);
if end_angle - start_angle >= 2.0 * PI {
self.current_contour.close();
}
}
fn into_outline(mut self) -> Outline {
self.flush_current_contour();
self.outline

View File

@ -152,7 +152,7 @@ impl MoireRenderer {
for index in 0..CIRCLE_COUNT {
let radius = (index + 1) as f32 * CIRCLE_SPACING * self.device_pixel_ratio;
let mut path = Path2D::new();
path.arc(center, radius, 0.0, PI * 2.0);
path.ellipse(center, Point2DF::splat(radius), 0.0, 0.0, PI * 2.0);
canvas.stroke_path(path);
}
}