pub struct Vector2D<T, Kind> {
pub x: T,
pub y: T,
/* private fields */
}
Expand description
A generic vector with an X and Y component.
Fields
x: T
y: T
Implementations
sourceimpl<T> Vector2D<T, Point>
impl<T> Vector2D<T, Point>
sourcepub fn offset<P: ToPoint2D<T>>(self, point: P) -> Offset2D<T> where
T: Sub<Output = T>,
pub fn offset<P: ToPoint2D<T>>(self, point: P) -> Offset2D<T> where
T: Sub<Output = T>,
Returns the offset between self
and point
.
Order matters here, so if you are trying to get the offset
needed for point A to get to point B, you would do a.offset(b)
.
Examples
let a = point!(10, 40);
let b = point!(5, 60);
assert_eq!(a.offset(b), offset!(-5, 20));
sourceimpl<T, K> Vector2D<T, K>
impl<T, K> Vector2D<T, K>
sourcepub fn new(x: T, y: T) -> Self
pub fn new(x: T, y: T) -> Self
Returns a new Vector2D with x
and y
components.
In most cases you should not call this directly, but rather use the macros to get the specialized variants.
Examples
// Avoid doing this
let point: Vector2D<_, Point> = Vector2D::new(20, 40);
// This is better, but not great
let point: Point2D<_> = Vector2D::new(20, 40);
// This is acceptable, but...
let point = Point2D::new(20, 40);
// ...this is the preferred way
let point = point!(20, 40);
sourcepub fn splat(value: T) -> Self where
T: Copy,
pub fn splat(value: T) -> Self where
T: Copy,
Returns a new Vector2D where both components are set to value
.
Prefer using the splat syntax with the specialized macros instead of calling this directly.
Examples
// This is acceptable, but...
let offset = Offset2D::splat(5);
// ...this is the preferred way
let offset = offset!(5; 2);
assert_eq!(offset, offset!(5, 5));
Trait Implementations
sourceimpl<T, K> ToVector2D<T, K> for Vector2D<T, K>
impl<T, K> ToVector2D<T, K> for Vector2D<T, K>
Makes it so that Vector2D
itself can be used for interfaces expecting it.
sourceimpl<T, K, ToVector> Vector<T, ToVector> for Vector2D<T, K> where
ToVector: ToVector2D<T, K>,
impl<T, K, ToVector> Vector<T, ToVector> for Vector2D<T, K> where
ToVector: ToVector2D<T, K>,
sourcefn dot(&self, rhs: ToVector) -> T where
T: Copy + Mul<Output = T> + Add<Output = T>,
fn dot(&self, rhs: ToVector) -> T where
T: Copy + Mul<Output = T> + Add<Output = T>,
Returns the dot product of self
and rhs
.
Examples
let a = offset!(5, 10);
let b = offset!(10, 5);
assert_eq!(a.dot(b), 100);
impl<T: Copy, Kind: Copy> Copy for Vector2D<T, Kind>
impl<T, Kind> StructuralPartialEq for Vector2D<T, Kind>
Auto Trait Implementations
impl<T, Kind> RefUnwindSafe for Vector2D<T, Kind> where
Kind: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, Kind> Send for Vector2D<T, Kind> where
Kind: Send,
T: Send,
impl<T, Kind> Sync for Vector2D<T, Kind> where
Kind: Sync,
T: Sync,
impl<T, Kind> Unpin for Vector2D<T, Kind> where
Kind: Unpin,
T: Unpin,
impl<T, Kind> UnwindSafe for Vector2D<T, Kind> where
Kind: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more