Merge pull request #446 from hannobraun/chain

Expand `PolyChain` API
This commit is contained in:
Hanno Braun 2022-04-09 15:43:26 +02:00 committed by GitHub
commit 1202b5dad6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,11 @@ pub struct PolyChain<const D: usize> {
}
impl<const D: usize> PolyChain<D> {
/// Create an empty `PolyChain`
pub fn new() -> Self {
Self { points: Vec::new() }
}
/// Construct a polygonal chain from a number of points
pub fn from_points(
points: impl IntoIterator<Item = impl Into<Point<D>>>,
@ -46,6 +51,18 @@ impl<const D: usize> PolyChain<D> {
self
}
/// Reverse the order of points in the `PolyChain`
pub fn reverse(mut self) -> Self {
self.points.reverse();
self
}
}
impl<const D: usize> Default for PolyChain<D> {
fn default() -> Self {
Self::new()
}
}
impl<P, Ps, const D: usize> From<Ps> for PolyChain<D>