#[repr(C, packed(1))]pub struct Vector2 {
pub x: f32,
pub y: f32,
}
Fields§
§x: f32
§y: f32
Implementations§
Source§impl Vector2
impl Vector2
Sourcepub fn new() -> Vector2
pub fn new() -> Vector2
Creates a vector <0.0, 0.0>
§Examples
use vex::Vector2;
let actual = Vector2::new();
let expected = Vector2 { x: 0.0, y: 0.0 };
assert_eq!(actual, expected);
Sourcepub fn one() -> Vector2
pub fn one() -> Vector2
Creates a vector <1.0, 1.0>
§Examples
use vex::Vector2;
let actual = Vector2::one();
let expected = Vector2 { x: 1.0, y: 1.0 };
assert_eq!(actual, expected);
Sourcepub fn make(x: f32, y: f32) -> Vector2
pub fn make(x: f32, y: f32) -> Vector2
Creates a vector from the provided values
§Examples
use vex::Vector2;
let actual = Vector2::make(1.0, 2.0);
let expected = Vector2 { x: 1.0, y: 2.0 };
assert_eq!(actual, expected);
Sourcepub fn dot(a: &Vector2, b: &Vector2) -> f32
pub fn dot(a: &Vector2, b: &Vector2) -> f32
Find the dot product between two vectors
§Examples
use vex::Vector2;
let a = Vector2::make(1.0, 0.0);
let b = Vector2::make(0.0, 1.0);
let actual = Vector2::dot(&a, &b);
let expected = 0.0;
assert_eq!(actual, expected);
Sourcepub fn cross(a: &Vector2, b: &Vector2) -> f32
pub fn cross(a: &Vector2, b: &Vector2) -> f32
Find the cross product between two vectors
§Examples
use vex::Vector2;
let a = Vector2::make(1.0, 0.0);
let b = Vector2::make(0.0, 1.0);
let actual = Vector2::cross(&a, &b);
let expected = 1.0;
assert_eq!(actual, expected);
Sourcepub fn cross_scalar_vec(s: f32, v: &Vector2) -> Vector2
pub fn cross_scalar_vec(s: f32, v: &Vector2) -> Vector2
Find the cross product between a scalar (left) and vector (right)
§Examples
use vex::Vector2;
let s = 1.0;
let v = Vector2::make(1.0, 0.0);
let actual = Vector2::cross_scalar_vec(s, &v);
let expected = Vector2::make(0.0, 1.0);
assert_eq!(actual, expected);
Sourcepub fn cross_vec_scalar(v: &Vector2, s: f32) -> Vector2
pub fn cross_vec_scalar(v: &Vector2, s: f32) -> Vector2
Find the cross product between a vector (left) and scalar (right)
§Examples
use vex::Vector2;
let s = 1.0;
let v = Vector2::make(1.0, 0.0);
let actual = Vector2::cross_vec_scalar(&v, s);
let expected = Vector2::make(0.0, -1.0);
assert_eq!(actual, expected);
Sourcepub fn min(a: &Vector2, b: &Vector2) -> Vector2
pub fn min(a: &Vector2, b: &Vector2) -> Vector2
Find the minimum (component-wise) vector between two vectors
§Examples
use vex::Vector2;
let a = Vector2::make(1.0, 4.0);
let b = Vector2::make(2.0, 3.0);
let actual = Vector2::min(&a, &b);
let expected = Vector2::make(1.0, 3.0);
assert_eq!(actual, expected);
Sourcepub fn max(a: &Vector2, b: &Vector2) -> Vector2
pub fn max(a: &Vector2, b: &Vector2) -> Vector2
Find the maximum (component-wise) vector between two vectors
§Examples
use vex::Vector2;
let a = Vector2::make(1.0, 4.0);
let b = Vector2::make(2.0, 3.0);
let actual = Vector2::max(&a, &b);
let expected = Vector2::make(2.0, 4.0);
assert_eq!(actual, expected);
Sourcepub fn clamp(&mut self, a: &Vector2, b: &Vector2)
pub fn clamp(&mut self, a: &Vector2, b: &Vector2)
Find the clamped (component-wise) vector between two vectors
§Examples
use vex::Vector2;
let a = Vector2::make(1.0, 3.0);
let b = Vector2::make(2.0, 4.0);
let mut actual = Vector2::make(0.0, 5.0);
actual.clamp(&a, &b);
let expected = Vector2::make(1.0, 4.0);
assert_eq!(actual, expected);
Sourcepub fn set(&mut self, x: f32, y: f32)
pub fn set(&mut self, x: f32, y: f32)
Set the components of a vector
§Examples
use vex::Vector2;
let mut actual = Vector2::new();
actual.set(1.0, 2.0);
let expected = Vector2::make(1.0, 2.0);
assert_eq!(actual, expected);
Sourcepub fn mag(&self) -> f32
pub fn mag(&self) -> f32
Get the magnitude of the vector
§Examples
use vex::Vector2;
let actual = Vector2::make(1.0, 2.0).mag();
let expected = 2.2360679775;
assert_eq!(actual, expected);
Sourcepub fn mag_sq(&self) -> f32
pub fn mag_sq(&self) -> f32
Get the squared magnitude of the vector
§Examples
use vex::Vector2;
let actual = Vector2::make(1.0, 2.0).mag_sq();
let expected = 5.0;
assert_eq!(actual, expected);
Sourcepub fn norm(&mut self) -> f32
pub fn norm(&mut self) -> f32
Normalize the vector
§Examples
use vex::Vector2;
let mut actual = Vector2::make(1.0, 2.0);
actual.norm();
let expected = Vector2::make(0.4472135955, 0.894427191);
assert_eq!(actual, expected);
Sourcepub fn abs(&mut self)
pub fn abs(&mut self)
Set the components of a vector to their absolute values
§Examples
use vex::Vector2;
let mut actual = Vector2::make(-1.0, -2.0);
actual.abs();
let expected = Vector2::make(1.0, 2.0);
assert_eq!(actual, expected);
Trait Implementations§
Source§impl Add<f32> for Vector2
impl Add<f32> for Vector2
Source§impl Add for Vector2
impl Add for Vector2
Source§impl AddAssign<f32> for Vector2
impl AddAssign<f32> for Vector2
Source§fn add_assign(&mut self, _rhs: f32)
fn add_assign(&mut self, _rhs: f32)
Increment a vector by a scalar
§Examples
use vex::Vector2;
let mut actual = Vector2::make(1.0, 2.0);
actual += 10.0;
let expected = Vector2::make(11.0, 12.0);
assert_eq!(actual, expected);
Source§impl AddAssign for Vector2
impl AddAssign for Vector2
Source§fn add_assign(&mut self, _rhs: Vector2)
fn add_assign(&mut self, _rhs: Vector2)
Increment a vector by another vector
§Examples
use vex::Vector2;
let mut actual = Vector2::make(1.0, 2.0);
actual += Vector2::make(1.0, 2.0);
let expected = Vector2::make(2.0, 4.0);
assert_eq!(actual, expected);
Source§impl Div<f32> for Vector2
impl Div<f32> for Vector2
Source§impl Div for Vector2
impl Div for Vector2
Source§impl DivAssign<f32> for Vector2
impl DivAssign<f32> for Vector2
Source§fn div_assign(&mut self, _rhs: f32)
fn div_assign(&mut self, _rhs: f32)
Divide a vector by a scalar
§Examples
use vex::Vector2;
let mut actual = Vector2::make(1.0, 2.0);
actual /= 2.0;
let expected = Vector2::make(0.5, 1.0);
assert_eq!(actual, expected);
Source§impl DivAssign for Vector2
impl DivAssign for Vector2
Source§fn div_assign(&mut self, _rhs: Vector2)
fn div_assign(&mut self, _rhs: Vector2)
Divide a vector by another vector
§Examples
use vex::Vector2;
let mut actual = Vector2::make(1.0, 2.0);
actual /= Vector2::make(2.0, 8.0);
let expected = Vector2::make(0.5, 0.25);
assert_eq!(actual, expected);
Source§impl Matrix<Vector2> for Matrix2
impl Matrix<Vector2> for Matrix2
Source§fn transform_point(&self, point: &Vector2) -> Vector2
fn transform_point(&self, point: &Vector2) -> Vector2
Find the resulting vector given a vector and matrix
§Examples
use vex::Matrix;
use vex::Matrix2;
use vex::Vector2;
let m = Matrix2::make(1.0, 2.0, 3.0, 4.0);
let v = Vector2::make(1.0, 2.0);
let actual = m.transform_point(&v);
let expected = Vector2::make(7.0, 10.0);
assert_eq!(actual, expected);
Source§impl Matrix<Vector2> for Matrix3
impl Matrix<Vector2> for Matrix3
Source§fn transform_point(&self, point: &Vector2) -> Vector2
fn transform_point(&self, point: &Vector2) -> Vector2
Find the resulting vector given a vector and matrix
§Examples
use vex::Matrix;
use vex::Matrix3;
use vex::Vector2;
let m = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
let v = Vector2::make(1.0, 2.0);
let actual = m.transform_point(&v);
let expected = Vector2::make(16.0, 20.0);
assert_eq!(actual, expected);
Source§impl Mul<f32> for Vector2
impl Mul<f32> for Vector2
Source§impl Mul for Vector2
impl Mul for Vector2
Source§impl MulAssign<f32> for Vector2
impl MulAssign<f32> for Vector2
Source§fn mul_assign(&mut self, _rhs: f32)
fn mul_assign(&mut self, _rhs: f32)
Multiply a vector by a scalar
§Examples
use vex::Vector2;
let mut actual = Vector2::make(1.0, 2.0);
actual *= 2.0;
let expected = Vector2::make(2.0, 4.0);
assert_eq!(actual, expected);
Source§impl MulAssign for Vector2
impl MulAssign for Vector2
Source§fn mul_assign(&mut self, _rhs: Vector2)
fn mul_assign(&mut self, _rhs: Vector2)
Multiply a vector by another vector
§Examples
use vex::Vector2;
let mut actual = Vector2::make(1.0, 2.0);
actual *= Vector2::make(2.0, 3.0);
let expected = Vector2::make(2.0, 6.0);
assert_eq!(actual, expected);
Source§impl PartialEq for Vector2
impl PartialEq for Vector2
Source§impl Sub<f32> for Vector2
impl Sub<f32> for Vector2
Source§impl Sub for Vector2
impl Sub for Vector2
Source§impl SubAssign<f32> for Vector2
impl SubAssign<f32> for Vector2
Source§fn sub_assign(&mut self, _rhs: f32)
fn sub_assign(&mut self, _rhs: f32)
Decrement a vector by a scalar
§Examples
use vex::Vector2;
let mut actual = Vector2::make(1.0, 2.0);
actual -= 1.0;
let expected = Vector2::make(0.0, 1.0);
assert_eq!(actual, expected);
Source§impl SubAssign for Vector2
impl SubAssign for Vector2
Source§fn sub_assign(&mut self, _rhs: Vector2)
fn sub_assign(&mut self, _rhs: Vector2)
Decrement a vector by another vector
§Examples
use vex::Vector2;
let mut actual = Vector2::make(1.0, 2.0);
actual -= Vector2::make(1.0, 2.0);
assert_eq!(actual, Vector2::new());