Skip to content

Commit

Permalink
feat: add .offset(x, y) method to Path and Paths
Browse files Browse the repository at this point in the history
Adds a offset method to Path and Paths structs that
creates a clone with each point offset by that x/y
value.
  • Loading branch information
tirithen committed May 3, 2024
1 parent b17ccfd commit be676f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ impl<P: PointScaler> Path<P> {
}
}

/// Construct a clone with each point offset with a x/y distance
pub fn offset(&self, x: f64, y: f64) -> Self {
Self::new(
self.0
.iter()
.map(|p| Point::<P>::new(p.x() + x, p.y() + y))
.collect(),
)
}

/// Returns the bounds for this path.
pub fn bounds(&self) -> Bounds {
let mut bounds = Bounds::minmax();
Expand Down
5 changes: 5 additions & 0 deletions src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ impl<P: PointScaler> Paths<P> {
}
}

/// Construct a clone with each point offset with a x/y distance
pub fn offset(&self, x: f64, y: f64) -> Self {
Self::new(self.0.iter().map(|p| p.offset(x, y)).collect())
}

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

0 comments on commit be676f5

Please sign in to comment.