[−][src]Struct bk2d::point::Path
A path, or a vector
Example
let path = bk2d::point::Path::new(2, 1); assert_eq!(path.dx, 2); assert_eq!(path.dy, 1); assert_eq!(path.length(), 3); // 2 + 1
Merge multiple path
let a = bk2d::point::Path::new(2, 1); let b = bk2d::point::Path::new(-3, 2); let c = bk2d::point::Path::new(1, 0); assert_eq!(bk2d::point::Path::merge(&[a, b, c]), bk2d::point::Path::new(0, 3)); assert_eq!(a + b + c, bk2d::point::Path::new(0, 3));
Common direction
assert_eq!(bk2d::point::Path::up(), bk2d::point::Path::new(0, -1)); assert_eq!(bk2d::point::Path::down(), bk2d::point::Path::new(0, 1)); assert_eq!(bk2d::point::Path::left(), bk2d::point::Path::new(-1, 0)); assert_eq!(bk2d::point::Path::right(), bk2d::point::Path::new(1, 0));
Fields
dx: i32
dy: i32
Methods
impl Path
[src]
pub fn new(dx: i32, dy: i32) -> Path
[src]
pub fn up() -> Path
[src]
pub fn down() -> Path
[src]
pub fn left() -> Path
[src]
pub fn right() -> Path
[src]
pub fn merge(paths: &[Path]) -> Path
[src]
Merge multiple path
Example
let a = bk2d::point::Path::new(2, 1); let b = bk2d::point::Path::new(-3, 2); let c = bk2d::point::Path::new(1, 0); assert_eq!(bk2d::point::Path::merge(&[a, b]), bk2d::point::Path::new(-1, 3)); assert_eq!(bk2d::point::Path::merge(&[a, c]), bk2d::point::Path::new(3, 1)); assert_eq!(bk2d::point::Path::merge(&[b, c]), bk2d::point::Path::new(-2, 2)); assert_eq!(bk2d::point::Path::merge(&[a, b, c]), bk2d::point::Path::new(0, 3));
pub fn length(self) -> u32
[src]
Distance of path
Example
assert_eq!(bk2d::point::Path::new(1, 2).length(), 3); assert_eq!(bk2d::point::Path::new(5, -3).length(), 8);
Trait Implementations
impl PartialEq<Path> for Path
[src]
impl Clone for Path
[src]
fn clone(&self) -> Path
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Default for Path
[src]
impl Eq for Path
[src]
impl Copy for Path
[src]
impl Debug for Path
[src]
impl Add<Path> for Point
[src]
type Output = Point
The resulting type after applying the +
operator.
fn add(self, other: Path) -> Point
[src]
Point moves on the path
Example
let a = bk2d::point::Point::new(3, 1); let b = bk2d::point::Path::new(-2, 1); assert_eq!(a + b, bk2d::point::Point::new(1, 2));
impl Add<Path> for Path
[src]
type Output = Path
The resulting type after applying the +
operator.
fn add(self, other: Path) -> Path
[src]
Vector Addition
Example
let a = bk2d::point::Path::new(2, 1); let b = bk2d::point::Path::new(-3, 2); let c = bk2d::point::Path::new(1, 0); assert_eq!(a + b, bk2d::point::Path::new(-1, 3)); assert_eq!(a + c, bk2d::point::Path::new(3, 1)); assert_eq!(b + c, bk2d::point::Path::new(-2, 2)); assert_eq!(a + b + c, bk2d::point::Path::new(0, 3));
impl Sub<Path> for Point
[src]
type Output = Point
The resulting type after applying the -
operator.
fn sub(self, other: Path) -> Point
[src]
Point moves backward on the path
Example
let a = bk2d::point::Point::new(1, 2); let b = bk2d::point::Path::new(-2, 1); assert_eq!(a - b, bk2d::point::Point::new(3, 1));
impl AddAssign<Path> for Point
[src]
fn add_assign(&mut self, other: Path)
[src]
Point moves on the path
Example
let mut a = bk2d::point::Point::new(3, 1); a += bk2d::point::Path::new(-2, 1); assert_eq!(a, bk2d::point::Point::new(1, 2));
impl SubAssign<Path> for Point
[src]
fn sub_assign(&mut self, other: Path)
[src]
Point moves backward on the path
Example
let mut a = bk2d::point::Point::new(1, 2); a -= bk2d::point::Path::new(-2, 1); assert_eq!(a, bk2d::point::Point::new(3, 1));
Auto Trait Implementations
impl Unpin for Path
impl Sync for Path
impl Send for Path
impl RefUnwindSafe for Path
impl UnwindSafe for Path
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,