Skip to main content

Vector2

Struct Vector2 

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

three.js’ Vector2: an ordered pair of numbers, used for 2D points, directions, and any other pair of related values.

Fields§

§x: f64

The x component.

§y: f64

The y component.

Implementations§

Source§

impl Vector2

Source

pub const ZERO: Self

The zero vector.

Source

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

Constructs a new vector with the given components.

Source

pub fn width(&self) -> f64

Vector2.width — the alias Vector2 exposes for x.

Source

pub fn height(&self) -> f64

Vector2.height — the alias Vector2 exposes for y.

Source

pub fn set(&mut self, x: f64, y: f64) -> &mut Self

Sets the vector’s components.

Source

pub fn set_scalar(&mut self, scalar: f64) -> &mut Self

Vector2.setScalar(): sets both components to scalar.

Source

pub fn set_x(&mut self, x: f64) -> &mut Self

Vector2.setX().

Source

pub fn set_y(&mut self, y: f64) -> &mut Self

Vector2.setY().

Source

pub fn set_component(&mut self, index: usize, value: f64) -> &mut Self

Vector2.setComponent(): sets x (index 0) or y (index 1). Panics where three.js throws.

Source

pub fn get_component(&self, index: usize) -> f64

Vector2.getComponent(): x (index 0) or y (index 1). Panics where three.js throws.

Source

pub fn copy(&mut self, v: &Self) -> &mut Self

Copies the components of v into this vector.

Source

pub fn add(&mut self, v: &Self) -> &mut Self

Adds v to this vector.

Source

pub fn add_scalar(&mut self, s: f64) -> &mut Self

Vector2.addScalar(): adds s to both components.

Source

pub fn add_vectors(&mut self, a: &Self, b: &Self) -> &mut Self

Vector2.addVectors(): sets this vector to a + b.

Source

pub fn add_scaled_vector(&mut self, v: &Self, s: f64) -> &mut Self

Vector2.addScaledVector(): adds v * s to this vector.

Source

pub fn sub(&mut self, v: &Self) -> &mut Self

Subtracts v from this vector.

Source

pub fn sub_scalar(&mut self, s: f64) -> &mut Self

Vector2.subScalar(): subtracts s from both components.

Source

pub fn sub_vectors(&mut self, a: &Self, b: &Self) -> &mut Self

Vector2.subVectors(): sets this vector to a - b.

Source

pub fn multiply(&mut self, v: &Self) -> &mut Self

Multiplies this vector by v, component-wise.

Source

pub fn multiply_scalar(&mut self, scalar: f64) -> &mut Self

Vector2.multiplyScalar().

Source

pub fn divide(&mut self, v: &Self) -> &mut Self

Divides this vector by v, component-wise.

Source

pub fn divide_scalar(&mut self, scalar: f64) -> &mut Self

Vector2.divideScalar().

Source

pub fn apply_matrix3(&mut self, m: &Matrix3) -> &mut Self

Vector2.applyMatrix3().

Source

pub fn min(&mut self, v: &Self) -> &mut Self

Replaces each component with the smaller of itself and the matching component of v.

Source

pub fn max(&mut self, v: &Self) -> &mut Self

Replaces each component with the larger of itself and the matching component of v.

Source

pub fn clamp(&mut self, min: &Self, max: &Self) -> &mut Self

Clamps each component between the matching components of min and max.

Source

pub fn clamp_scalar(&mut self, min_val: f64, max_val: f64) -> &mut Self

Vector2.clampScalar(): clamps each component between min_val and max_val.

Source

pub fn clamp_length(&mut self, min: f64, max: f64) -> &mut Self

Vector2.clampLength(): clamps this vector’s length between min and max, preserving its direction.

Source

pub fn floor(&mut self) -> &mut Self

Rounds each component down to the nearest integer.

Source

pub fn ceil(&mut self) -> &mut Self

Rounds each component up to the nearest integer.

Source

pub fn round(&mut self) -> &mut Self

Vector2.round() — Math.round, which rounds half up (toward +Infinity), not half away from zero the way Rust’s f64::round does.

Source

pub fn round_to_zero(&mut self) -> &mut Self

Vector2.roundToZero() — Math.trunc.

Source

pub fn negate(&mut self) -> &mut Self

Negates both components.

Source

pub fn dot(&self, v: &Self) -> f64

The dot product of this vector and v.

Source

pub fn cross(&self, v: &Self) -> f64

Vector2.cross() — the z component of the 3D cross product.

