Skip to main content

Vector

Struct Vector 

Source
pub struct Vector {
    pub x: f64,
    pub y: f64,
}
Expand description

Defines a vector.

Fields§

§x: f64

The X component.

§y: f64

The Y component.

Implementations§

Source§

impl Vector

Source

pub const ZERO: Vector

The zero vector.

Source

pub const ONE: Vector

The one vector.

Source

pub const UNIT_X: Vector

The X unit vector.

Source

pub const UNIT_Y: Vector

The Y unit vector.

Source

pub const fn new(x: f64, y: f64) -> Self

Initializes a new instance of the Vector structure.

Source

pub fn parse(s: &str) -> Result<Self, FormatError>

Parses a Vector string ("x, y" or "x y").

Source

pub fn length(&self) -> f64

Length of the vector.

Source

pub fn squared_length(&self) -> f64

Squared length of the vector.

Source

pub fn equals(&self, other: Vector) -> bool

Check if two vectors are equal (exact comparison of the components).

Source

pub fn nearly_equals(&self, other: Vector) -> bool

Check if two vectors are nearly equal (numerically).

Source

pub const fn with_x(&self, x: f64) -> Vector

Returns a new vector with the specified X component.

Source

pub const fn with_y(&self, y: f64) -> Vector

Returns a new vector with the specified Y component.

Source

pub fn normalize(&self) -> Vector

Returns a normalized version of this vector. A zero-length vector yields NaN components.

Source

pub fn negate(&self) -> Vector

Returns a negated version of this vector.

Source

pub fn dot(a: Vector, b: Vector) -> f64

Returns the dot product of two vectors.

Source

pub fn cross(a: Vector, b: Vector) -> f64

Returns the cross product of two vectors.

Source

pub fn normalize_vector(vector: Vector) -> Vector

Normalizes the given vector (static form of normalize).

Source

pub fn divide(a: Vector, b: Vector) -> Vector

Divides the first vector by the second, component-wise.

Source

pub fn divide_scalar(vector: Vector, scalar: f64) -> Vector

Divides the vector by the given scalar.

Source

pub fn multiply(a: Vector, b: Vector) -> Vector

Multiplies the first vector by the second, component-wise.

Source

pub fn multiply_scalar(vector: Vector, scalar: f64) -> Vector

Multiplies the vector by the given scalar.

Source

pub fn add(a: Vector, b: Vector) -> Vector

Adds the second to the first vector.

Source

pub fn subtract(a: Vector, b: Vector) -> Vector

Subtracts the second from the first vector.

Source

pub fn negate_vector(vector: Vector) -> Vector

Negates the vector (static form of negate).

Source

pub const fn deconstruct(&self) -> (f64, f64)

Deconstructs the vector into its X and Y components.

Source

pub fn abs(&self) -> Vector

Returns a vector whose elements are the absolute values of each of the specified vector’s elements.

Source

pub fn clamp(value: Vector, min: Vector, max: Vector) -> Vector

Restricts a vector between a minimum and a maximum value.

Source

pub fn max(left: Vector, right: Vector) -> Vector

Returns a vector whose elements are the maximum of each of the pairs of elements in two specified vectors.

Source

pub fn min(left: Vector, right: Vector) -> Vector

Returns a vector whose elements are the minimum of each of the pairs of elements in two specified vectors.

Source

pub fn distance(value1: Vector, value2: Vector) -> f64

Computes the Euclidean distance between the two given points.

Source

pub fn distance_squared(value1: Vector, value2: Vector) -> f64

Returns the Euclidean distance squared between two specified points.

Trait Implementations§

Source§

impl Add for Vector

Source§

type Output = Vector

The resulting type after applying the + operator.
Source§

fn add(self, b: Vector) -> Vector

Performs the + operation. Read more
Source§

impl Add<Vector> for Point

Source§

type Output = Point

The resulting type after applying the + operator.
Source§

fn add(self, b: Vector) -> Point

Performs the + operation. Read more
Source§

impl AddAssign for Vector

Source§

fn add_assign(&mut self, b: Vector)

Performs the += operation. Read more
Source§

impl AddAssign<Vector> for Point

Source§

fn add_assign(&mut self, b: Vector)

Performs the += operation. Read more
Source§

impl BatchValue for Vector

Source§

fn write_to(&self, out: &mut Vec<u8>)

Source§

