@@ -61,6 +61,15 @@ impl Outline {
61
61
}
62
62
}
63
63
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
+
64
73
#[ inline]
65
74
pub fn from_segments < I > ( segments : I ) -> Outline
66
75
where
@@ -178,6 +187,11 @@ impl Outline {
178
187
self . bounds = new_bounds. unwrap_or_else ( || RectF :: default ( ) ) ;
179
188
}
180
189
190
+ pub fn transformed ( mut self , transform : & Transform2F ) -> Outline {
191
+ self . transform ( transform) ;
192
+ self
193
+ }
194
+
181
195
pub fn apply_perspective ( & mut self , perspective : & Perspective ) {
182
196
let mut new_bounds = None ;
183
197
for contour in & mut self . contours {
@@ -224,6 +238,12 @@ impl Outline {
224
238
self . contours . iter ( ) . all ( Contour :: is_empty)
225
239
}
226
240
241
+ /// Returns the number of contours in this outline.
242
+ #[ inline]
243
+ pub fn len ( & self ) -> usize {
244
+ self . contours . len ( )
245
+ }
246
+
227
247
/// Appends the contours in another outline to this one.
228
248
pub fn push_outline ( & mut self , other : Outline ) {
229
249
if other. is_empty ( ) {
@@ -275,7 +295,7 @@ impl Contour {
275
295
276
296
#[ inline]
277
297
pub fn from_rect ( rect : RectF ) -> Contour {
278
- let mut contour = Contour :: new ( ) ;
298
+ let mut contour = Contour :: with_capacity ( 4 ) ;
279
299
contour. push_point ( rect. origin ( ) , PointFlags :: empty ( ) , false ) ;
280
300
contour. push_point ( rect. upper_right ( ) , PointFlags :: empty ( ) , false ) ;
281
301
contour. push_point ( rect. lower_right ( ) , PointFlags :: empty ( ) , false ) ;
@@ -614,6 +634,12 @@ impl Contour {
614
634
}
615
635
}
616
636
637
+ #[ inline]
638
+ pub fn transformed ( mut self , transform : & Transform2F ) -> Contour {
639
+ self . transform ( transform) ;
640
+ self
641
+ }
642
+
617
643
pub fn apply_perspective ( & mut self , perspective : & Perspective ) {
618
644
for ( point_index, point) in self . points . iter_mut ( ) . enumerate ( ) {
619
645
* point = * perspective * * point;
0 commit comments