Struct sfml::system::Vector2 [] [src]

#[repr(C)]
pub struct Vector2<T> { pub x: T, pub y: T, }

Utility type for manipulating 2-dimensional vectors.

Vector2 is a simple type that defines a mathematical vector with two coordinates (x and y).

It can be used to represent anything that has two dimensions: a size, a point, a velocity, etc.

The type parameter T is the type of the coordinates.

You generally don't have to care about the generic form (Vector2<T>), the most common specializations have special type aliases:

  • Vector2<f32> is Vector2f
  • Vector2<i32> is Vector2i
  • Vector2<u32> is Vector2u

The Vector2 type has a small and simple interface, its x and y members can be accessed directly (there are no accessors like set_x(), get_x()) and it contains no mathematical function like dot product, cross product, length, etc.

Usage example

let mut v1 = Vector2f::new(16.5, 24.0);
v1.x = 18.2;
let y = v1.y;

let v2 = v1 * 5.0;
let v3 = v1 + v2;
assert_ne!(v2, v3);

Note: for 3-dimensional vectors, see Vector3.

Fields

X coordinate of the vector.

Y coordinate of the vector.

Methods

impl<T> Vector2<T>
[src]

[src]

Creates a new vector from its coordinates.

Trait Implementations

impl<T: Clone> Clone for Vector2<T>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: PartialOrd> PartialOrd for Vector2<T>
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T: Ord> Ord for Vector2<T>
[src]

[src]

This method returns an Ordering between self and other. Read more

1.22.0
[src]

Compares and returns the maximum of two values. Read more

1.22.0
[src]

Compares and returns the minimum of two values. Read more

impl<T: PartialEq> PartialEq for Vector2<T>
[src]

[src]

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

[src]

This method tests for !=.

impl<T: Eq> Eq for Vector2<T>
[src]

impl<T: Debug> Debug for Vector2<T>
[src]

[src]

Formats the value using the given formatter.

impl<T: Copy> Copy for Vector2<T>
[src]

impl<T: Default> Default for Vector2<T>
[src]

[src]

Returns the "default value" for a type. Read more

impl<T> From<(T, T)> for Vector2<T>
[src]

[src]

Constructs a Vector2 from (x, y).

impl<T: Add + Copy> Add<T> for Vector2<T>
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl<T: Sub + Copy> Sub<T> for Vector2<T>
[src]

The resulting type after applying the - operator.

[src]

Performs the - operation.

impl<T: Mul + Copy> Mul<T> for Vector2<T>
[src]

The resulting type after applying the * operator.

[src]

Performs the * operation.

impl<T: Div + Copy> Div<T> for Vector2<T>
[src]

The resulting type after applying the / operator.

[src]

Performs the / operation.

impl<T: Add> Add for Vector2<T>
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl<T: AddAssign> AddAssign for Vector2<T>
[src]

[src]

Performs the += operation.

impl<T: Sub> Sub for Vector2<T>
[src]

The resulting type after applying the - operator.

[src]

Performs the - operation.

impl<T: SubAssign> SubAssign for Vector2<T>
[src]

[src]

Performs the -= operation.

impl<T: Mul> Mul for Vector2<T>
[src]

The resulting type after applying the * operator.

[src]

Performs the * operation.

impl<T: MulAssign + Copy> MulAssign<T> for Vector2<T>
[src]

[src]

Performs the *= operation.

impl<T: Div> Div for Vector2<T>
[src]

The resulting type after applying the / operator.

[src]

Performs the / operation.

impl<T: DivAssign + Copy> DivAssign<T> for Vector2<T>
[src]

[src]

Performs the /= operation.

impl<T: Neg<Output = T>> Neg for Vector2<T>
[src]

The resulting type after applying the - operator.

[src]

Performs the unary - operation.