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: f64The x component.
y: f64The y component.
Implementations§
Source§impl Vector2
impl Vector2
Sourcepub fn set_scalar(&mut self, scalar: f64) -> &mut Self
pub fn set_scalar(&mut self, scalar: f64) -> &mut Self
Vector2.setScalar(): sets both components to scalar.
Sourcepub fn set_component(&mut self, index: usize, value: f64) -> &mut Self
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.
Sourcepub fn get_component(&self, index: usize) -> f64
pub fn get_component(&self, index: usize) -> f64
Vector2.getComponent(): x (index 0) or y (index 1). Panics where
three.js throws.
Sourcepub fn add_scalar(&mut self, s: f64) -> &mut Self
pub fn add_scalar(&mut self, s: f64) -> &mut Self
Vector2.addScalar(): adds s to both components.
Sourcepub fn add_vectors(&mut self, a: &Self, b: &Self) -> &mut Self
pub fn add_vectors(&mut self, a: &Self, b: &Self) -> &mut Self
Vector2.addVectors(): sets this vector to a + b.
Sourcepub fn add_scaled_vector(&mut self, v: &Self, s: f64) -> &mut Self
pub fn add_scaled_vector(&mut self, v: &Self, s: f64) -> &mut Self
Vector2.addScaledVector(): adds v * s to this vector.
Sourcepub fn sub_scalar(&mut self, s: f64) -> &mut Self
pub fn sub_scalar(&mut self, s: f64) -> &mut Self
Vector2.subScalar(): subtracts s from both components.
Sourcepub fn sub_vectors(&mut self, a: &Self, b: &Self) -> &mut Self
pub fn sub_vectors(&mut self, a: &Self, b: &Self) -> &mut Self
Vector2.subVectors(): sets this vector to a - b.
Sourcepub fn multiply_scalar(&mut self, scalar: f64) -> &mut Self
pub fn multiply_scalar(&mut self, scalar: f64) -> &mut Self
Vector2.multiplyScalar().
Sourcepub fn divide_scalar(&mut self, scalar: f64) -> &mut Self
pub fn divide_scalar(&mut self, scalar: f64) -> &mut Self
Vector2.divideScalar().
Sourcepub fn apply_matrix3(&mut self, m: &Matrix3) -> &mut Self
pub fn apply_matrix3(&mut self, m: &Matrix3) -> &mut Self
Vector2.applyMatrix3().
Sourcepub fn min(&mut self, v: &Self) -> &mut Self
pub fn min(&mut self, v: &Self) -> &mut Self
Replaces each component with the smaller of itself and the matching
component of v.
Sourcepub fn max(&mut self, v: &Self) -> &mut Self
pub fn max(&mut self, v: &Self) -> &mut Self
Replaces each component with the larger of itself and the matching
component of v.
Sourcepub fn clamp(&mut self, min: &Self, max: &Self) -> &mut Self
pub fn clamp(&mut self, min: &Self, max: &Self) -> &mut Self
Clamps each component between the matching components of min and
max.
Sourcepub fn clamp_scalar(&mut self, min_val: f64, max_val: f64) -> &mut Self
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.
Sourcepub fn clamp_length(&mut self, min: f64, max: f64) -> &mut Self
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.
Sourcepub fn round(&mut self) -> &mut Self
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.
Sourcepub fn round_to_zero(&mut self) -> &mut Self
pub fn round_to_zero(&mut self) -> &mut Self
Vector2.roundToZero() — Math.trunc.
Sourcepub fn cross(&self, v: &Self) -> f64
pub fn cross(&self, v: &Self) -> f64
Vector2.cross() — the z component of the 3D cross product.
Sourcepub fn length_sq(&self) -> f64
pub fn length_sq(&self) -> f64
Vector2.lengthSq(): the squared Euclidean length, cheaper than
Vector2::length when only comparing lengths.
Sourcepub fn manhattan_length(&self) -> f64
pub fn manhattan_length(&self) -> f64
Vector2.manhattanLength().
Sourcepub fn normalize(&mut self) -> &mut Self
pub fn normalize(&mut self) -> &mut Self
Scales this vector to unit length, or to (0, 0) if its length is 0.
Sourcepub fn angle(&self) -> f64
pub fn angle(&self) -> f64
Vector2.angle() — in the range [0, 2pi), measured counter-clockwise
from the positive x axis.
Sourcepub fn angle_to(&self, v: &Self) -> f64
pub fn angle_to(&self, v: &Self) -> f64
Vector2.angleTo(): the angle in radians between this vector and v.
Sourcepub fn distance_to(&self, v: &Self) -> f64
pub fn distance_to(&self, v: &Self) -> f64
The distance from this vector to v.
Sourcepub fn distance_to_squared(&self, v: &Self) -> f64
pub fn distance_to_squared(&self, v: &Self) -> f64
Vector2.distanceToSquared(): cheaper than Vector2::distance_to
when only comparing distances.
Sourcepub fn manhattan_distance_to(&self, v: &Self) -> f64
pub fn manhattan_distance_to(&self, v: &Self) -> f64
Vector2.manhattanDistanceTo().
Sourcepub fn set_length(&mut self, length: f64) -> &mut Self
pub fn set_length(&mut self, length: f64) -> &mut Self
Vector2.setLength(): rescales this vector to the given length,
preserving its direction.
Sourcepub fn lerp(&mut self, v: &Self, alpha: f64) -> &mut Self
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).
Sourcepub fn lerp_vectors(&mut self, v1: &Self, v2: &Self, alpha: f64) -> &mut Self
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.
Sourcepub fn from_array(&mut self, array: &[f64], offset: usize) -> &mut Self
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].
Sourcepub fn rotate_around(&mut self, center: &Self, angle: f64) -> &mut Self
pub fn rotate_around(&mut self, center: &Self, angle: f64) -> &mut Self
Vector2.rotateAround().
Trait Implementations§
Source§impl BezierVector for Vector2
impl BezierVector for Vector2
Source§const QUADRATIC_TYPE_NAME: &'static str = "QuadraticBezierCurve"
const QUADRATIC_TYPE_NAME: &'static str = "QuadraticBezierCurve"
'QuadraticBezierCurve' / 'QuadraticBezierCurve3'.Source§const CUBIC_TYPE_NAME: &'static str = "CubicBezierCurve"
const CUBIC_TYPE_NAME: &'static str = "CubicBezierCurve"
'CubicBezierCurve' / 'CubicBezierCurve3'.impl Copy for Vector2
Source§impl CurveVector for Vector2
impl CurveVector for Vector2
Source§fn distance_to(&self, v: &Self) -> f64
fn distance_to(&self, v: &Self) -> f64
v.distanceTo( w ).Source§fn tangent(pt1: &Self, pt2: &Self) -> Self
fn tangent(pt1: &Self, pt2: &Self) -> Self
new VectorN().copy( pt2 ).sub( pt1 ).normalize() — Curve.getTangent’s
body.Source§fn to_vector3(&self) -> Vector3
fn to_vector3(&self) -> Vector3
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.