Skip to content

Commit

Permalink
feat(path): add .flip_x and .flip_y to path structs
Browse files Browse the repository at this point in the history
Adds path.flip_x() and path.flip_y() for Path and
Paths structs.
  • Loading branch information
tirithen committed May 4, 2024
1 parent 91e0864 commit 6323292
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,34 @@ 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();

Self::new(
self.0
.iter()
.map(|p| Point::<P>::new(size_x - (p.x() - min_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();

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

/// Returns the bounds for this path.
pub fn bounds(&self) -> Bounds {
let mut bounds = Bounds::minmax();
Expand Down
10 changes: 10 additions & 0 deletions src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ impl<P: PointScaler> Paths<P> {
Self::new(self.0.iter().map(|p| p.offset(x, y)).collect())
}

/// Construct a clone with each point x value flipped
pub fn flip_x(&self) -> Self {
Self::new(self.0.iter().map(|p| p.flip_x()).collect())
}

/// Construct a clone with each point y value flipped
pub fn flip_y(&self) -> Self {
Self::new(self.0.iter().map(|p| p.flip_y()).collect())
}

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

0 comments on commit 6323292

Please sign in to comment.