Skip to content

Commit

Permalink
fix(path): keep path bounds centered during flip
Browse files Browse the repository at this point in the history
Keep the path translations when running .flip_x()
or .flip_y().
  • Loading branch information
tirithen committed May 7, 2024
1 parent 06bcfb3 commit d87993e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,30 @@ impl<P: PointScaler> Path<P> {
/// Construct a clone with each point x value flipped
pub fn flip_x(&self) -> Self {
let bounds = self.bounds();
let min_x = bounds.min.x();
let size_x = bounds.size().x();
let center = bounds.center();

Self::new(
self.0
.iter()
.map(|p| Point::<P>::new(size_x - (p.x() - min_x), p.y()))
.map(|p| Point::<P>::new(center.x() + (center.x() - p.x()), p.y()))
.collect(),
)
}

/// Construct a clone with each point y value flipped
pub fn flip_y(&self) -> Self {
let bounds = self.bounds();
let min_y = bounds.min.y();
let size_y = bounds.size().y();
let center = bounds.center();

Self::new(
self.0
.iter()
.map(|p| Point::<P>::new(p.x(), size_y - (p.y() - min_y)))
.map(|p| Point::<P>::new(p.x(), center.y() + (center.y() - p.y())))
.collect(),
)
}

/// Returns the bounds for this path.
/// Returns the bounds for this path
pub fn bounds(&self) -> Bounds {
let mut bounds = Bounds::minmax();

Expand Down

0 comments on commit d87993e

Please sign in to comment.