Trait BidiView

Source
pub trait BidiView: Index<(usize, usize)> {
Show 15 methods // Required methods fn width(&self) -> usize; fn height(&self) -> usize; fn get(&self, x: usize, y: usize) -> Option<&Self::Output>; // Provided methods fn size(&self) -> (usize, usize) { ... } fn equivalent<V>(&self, other: &V) -> bool where Self: Sized, Self::Output: PartialEq + Sized + Debug, V: BidiView<Output = Self::Output> { ... } fn get_signed(&self, x: isize, y: isize) -> Option<&Self::Output> { ... } fn bounding_rect(&self) -> BidiRect { ... } fn iter(&self) -> Iter<'_, Self::Output, Self> where Self::Output: Sized, Self: Sized { ... } fn to_transposed(self) -> TransposingBidiView<Self> where Self: Sized { ... } fn to_rotated180(self) -> Rotating180BidiView<Self> where Self: Sized { ... } fn to_rotated90ccw(self) -> Rotating90BidiView<Self> where Self: Sized { ... } fn to_rotated270ccw(self) -> Rotating270BidiView<Self> where Self: Sized { ... } fn to_reversed_columns(self) -> ReversingColumnsBidiView<Self> where Self: Sized { ... } fn to_reversed_rows(self) -> ReversingRowsBidiView<Self> where Self: Sized { ... } fn to_cropped( self, rect: &BidiRect, ) -> Result<CroppingBidiView<Self>, BidiError> where Self: Sized { ... }
}
Expand description

An object-safe trait providing a bidimensional view over a data structure.

This trait is used internally to abstract many operations from the underlying data structures, but can be implemented by external types to re-use the algorithms with other bidimensional data structures.

Required Methods§

Source

fn width(&self) -> usize

Returns the width of the bidimensional view

§Examples

let v = bidiarray!{
    [1, 2, 3],
    [4, 5, 6],
};

let r = v.size();

assert_eq!(3, v.width());
assert_eq!(2, v.height());
Source

fn height(&self) -> usize

Returns the height of the bidimensional view

§Examples

let v = bidiarray!{
    [1, 2, 3],
    [4, 5, 6],
};

assert_eq!(3, v.width());
assert_eq!(2, v.height());
Source

fn get(&self, x: usize, y: usize) -> Option<&Self::Output>

Returns the item at (x, y) coordinates, or None if the coordinates are out of range.

§Examples

let a = bidiarray!{
    [1, 2],
    [3, 4],
};

assert_eq!(a.get(0, 0).unwrap(), &1);
assert!(a.get(3, 0).is_none());

Provided Methods§

Source

fn size(&self) -> (usize, usize)

Returns the size of the bidimensional view (i.e. a tuple of (width, height)).

§Examples

let v = bidiarray!{
    [1, 2, 3],
    [4, 5, 6],
};

let r = v.size();

assert_eq!(3, r.0);
assert_eq!(2, r.1);
Source

fn equivalent<V>(&self, other: &V) -> bool
where Self: Sized, Self::Output: PartialEq + Sized + Debug, V: BidiView<Output = Self::Output>,