fn read_from(input: &mut BatchValueReader<'_>) -> Self

Source§

impl Clone for Vector

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Vector

Source§

impl Debug for Vector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Vector

Source§

fn default() -> Self

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

impl Display for Vector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<Vector> for Rect

Divides a rectangle by a vector.

Source§

type Output = Rect

The resulting type after applying the / operator.
Source§

fn div(self, scale: Vector) -> Rect

Performs the / operation. Read more
Source§

impl Div<Vector> for Size

Scales a size.

Source§

type Output = Size

The resulting type after applying the / operator.
Source§

fn div(self, scale: Vector) -> Size

Performs the / operation. Read more
Source§

impl Div<f64> for Vector

Source§

type Output = Vector

The resulting type after applying the / operator.
Source§

fn div(self, scale: f64) -> Vector

Performs the / operation. Read more
Source§

impl DivAssign<Vector> for Rect

Source§

fn div_assign(&mut self, scale: Vector)

Performs the /= operation. Read more
Source§

impl DivAssign<Vector> for Size

Source§

fn div_assign(&mut self, scale: Vector)

Performs the /= operation. Read more
Source§

impl DivAssign<f64> for Vector

Source§

fn div_assign(&mut self, scale: f64)

Performs the /= operation. Read more
Source§

impl ExpressionVariantValue for Vector

Source§

const FFI_VARIANT_TYPE: Option<VariantType>

The variant type a foreign function parameter of this type is matched against, or None when the type cannot be a foreign function parameter.
Source§

fn try_from_variant(v: &ExpressionVariant) -> Option<Self>

Source§

fn into_variant(self) -> ExpressionVariant

Source§

impl From<Point> for Vector

Converts the Point to a Vector.

Source§

fn from(p: Point) -> Vector

Converts to this type from the input type.
Source§

impl From<Vector2> for Vector

The widening conversion to the double-precision vector.

Source§

fn from(value: Vector2) -> Vector

Converts to this type from the input type.
Source§

impl From<Vector> for Vector2

The narrowing conversion of the double-precision vector.

Source§

fn from(value: Vector) -> Vector2

Converts to this type from the input type.
Source§

impl From<Vector> for ExpressionVariant

Source§

fn from(value: Vector) -> ExpressionVariant

Converts to this type from the input type.
Source§

impl From<Vector> for Point

Converts the Vector to a Point (an explicit conversion in the reference API).

Source§

fn from(a: Vector) -> Point

Converts to this type from the input type.
Source§

impl From<Vector> for (f64, f64)

Source§

fn from(v: Vector) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Vector

Source§

type Err = FormatError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, FormatError>

Parses a string s to return a value of this type. Read more
Source§

impl IInterpolator<Vector> for VectorInterpolator

Source§

fn interpolate(&self, from: Vector, to: Vector, progress: f32) -> Vector

Source§

impl MarkupTyped for Vector

Source§

const MARKUP: &'static MarkupType

The markup metadata of the type.
Source§

impl Mul for Vector

Calculates the dot product of two vectors.

Source§

type Output = f64

The resulting type after applying the * operator.
Source§

fn mul(self, b: Vector) -> f64

Performs the * operation. Read more
Source§

impl Mul<Vector> for Rect

Multiplies a rectangle by a scaling vector.

Source§

type Output = Rect

The resulting type after applying the * operator.
Source§

fn mul(self, scale: Vector) -> Rect

Performs the * operation. Read more
Source§

impl Mul<Vector> for Size

Scales a size.

Source§

type Output = Size

The resulting type after applying the * operator.
Source§

fn mul(self, scale: Vector) -> Size

Performs the * operation. Read more
Source§

impl Mul<Vector> for f64

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, vector: Vector) -> Vector

Performs the * operation. Read more
Source§

impl Mul<f64> for Vector

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, scale: f64) -> Vector

Performs the * operation. Read more
Source§

impl MulAssign<Vector> for Rect

Source§

fn mul_assign(&mut self, scale: Vector)

Performs the *= operation. Read more
Source§

impl MulAssign<Vector> for Size

Source§

fn mul_assign(&mut self, scale: Vector)

Performs the *= operation. Read more
Source§

impl MulAssign<f64> for Vector

Source§

fn mul_assign(&mut self, scale: f64)

Performs the *= operation. Read more
Source§

impl Neg for Vector

Source§

type Output = Vector

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vector

Performs the unary - operation. Read more
Source§

impl PartialEq for Vector

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl ServerPropertyValue for Vector

Source§

fn differs(&self, other: &Self) -> bool

Source§

fn default_equals(&self, other: &Self) -> bool

Source§

impl StructuralPartialEq for Vector

Source§

impl Sub for Vector

Source§

type Output = Vector

The resulting type after applying the - operator.
Source§

fn sub(self, b: Vector) -> Vector

Performs the - operation. Read more
Source§

impl Sub<Vector> for Point

Source§

type Output = Point

The resulting type after applying the - operator.
Source§

fn sub(self, b: Vector) -> Point

Performs the - operation. Read more
Source§

impl SubAssign for Vector

Source§

fn sub_assign(&mut self, b: Vector)

Performs the -= operation. Read more
Source§

impl SubAssign<Vector> for Point

Source§

fn sub_assign(&mut self, b: Vector)

Performs the -= operation. Read more
Source§

impl Transition<Vector> for VectorTransition

Source§

fn do_transition( this: &Self, progress: Rc<dyn IObservable<f64>>, old_value: Vector, new_value: Vector, ) -> Rc<dyn IObservable<Vector>>

Creates the observable of the values of the transition from old_value to new_value, driven by progress (from 0 to 1).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyValue for T
where T: PartialEq + 'static,

Source§

fn any_value_as_any(&self) -> &(dyn Any + 'static)

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> PropertyValue for T
where T: Clone + PartialEq + 'static,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.