Handle trivial cases in X clipping
This commit is contained in:
parent
611f7379dc
commit
1e2d4ab8fe
|
@ -678,11 +678,14 @@ impl Segment {
|
||||||
fn clip_x(&self, range: Range<f32>) -> Option<Segment> {
|
fn clip_x(&self, range: Range<f32>) -> Option<Segment> {
|
||||||
//println!("clip_x({:?}, {:?})", self, range.clone());
|
//println!("clip_x({:?}, {:?})", self, range.clone());
|
||||||
|
|
||||||
if self.from.x <= range.start && self.to.x <= range.start {
|
// Trivial cases.
|
||||||
|
if (self.from.x <= range.start && self.to.x <= range.start) ||
|
||||||
|
(self.from.x >= range.end && self.to.x >= range.end) {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
if self.from.x >= range.end && self.to.x >= range.end {
|
let (start, end) = (f32::min(self.from.x, self.to.x), f32::max(self.from.x, self.to.x));
|
||||||
return None
|
if start >= range.start && end <= range.end {
|
||||||
|
return Some(*self)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(pcwalton): Reduce code duplication!
|
// FIXME(pcwalton): Reduce code duplication!
|
||||||
|
@ -819,18 +822,8 @@ impl Segment {
|
||||||
!self.flags.contains(SegmentFlags::HAS_ENDPOINTS)
|
!self.flags.contains(SegmentFlags::HAS_ENDPOINTS)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: If we convert these to monotonic then we can optimize this method.
|
|
||||||
// TODO(pcwalton): Consider changing the representation of `Segment` to remove the code
|
|
||||||
// duplication in the branches here?
|
|
||||||
fn min_y(&self) -> f32 {
|
fn min_y(&self) -> f32 {
|
||||||
let mut min_y = f32::min(self.from.y, self.to.y);
|
f32::min(self.from.y, self.to.y)
|
||||||
if self.flags.contains(SegmentFlags::HAS_CONTROL_POINT_0) {
|
|
||||||
min_y = f32::min(min_y, self.ctrl0.y)
|
|
||||||
}
|
|
||||||
if self.flags.contains(SegmentFlags::HAS_CONTROL_POINT_1) {
|
|
||||||
min_y = f32::min(min_y, self.ctrl1.y)
|
|
||||||
}
|
|
||||||
min_y
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clip_y(&self, y: f32) -> ClippedSegments {
|
fn clip_y(&self, y: f32) -> ClippedSegments {
|
||||||
|
|
Loading…
Reference in New Issue