bezier-nd 0.6.0

Bezier curve implementations using N-dimensional vectors
Documentation
//a Imports
use crate::line::BezierLineIter;
use geo_nd::Float;

//a BezierPointIter
//tp BezierPointIter
/// An iterator with Item = V of points that form a single Bezier curve where the
/// steps between points would be lines that are 'straight enough'.
///
/// This iterator returns the points that BezierLineIter uses, in the
/// same order (pa, pb, ...).
///
/// The first point returned will be the starting point of the Bezier
/// (control point `p0`); the last point returned will be the end
/// point of the Bezier (control point `p1`).
///
/// This iterator is generated by the [crate::Bezier::as_points] method
pub struct BezierPointIter<F: Float, const D: usize> {
    /// A line iterator that returns the next line segment required;
    /// usually the first point of this segment that this iterator
    /// provides is returned as the next point.
    ///
    /// When this returns none, the end-point of the previous
    /// iteration needs to be returned as the last point.
    lines: BezierLineIter<F, D>,

    /// The last point to be returned - if this is valid then the line
    /// iterator has finished, and just the last point on the Bezier
    /// needs to be returned.
    last_point: Option<[F; D]>,
}

//ip BezierPointIter
impl<F, const D: usize> BezierPointIter<F, D>
where
    F: Float,
{
    //fp new
    /// Create a new point iterator from a line iterator
    pub fn new(lines: BezierLineIter<F, D>) -> Self {
        Self {
            lines,
            last_point: None,
        }
    }

    //zz All done
}

//ii BezierPointIter
impl<F, const D: usize> Iterator for BezierPointIter<F, D>
where
    F: Float,
{
    /// Iterator returns Point's
    type Item = [F; D];

    /// Return the first point of any line segment provided by the
    /// line iterator, but record the endpoint of that segment first;
    /// if the line iterator has finished then return any recorded
    /// endpoint, deleting it first.
    fn next(&mut self) -> Option<Self::Item> {
        if let Some((p0, p1)) = self.lines.next() {
            self.last_point = Some(p1);
            Some(p0)
        } else {
            let p = self.last_point;
            self.last_point = None;
            p
        }
    }

    //zz All done
}