pub struct Offset {
pub col_offset: i32,
pub row_offset: i32,
}Expand description
A two-dimensional offset vector used to relate grid elements spatially.
Fields§
§col_offset: i32§row_offset: i32Implementations§
Source§impl Offset
impl Offset
Sourcepub fn cardinal_sum(n: i32, e: i32, s: i32, w: i32) -> Self
pub fn cardinal_sum(n: i32, e: i32, s: i32, w: i32) -> Self
Create a new Offset from the sum of cardinal vectors.
§Examples
use gridd::Offset;
assert_eq!(
Offset::cardinal_sum(1, 0, -1, 0),
Offset::NORTH - Offset::SOUTH
);
assert_eq!(
Offset::cardinal_sum(0, 2, 0, 3),
2 * Offset::EAST + 3 * Offset::WEST
);Sourcepub fn rcoord(&self, (col, row): Coord) -> Option<Coord>
pub fn rcoord(&self, (col, row): Coord) -> Option<Coord>
Get the coordinate pointed to by an Offset from a given Coord.
Returns None when either Coord component would be negative.
§Examples
use gridd::{Coord, Offset};
let coord: Coord = (3, 5);
let v1 = Offset::from((-3, 2));
assert_eq!(Some((0, 7)), v1.rcoord(coord));
let v2 = Offset::from((-4, 5));
assert_eq!(None, v2.rcoord(coord));Trait Implementations§
Source§impl Ord for Offset
impl Ord for Offset
Source§impl PartialOrd for Offset
impl PartialOrd for Offset
impl Copy for Offset
impl Eq for Offset
impl StructuralPartialEq for Offset
Auto Trait Implementations§
impl Freeze for Offset
impl RefUnwindSafe for Offset
impl Send for Offset
impl Sync for Offset
impl Unpin for Offset
impl UnwindSafe for Offset
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more