-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add bounds struct to path/paths
Adds Bounds struct that gives information about the min/max cut coordinates of a Path or Paths struct.
- Loading branch information
Showing
5 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::Point; | ||
|
||
/// Represents an area from one min and one max [Point](struct.Point.html). | ||
#[derive(Default, Debug, Copy, Clone, PartialEq)] | ||
pub struct Bounds { | ||
/// Minimum point of the boundary. | ||
pub min: Point, | ||
/// Maximum point of the boundary. | ||
pub max: Point, | ||
} | ||
|
||
impl Bounds { | ||
/// Create a `Bounds` struct starting at xy 0.0 and ending at the given xy | ||
/// coordinates. | ||
#[must_use] | ||
pub fn new(x: f64, y: f64) -> Self { | ||
Self { | ||
min: Point::new(0.0, 0.0), | ||
max: Point::new(x, y), | ||
} | ||
} | ||
|
||
/// Create a `Bounds` struct using xy maximum value as min and minimum value | ||
/// for max. | ||
#[must_use] | ||
pub fn minmax() -> Self { | ||
Self { | ||
min: Point::MAX, | ||
max: Point::MIN, | ||
} | ||
} | ||
|
||
/// Return the size of the bounds area as a [Point](struct.Point.html). | ||
#[must_use] | ||
pub fn size(&self) -> Point { | ||
Point::new(self.max.x() - self.min.x(), self.max.y() - self.min.y()) | ||
} | ||
|
||
/// Return the center of the bounds area as a [Point](struct.Point.html). | ||
#[must_use] | ||
pub fn center(&self) -> Point { | ||
let size = self.size(); | ||
Point::new(self.min.x() + size.x() / 2.0, self.min.y() + size.y() / 2.0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters