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: Ty: T

Implementations

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));

Returns a new Bounds2D using self as position, and size as the size.

Examples
let bounds = point!(20u32, 30).with_size(size!(50; 2));

assert_eq!(bounds, bounds!(20, 30, 50, 50));

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);

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));

Casts self into a new Vector2D where components are the (usually inferred) input type.

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The resulting type after applying the - operator.

Performs the - operation. Read more

Makes it so that Vector2D itself can be used for interfaces expecting it.

Converts this type into a Vector2D.

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);

Returns the normal of the cross product between self and rhs.

Examples
let a = offset!(0, 0);
let b = offset!(20, 20);

assert_eq!(a.cross(b), 0);

Returns the absolute distance between self and rhs.

Examples
let a = offset!(10, 10);
let b = offset!(0, 0);

assert_eq!(a.distance(b), 20);

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.