Returns true if two bidimensional views are equivalent (that is they have the same width, height and equal elements

§Examples

let v = bidivec!{
    [1, 2],
    [3, 4],
};

let a = bidiarray!{
    [1, 2],
    [3, 4],
};

assert!(v.equivalent(&a));
Source

fn get_signed(&self, x: isize, y: isize) -> Option<&Self::Output>

Returns the item at (x, y) coordinates (using signed coordinates), or None if the coordinates are out of range.

§Examples

let a = bidiarray!{
    [1, 2],
    [3, 4],
};

assert_eq!(a.get_signed(0, 0).unwrap(), &1);
assert!(a.get_signed(3, 0).is_none());
assert!(a.get_signed(-1, 0).is_none());
Source

fn bounding_rect(&self) -> BidiRect

Returns the bounding rect of the view

§Examples

let v = bidiarray!{
    [1, 2, 3],
    [4, 5, 6],
};

let r = v.bounding_rect();

assert_eq!(0, r.x);
assert_eq!(0, r.y);
assert_eq!(3, r.width);
assert_eq!(2, r.height);
Source

fn iter(&self) -> Iter<'_, Self::Output, Self>
where Self::Output: Sized, Self: Sized,

Returns an iterator over the items of the view

§Examples

fn get_max<V>(v: &V) -> Option<i32>
where V: BidiView<Output=i32>
{
    v.iter().copied().max()
};

let v = bidiarray!{
    [1, 2, 3],
    [4, 5, 6],
};

assert_eq!(Some(6), get_max(&v));
Source

fn to_transposed(self) -> TransposingBidiView<Self>
where Self: Sized,

Returns a bidiview that represents data in this bidiview as transposed (that is, flipped over its diagonal).

§Examples

let v = bidiarray!{
    [1, 2, 3],
    [4, 5, 6],
};

let v = v.to_transposed();

assert!(v.equivalent(&bidiarray!{
    [1, 4],
    [2, 5],
    [3, 6],
}));
Source

fn to_rotated180(self) -> Rotating180BidiView<Self>
where Self: Sized,

Returns a bidiview that represents data in this bidiview as rotated by 180°.

§Examples

let v = bidiarray!{
    [1, 2, 3],
    [4, 5, 6],
};

let v = v.to_rotated180();

assert!(v.equivalent(&bidiarray!{
    [6, 5, 4],
    [3, 2, 1],
}));
Source

fn to_rotated90ccw(self) -> Rotating90BidiView<Self>
where Self: Sized,

Returns a bidiview that represents data in this bidiview as rotated by 90° counter-clockwise

§Examples

let v = bidiarray!{
    [1, 2, 3],
    [4, 5, 6],
};

let v = v.to_rotated90ccw();

assert!(v.equivalent(&bidiarray!{
    [3, 6],
    [2, 5],
    [1, 4],
}));
Source

fn to_rotated270ccw(self) -> Rotating270BidiView<Self>
where Self: Sized,

Returns a bidiview that represents data in this bidiview as rotated by 270° counter-clockwise

§Examples

let v = bidiarray!{
    [1, 2, 3],
    [4, 5, 6],
};

let v = v.to_rotated270ccw();

assert!(v.equivalent(&bidiarray!{
    [4, 1],
    [5, 2],
    [6, 3],
}));
Source

fn to_reversed_columns(self) -> ReversingColumnsBidiView<Self>
where Self: Sized,

Returns a bidiview that represents data in this bidiview as if its columns were all reversed (as if flipped over an horizontal axis).

§Examples

let v = bidiarray!{
    [1, 2, 3],
    [4, 5, 6],
};

let v = v.to_reversed_columns();

assert!(v.equivalent(&bidiarray!{
    [4, 5, 6],
    [1, 2, 3],
}));
Source

fn to_reversed_rows(self) -> ReversingRowsBidiView<Self>
where Self: Sized,

Returns a bidiview that represents data in this bidiview as if its rows were all reversed (as if flipped over a vertical axis).

§Examples

let v = bidiarray!{
    [1, 2, 3],
    [4, 5, 6],
};

let v = v.to_reversed_rows();

assert!(v.equivalent(&bidiarray!{
    [3, 2, 1],
    [6, 5, 4],
}));
Source

fn to_cropped( self, rect: &BidiRect, ) -> Result<CroppingBidiView<Self>, BidiError>
where Self: Sized,

Returns a bidiview that represents data in this bidiview as if was cropped, by starting at a different origin, and having different height and width.

§Examples

let v = bidiarray!{
    [1, 2, 3],
    [4, 5, 6],
};

let v = v.to_cropped(&BidiRect::new(0, 0, 2, 2))?;

assert!(v.equivalent(&bidiarray!{
    [1, 2],
    [4, 5],
}));

Trait Implementations§

Source§

impl<T> BidiFrom<&dyn BidiView<Output = T>> for BidiArray<T>
where T: Clone,

Source§

fn from_view(source: &dyn BidiView<Output = T>) -> Result<Self, BidiError>

Constructs a new instance of the type implementing this trait using another BidiView as the source of data.
Source§

fn from_view_cut( source: &dyn BidiView<Output = T>, cut: &BidiRect, ) -> Result<Self, BidiError>

Constructs a new instance of the type implementing this trait using the specified region of another BidiView as the source of data.
Source§

impl<T> BidiFrom<&dyn BidiView<Output = T>> for BidiGrowVec<T>
where T: Clone,

Source§

fn from_view(source: &dyn BidiView<Output = T>) -> Result<Self, BidiError>

Constructs a new instance of the type implementing this trait using another BidiView as the source of data.
Source§

fn from_view_cut( source: &dyn BidiView<Output = T>, cut: &BidiRect, ) -> Result<Self, BidiError>

Constructs a new instance of the type implementing this trait using the specified region of another BidiView as the source of data.
Source§

impl<T> BidiFrom<&dyn BidiView<Output = T>> for BidiVec<T>
where T: Clone,

Source§

fn from_view(source: &dyn BidiView<Output = T>) -> Result<Self, BidiError>

Constructs a new instance of the type implementing this trait using another BidiView as the source of data.
Source§

fn from_view_cut( source: &dyn BidiView<Output = T>, cut: &BidiRect, ) -> Result<Self, BidiError>

Constructs a new instance of the type implementing this trait using the specified region of another BidiView as the source of data.

Implementors§