minlin 0.4.0

Rust library with minimal linear algebra made to be as convinient as possible.
Documentation
use std::ops::AddAssign;

use crate::{One, Vec2};

/// Iterator over 2D area.
pub struct Vec2RangeIter<T> {
    start: Vec2<T>,
    end: Vec2<T>,
    x: T,
}

impl<T> Vec2RangeIter<T>
where
    T: Copy,
{
    /// Create new iterator over 2D area.
    pub fn new(start: Vec2<T>, end: Vec2<T>) -> Self {
        Self {
            x: start.x,
            start,
            end,
        }
    }
}

impl<T> Vec2RangeIter<T> {
    /// Check whether the remaining part contains te given vector.
    pub fn contains(&self, other: impl Into<Vec2<T>>) -> bool
    where
        T: Ord,
    {
        let Vec2 { x, y } = other.into();
        x >= self.start.x
            && x < self.end.x
            && y >= self.start.y
            && y < self.end.y
    }
}

impl<T> Iterator for Vec2RangeIter<T>
where
    T: Copy + AddAssign + PartialOrd + One,
{
    type Item = Vec2<T>;

    fn next(&mut self) -> Option<Self::Item> {
        if self.x >= self.end.x {
            if self.x == self.start.x {
                return None;
            }
            self.x = self.start.x;
            self.start.y += T::ONE;
        }

        if self.start.y >= self.end.y {
            return None;
        }

        let res = (self.x, self.start.y);
        self.x += T::ONE;
        Some(res.into())
    }
}