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§
Sourcefn width(&self) -> usize
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());
Provided Methods§
Sourcefn size(&self) -> (usize, usize)
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);
Sourcefn equivalent<V>(&self, other: &V) -> bool
fn equivalent<V>(&self, other: &V) -> bool
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));
Sourcefn bounding_rect(&self) -> BidiRect
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);
Sourcefn iter(&self) -> Iter<'_, Self::Output, Self> ⓘ
fn iter(&self) -> Iter<'_, Self::Output, Self> ⓘ
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));
Sourcefn to_transposed(self) -> TransposingBidiView<Self>where
Self: Sized,
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],
}));
Sourcefn to_rotated180(self) -> Rotating180BidiView<Self>where
Self: Sized,
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],
}));
Sourcefn to_rotated90ccw(self) -> Rotating90BidiView<Self>where
Self: Sized,
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],
}));
Sourcefn to_rotated270ccw(self) -> Rotating270BidiView<Self>where
Self: Sized,
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],
}));
Sourcefn to_reversed_columns(self) -> ReversingColumnsBidiView<Self>where
Self: Sized,
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],
}));
Sourcefn to_reversed_rows(self) -> ReversingRowsBidiView<Self>where
Self: Sized,
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],
}));
Sourcefn to_cropped(
self,
rect: &BidiRect,
) -> Result<CroppingBidiView<Self>, BidiError>where
Self: Sized,
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],
}));