pub fn expand(v: Vector) -> Vec<Coord> {
        if v.from == v.to {
            return vec![v.from];
        }

        // Moving in diagonals is currently not supported, so if the Vector
        // doesn't strictly move on the X or Y axis, return an empty list.
        let mut coords = vec![];
        if v.from.x == v.to.x {
            let x = v.from.x;
            let lower = min(v.from.y, v.to.y);
            let higher = max(v.from.y, v.to.y);
            for y in lower..higher + 1 {
                coords.push(Coord { x, y });
            }
        } else if v.from.y == v.to.y {
            let y = v.from.y;
            let lower = min(v.from.x, v.to.x);
            let higher = max(v.from.x, v.to.x);
            for x in lower..higher + 1 {
                coords.push(Coord { x, y });
            }
        } else if (v.from.y - v.to.y).abs() == (v.from.x - v.to.x).abs() {
            // "perfect" diagonal
            let mut range_x = v.from.x..v.to.x + 1;
            if range_x.is_empty() {
                range_x = Range::from((v.to.x..v.from.x + 1).rev());
            }

            let mut range_y = v.from.y..v.to.y + 1;
            if range_y.is_empty() {
                range_y = (v.to.y..v.from.y + 1).rev();
            }

            coords = range_x
                .zip(range_y)
                .map(|(x, y)| Coord::from((x, y)))
                .collect();
        } else {
            println!("{} is a diagonal", v);
        }

        coords
    }
/// Expands a Vector v into a list of Coordiates covered by the Vector.
Expands a Vector v into a list of Coordiates covered by the Vector.
Expands a Vector v into a list of Coordiates covered by the Vector .
pub fn expand(v: Vector) -> Vec<Coord> {
        if v.from == v.to {
            return vec![v.from];
        }
        // Moving in diagonals is currently not supported, so if the Vector
        // doesn't strictly move on the X or Y axis, return an empty list.
        let mut coords = vec![];
        if v.from.x == v.to.x {
            let x = v.from.x;
            let lower = min(v.from.y, v.to.y);
            let higher = max(v.from.y, v.to.y);
            for y in lower..higher + 1 {
                coords.push(Coord { x, y });
            }
        } else if v.from.y == v.to.y {
            let y = v.from.y;
            let lower = min(v.from.x, v.to.x);
            let higher = max(v.from.x, v.to.x);
            for x in lower..higher + 1 {
                coords.push(Coord { x, y });
            }
        } else if (v.from.y - v.to.y).abs() == (v.from.x - v.to.x).abs() {
            // "perfect" diagonal
            let mut range_x = v.from.x..v.to.x + 1;
            if range_x.is_empty() {
                range_x = Range::from((v.to.x..v.from.x + 1).rev());
            }
            let mut range_y = v.from.y..v.to.y + 1;
            if range_y.is_empty() {
                range_y = (v.to.y..v.from.y + 1).rev();
            }
            coords = range_x
                .zip(range_y)
                .map(|(x, y)| Coord::from((x, y)))
                .collect();
        } else {
            println!("{} is a diagonal", v);
        }
        coords
    }
pub fn expand ( v : Vector ) -> Vec < Coord > { if v . from == v . to { return vec ! [ v from ] ; } // Moving in diagonals is currently not supported, so if the Vector // doesn't strictly move on the X or Y axis, return an empty list. let mut coords = vec ! [ ] ; if v . from . x == v . to . x { let x = v . from . x ; let lower = min ( v . from . y , v . to . y ) ; let higher = max ( v . from . y , v . to . y ) ; for y in lower .. higher + 1 { coords . push ( Coord { x , y } ) ; } } else if v . from . y == v . to . y { let y = v . from . y ; let lower = min ( v . from . x , v . to . x ) ; let higher = max ( v . from . x , v . to . x ) ; for x in lower .. higher + 1 { coords . push ( Coord { x , y } ) ; } } else if ( v . from . y - v . to . y ) . abs ( ) == ( v . from . x - v . to . x ) . abs ( ) { // "perfect" diagonal let mut range_x = v . from . x .. v . to . x + 1 ; if range_x . is_empty ( ) { range_x = Range :: from ( ( v . to . x .. v . from . x + 1 ) . rev ( ) ) ; } let mut range_y = v . from . y .. v . to . y + 1 ; if range_y . is_empty ( ) { range_y = ( v . to . y .. v . from . y + 1 ) . rev ( ) ; } coords = range_x . zip ( range_y ) . map ( | ( x , y ) | Coord :: from ( ( x , y ) ) ) . collect ( ) ; } else { println ! ( " " v ) ; } coords }
Expands a Vector v into a list of Coordiates covered by the Vector.
Expands a Vector v into a list of Coordiates covered by the Vector .
v
Vector
v
Vector