Source

pub fn length_sq(&self) -> f64

Vector2.lengthSq(): the squared Euclidean length, cheaper than Vector2::length when only comparing lengths.

Source

pub fn length(&self) -> f64

The Euclidean length (distance from (0, 0) to (x, y)).

Source

pub fn manhattan_length(&self) -> f64

Vector2.manhattanLength().

Source

pub fn normalize(&mut self) -> &mut Self

Scales this vector to unit length, or to (0, 0) if its length is 0.

Source

pub fn angle(&self) -> f64

Vector2.angle() — in the range [0, 2pi), measured counter-clockwise from the positive x axis.

Source

pub fn angle_to(&self, v: &Self) -> f64

Vector2.angleTo(): the angle in radians between this vector and v.

Source

pub fn distance_to(&self, v: &Self) -> f64

The distance from this vector to v.

Source

pub fn distance_to_squared(&self, v: &Self) -> f64

Vector2.distanceToSquared(): cheaper than Vector2::distance_to when only comparing distances.

Source

pub fn manhattan_distance_to(&self, v: &Self) -> f64

Vector2.manhattanDistanceTo().

Source

pub fn set_length(&mut self, length: f64) -> &mut Self

Vector2.setLength(): rescales this vector to the given length, preserving its direction.

Source

pub fn lerp(&mut self, v: &Self, alpha: f64) -> &mut Self

Linearly interpolates from this vector toward v, where alpha is the distance along the line (0 stays at this vector, 1 reaches v).

Source

pub fn lerp_vectors(&mut self, v1: &Self, v2: &Self, alpha: f64) -> &mut Self

Vector2.lerpVectors(): sets this vector to the linear interpolation from v1 to v2 at alpha.

Source

pub fn equals(&self, v: &Self) -> bool

Whether this vector’s components equal v’s.

Source

pub fn from_array(&mut self, array: &[f64], offset: usize) -> &mut Self

Vector2.fromArray(): reads x from array[offset] and y from array[offset + 1].

Source

pub fn to_array(&self) -> [f64; 2]

Vector2.toArray(): [x, y].

Source

pub fn rotate_around(&mut self, center: &Self, angle: f64) -> &mut Self

Vector2.rotateAround().

Trait Implementations§

Source§

impl BezierVector for Vector2

Source§

const QUADRATIC_TYPE_NAME: &'static str = "QuadraticBezierCurve"

'QuadraticBezierCurve' / 'QuadraticBezierCurve3'.
Source§

const CUBIC_TYPE_NAME: &'static str = "CubicBezierCurve"

'CubicBezierCurve' / 'CubicBezierCurve3'.
Source§

fn map_components(points: &[&Self], f: impl Fn(&[f64]) -> f64) -> Self

point.set( f( v0.x, ... ), f( v0.y, ... )[, f( v0.z, ... )] ).
Source§

impl Clone for Vector2

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 Vector2

Source§

impl CurveVector for Vector2

Source§

fn distance_to(&self, v: &Self) -> f64

v.distanceTo( w ).
Source§

fn equals(&self, v: &Self) -> bool

v.equals( w ).
Source§

fn tangent(pt1: &Self, pt2: &Self) -> Self

new VectorN().copy( pt2 ).sub( pt1 ).normalize() — Curve.getTangent’s body.
Source§

fn to_vector3(&self) -> Vector3

The point as a Vector3, z = 0 for a Vector2. Only Curve::compute_frenet_frames uses it; three.js copies a Vector2 tangent into a Vector3 there, which leaves z undefined (NaN downstream), so frames of a 2D curve are meaningless in three.js and merely planar here.
Source§

impl Debug for Vector2

Source§

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

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

impl Default for Vector2

Source§

fn default() -> Self

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

impl From<Vector2> for NodeRef

Source§

fn from(v: Vector2) -> Self

Converts to this type from the input type.
Source§

impl LineVector for Vector2

Source§

const TYPE_NAME: &'static str = "LineCurve"

'LineCurve' or 'LineCurve3'.
Source§

fn lerp_line(v1: &Self, v2: &Self, t: f64) -> Self

point.copy( v2 ).sub( v1 ); point.multiplyScalar( t ).add( v1 ).
Source§

fn direction(v1: &Self, v2: &Self) -> Self

optionalTarget.subVectors( v2, v1 ).normalize().
Source§

impl PartialEq for Vector2

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 StructuralPartialEq for Vector2

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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, 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.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,