diff --git a/content/src/outline.rs b/content/src/outline.rs index ad22caf1..99847f18 100644 --- a/content/src/outline.rs +++ b/content/src/outline.rs @@ -62,6 +62,14 @@ impl Outline { } } + #[inline] + pub fn with_capacity(capacity: usize) -> Outline { + Outline { + contours: Vec::with_capacity(capacity), + bounds: RectF::default(), + } + } + #[inline] pub fn from_segments(segments: I) -> Outline where @@ -275,7 +283,7 @@ impl Contour { #[inline] pub fn from_rect(rect: RectF) -> Contour { - let mut contour = Contour::new(); + let mut contour = Contour::with_capacity(4); contour.push_point(rect.origin(), PointFlags::empty(), false); contour.push_point(rect.upper_right(), PointFlags::empty(), false); contour.push_point(rect.lower_right(), PointFlags::empty(), false); @@ -614,6 +622,12 @@ impl Contour { } } + #[inline] + pub fn transformed(mut self, transform: &Transform2F) -> Contour { + self.transform(transform); + self + } + pub fn apply_perspective(&mut self, perspective: &Perspective) { for (point_index, point) in self.points.iter_mut().enumerate() { *point = *perspective * *point;