logo
pub trait IteratorExt: Iterator + Sized {
    fn perimeter(self) -> Perimeter<Self>Notable traits for Perimeter<I>impl<I> Iterator for Perimeter<I> where
    I: Iterator,
    I::Item: Clone
type Item = (I::Item, I::Item);

    where
        Self::Item: Clone
, { ... } fn keys(self) -> Keys<Self>Notable traits for Keys<I>impl<I> Iterator for Keys<I> where
    I: Iterator,
    I::Item: ClosedView
type Item = <I::Item as ClosedView>::Key;

    where
        Self::Item: ClosedView
, { ... } fn has_at_least(self, n: usize) -> Option<MultiPeek<Self>> { ... } fn has_exactly(self, n: usize) -> Option<MultiPeek<Self>> { ... } fn try_collect<T>(self) -> Result<T, T::Error>
    where
        T: TryFromIterator<Self::Item>
, { ... } }
Expand description

Extension methods for types implementing Iterator.

Provided Methods

Provides an iterator over a window of duplets that includes the first item in the sequence at both the beginning and end of the iteration.

Given a collection of ordered items $(a,b,c)$, this iterator yeilds the ordered items $((a,b),(b,c),(c,a))$.

Maps an iterator over graph views to the keys of those views.

It is often useful to examine or collect the keys of views over a MeshGraph. This iterator avoids redundant use of map to extract keys.

Examples

Collecting keys of faces before a topological mutation in a MeshGraph:

use decorum::R64;
use nalgebra::Point3;
use plexus::graph::MeshGraph;
use plexus::prelude::*;
use plexus::primitive::generate::Position;
use plexus::primitive::sphere::UvSphere;

type E3 = Point3<R64>;

let mut graph = UvSphere::new(6, 6)
    .polygons::<Position<E3>>()
    .collect::<MeshGraph<E3>>();

let keys = graph
    .faces()
    .filter(|face| face.arity() > 3)
    .keys()
    .collect::<Vec<_>>();
for key in keys {
    graph.face_mut(key).unwrap().poke_with_offset(0.5);
}

Determines if an iterator provides n or more items.

Returns a peekable iterator if the source iterator provides at least n items, otherwise None.

Examples

Ensuring that an iterator over vertices has an arity of at least three:

use plexus::IteratorExt;

fn is_convex(vertices: impl Iterator<Item = [f64; 2]>) -> bool {
    vertices
        .has_at_least(3)
        .and_then(|vertices| {
            for vertex in vertices {
                // ...
            }
            // ...
        })
        .is_some()
}

Implementors