Skip to content

Commit 495708d

Browse files
authored
Auto merge of #367 - pcwalton:transformed, r=pcwalton
Add some new Outline methods
2 parents 265e781 + 9d86f66 commit 495708d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

content/src/outline.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ impl Outline {
6161
}
6262
}
6363

64+
/// Returns a new `Outline` with storage for `capacity` contours preallocated.
65+
#[inline]
66+
pub fn with_capacity(capacity: usize) -> Outline {
67+
Outline {
68+
contours: Vec::with_capacity(capacity),
69+
bounds: RectF::default(),
70+
}
71+
}
72+
6473
#[inline]
6574
pub fn from_segments<I>(segments: I) -> Outline
6675
where
@@ -178,6 +187,11 @@ impl Outline {
178187
self.bounds = new_bounds.unwrap_or_else(|| RectF::default());
179188
}
180189

190+
pub fn transformed(mut self, transform: &Transform2F) -> Outline {
191+
self.transform(transform);
192+
self
193+
}
194+
181195
pub fn apply_perspective(&mut self, perspective: &Perspective) {
182196
let mut new_bounds = None;
183197
for contour in &mut self.contours {
@@ -224,6 +238,12 @@ impl Outline {
224238
self.contours.iter().all(Contour::is_empty)
225239
}
226240

241+
/// Returns the number of contours in this outline.
242+
#[inline]
243+
pub fn len(&self) -> usize {
244+
self.contours.len()
245+
}
246+
227247
/// Appends the contours in another outline to this one.
228248
pub fn push_outline(&mut self, other: Outline) {
229249
if other.is_empty() {
@@ -275,7 +295,7 @@ impl Contour {
275295

276296
#[inline]
277297
pub fn from_rect(rect: RectF) -> Contour {
278-
let mut contour = Contour::new();
298+
let mut contour = Contour::with_capacity(4);
279299
contour.push_point(rect.origin(), PointFlags::empty(), false);
280300
contour.push_point(rect.upper_right(), PointFlags::empty(), false);
281301
contour.push_point(rect.lower_right(), PointFlags::empty(), false);
@@ -614,6 +634,12 @@ impl Contour {
614634
}
615635
}
616636

637+
#[inline]
638+
pub fn transformed(mut self, transform: &Transform2F) -> Contour {
639+
self.transform(transform);
640+
self
641+
}
642+
617643
pub fn apply_perspective(&mut self, perspective: &Perspective) {
618644
for (point_index, point) in self.points.iter_mut().enumerate() {
619645
*point = *perspective * *point;

0 commit comments

Comments
 (0)