add Outline::with_capacity, Contour::transformed and a small fix

This commit is contained in:
Sebastian K 2020-06-17 08:00:41 +03:00
parent 7e05972549
commit 26e41b82ff
1 changed files with 15 additions and 1 deletions

View File

@ -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<I>(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;