Auto merge of #367 - pcwalton:transformed, r=pcwalton
Add some new Outline methods
This commit is contained in:
commit
495708dbf1
|
@ -61,6 +61,15 @@ impl Outline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a new `Outline` with storage for `capacity` contours preallocated.
|
||||||
|
#[inline]
|
||||||
|
pub fn with_capacity(capacity: usize) -> Outline {
|
||||||
|
Outline {
|
||||||
|
contours: Vec::with_capacity(capacity),
|
||||||
|
bounds: RectF::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_segments<I>(segments: I) -> Outline
|
pub fn from_segments<I>(segments: I) -> Outline
|
||||||
where
|
where
|
||||||
|
@ -178,6 +187,11 @@ impl Outline {
|
||||||
self.bounds = new_bounds.unwrap_or_else(|| RectF::default());
|
self.bounds = new_bounds.unwrap_or_else(|| RectF::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn transformed(mut self, transform: &Transform2F) -> Outline {
|
||||||
|
self.transform(transform);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn apply_perspective(&mut self, perspective: &Perspective) {
|
pub fn apply_perspective(&mut self, perspective: &Perspective) {
|
||||||
let mut new_bounds = None;
|
let mut new_bounds = None;
|
||||||
for contour in &mut self.contours {
|
for contour in &mut self.contours {
|
||||||
|
@ -224,6 +238,12 @@ impl Outline {
|
||||||
self.contours.iter().all(Contour::is_empty)
|
self.contours.iter().all(Contour::is_empty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the number of contours in this outline.
|
||||||
|
#[inline]
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.contours.len()
|
||||||
|
}
|
||||||
|
|
||||||
/// Appends the contours in another outline to this one.
|
/// Appends the contours in another outline to this one.
|
||||||
pub fn push_outline(&mut self, other: Outline) {
|
pub fn push_outline(&mut self, other: Outline) {
|
||||||
if other.is_empty() {
|
if other.is_empty() {
|
||||||
|
@ -275,7 +295,7 @@ impl Contour {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_rect(rect: RectF) -> Contour {
|
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.origin(), PointFlags::empty(), false);
|
||||||
contour.push_point(rect.upper_right(), PointFlags::empty(), false);
|
contour.push_point(rect.upper_right(), PointFlags::empty(), false);
|
||||||
contour.push_point(rect.lower_right(), PointFlags::empty(), false);
|
contour.push_point(rect.lower_right(), PointFlags::empty(), false);
|
||||||
|
@ -614,6 +634,12 @@ impl Contour {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn transformed(mut self, transform: &Transform2F) -> Contour {
|
||||||
|
self.transform(transform);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn apply_perspective(&mut self, perspective: &Perspective) {
|
pub fn apply_perspective(&mut self, perspective: &Perspective) {
|
||||||
for (point_index, point) in self.points.iter_mut().enumerate() {
|
for (point_index, point) in self.points.iter_mut().enumerate() {
|
||||||
*point = *perspective * *point;
|
*point = *perspective * *point;
|
||||||
|
|
Loading…
Reference in New Issue