[][src]Struct nannou::geom::vector::Vector2

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

A 2-dimensional vector.

Fields

x: Sy: S

Methods

impl<S> Vector2<S>[src]

pub fn new(x: S, y: S) -> Vector2<S>[src]

Construct a new vector, using the provided values.

pub fn from_value(scalar: S) -> Vector2<S> where
    S: Clone
[src]

Construct a vector using the given value for each field.

pub fn len(&self) -> usize[src]

The number of dimensions in the vector.

pub fn map<U, F>(self, f: F) -> Vector2<U> where
    F: FnMut(S) -> U, 
[src]

Perform the given operation on each field in the vector, returning a new vector constructed from the operations.

pub fn zip_map<T, U, F>(self, other: Vector2<T>, f: F) -> Vector2<U> where
    F: FnMut(S, T) -> U, 
[src]

Perform the given operation on each each field on both vectors, returning a new vector constructed from the operations.

pub fn is_finite(&self) -> bool where
    S: BaseFloat
[src]

Test whether or not the vector is infinite.

pub fn cast<T>(&self) -> Option<Vector2<T>> where
    S: NumCast + Clone,
    T: NumCast
[src]

Component-wise casting to another type.

pub fn zero() -> Vector2<S> where
    S: Zero
[src]

A zeroed vector.

pub fn is_zero(&self) -> bool where
    S: PartialEq + Zero
[src]

Whether or not the vector is zeroed.

pub fn one() -> Vector2<S> where
    S: One
[src]

A vector with 1 for each element.

pub fn is_one(&self) -> bool where
    S: PartialEq + One
[src]

Whether or not each element in the vector is equal to 1.

pub fn is_nan(&self) -> bool where
    S: BaseFloat
[src]

Tests whether or not any of the vector's elements is NaN.

pub fn sum(self) -> S where
    S: Add<Output = S> + Copy
[src]

Sum the fields of the vector.

pub fn product(self) -> S where
    S: Mul<Output = S> + Copy
[src]

The product of the fields of the vector.

pub fn limit_magnitude(self, limit: S) -> Self where
    S: BaseFloat
[src]

Return a vector whose magnitude is limited to the given value.

pub fn with_magnitude(self, magnitude: S) -> Self where
    S: BaseFloat
[src]

Return a vector with the given magnitude.

pub fn normalize(self) -> Self where
    S: BaseFloat
[src]

Return a normalized vector.

If self is_zero, this returns self.

pub fn magnitude(self) -> S where
    S: BaseFloat
[src]

The magnitude of the vector.

The magnitude represents the distance from the origin to the point described by the vector.

Note: This is equivalent to .magnitude2().sqrt(). As a result, it can be quite a bit more computationally efficient to use .magnitude2() directly when feasible.

Example

let a = vec2(5.0, 0.0);
let b = vec2(0.0, 5.0);
assert_eq!(a.magnitude(), 5.0);
assert_eq!(b.magnitude(), 5.0);

pub fn magnitude2(self) -> S where
    S: BaseFloat
[src]

The square of the magnitude.

See the magnitude docs for details.

pub fn dot(self, other: Vector2<S>) -> S where
    S: BaseFloat
[src]

The dot product of self and the given vector.

impl<S> Vector2<S>[src]

pub fn unit_x() -> Vector2<S> where
    S: Zero + One
[src]

A unit vector in the x direction.

pub fn unit_y() -> Vector2<S> where
    S: Zero + One
[src]

A unit vector in the y direction.

pub fn perp_dot(self, other: Vector2<S>) -> S where
    S: Sub<Output = S> + Mul<Output = S>, 
[src]

The perpendicular dot product of the vector and other.

pub fn extend(self, z: S) -> Vector3<S>[src]

Create a Vector3, using the x and y values from this vector, and the provided z.

pub fn from_angle(radians: S) -> Self where
    S: BaseFloat
[src]

Construct a normalised (aka "unit") vector from the given angle in radians.

Examples

assert_eq!(Vector2::from_angle(0.0), vec2(1.0, 0.0));
// Keep an eye out for accumulating floating point error.
assert_eq!(Vector2::from_angle(PI * 0.5), vec2(-0.00000004371139, 1.0));
assert_eq!(Vector2::from_angle(PI), vec2(-1.0, -0.00000008742278));
assert_eq!(Vector2::from_angle(PI * 1.5), vec2(0.000000011924881, -1.0));
assert_eq!(Vector2::from_angle(TAU), vec2(1.0, 0.00000017484555));

pub fn angle(self) -> S where
    S: BaseFloat
[src]

Returns the angle of the vector in radians.

Examples

let v = vec2(-0.5, 0.5);
let radians = v.angle();
draw.quad()
    .rotate(radians);
assert_eq!(radians, 2.356194490192345);

pub fn angle_between(self, other: Self) -> S where
    S: BaseFloat
[src]

Returns the angle of the vector between self and other in radians.

The result is between 0 and PI. Note: Nannou's implementation is commutative (v1.angle_between(v2) == v2.angle_between(v1)).

Example

let right = vec2(2.0, 0.0);
let up = vec2(0.0, 3.0);
let down = vec2(0.0, -100.0);
assert_eq!(right.angle_between(up), PI/2.0);
assert_eq!(right.angle_between(down), PI/2.0);

pub fn rotate(self, radians: S) -> Self where
    S: BaseFloat
[src]

Rotate the vector around the origin (0.0, 0.0) by the given radians.

Examples

let v = vec2(100.0, 0.0);
assert_eq!(v.rotate(PI).x, -v.x);
assert_eq!(v.rotate(TAU).x, v.x);

Trait Implementations

impl<S> AbsDiffEq<Vector2<S>> for Vector2<S> where
    S: AbsDiffEq,
    S::Epsilon: Copy
[src]

type Epsilon = S::Epsilon

Used for specifying relative comparisons.

impl<S> Add<Vector2<S>> for Vector2<S> where
    S: Add<Output = S>, 
[src]

type Output = Vector2<S>

The resulting type after applying the + operator.

impl<S> AddAssign<Vector2<S>> for Vector2<S> where
    S: AddAssign
[src]

impl<S> Array for Vector2<S> where
    S: Copy
[src]

type Element = S

impl<S> AsMut<[S; 2]> for Vector2<S>[src]

impl<S> AsRef<[S; 2]> for Vector2<S>[src]

impl<S> Bounded for Vector2<S> where
    S: Bounded
[src]

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

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

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

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

impl<S> Deref for Vector2<S>[src]

type Target = [S; 2]

The resulting type after dereferencing.

impl<S> DerefMut for Vector2<S>[src]

impl<'de, S> Deserialize<'de> for Vector2<S> where
    S: Deserialize<'de>, 
[src]

impl<S> Distribution<Vector2<S>> for Standard where
    Standard: Distribution<S>, 
[src]

impl<S> Div<S> for Vector2<S> where
    S: Copy + Div<Output = S>, 
[src]

type Output = Vector2<S>

The resulting type after applying the / operator.

impl<S> Div<Vector2<S>> for Vector2<S> where
    S: Div<Output = S>, 
[src]

type Output = Vector2<S>

The resulting type after applying the / operator.

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

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

impl<S> ElementWise<S> for Vector2<S> where
    S: BaseNum
[src]

impl<S> ElementWise<Vector2<S>> for Vector2<S> where
    S: BaseFloat
[src]

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

impl<S> EuclideanSpace for Vector2<S> where
    S: BaseNum
[src]

type Scalar = S

The associated scalar over which the space is defined. Read more

type Diff = Vector2<S>

The associated space of displacement vectors.

impl<S> From<[S; 2]> for Vector2<S> where
    S: Copy
[src]

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

impl<S> From<Point2<S>> for Vector2<S>[src]

impl<S> From<Point2D<f32, UnknownUnit>> for Vector2<S> where
    S: From<f32>, 
[src]

impl<S> From<Point2D<f64, UnknownUnit>> for Vector2<S> where
    S: From<f64>, 
[src]

impl<S> From<Size2D<f32, UnknownUnit>> for Vector2<S> where
    S: From<f32>, 
[src]

impl<S> From<Vector2<S>> for Vector2<S>[src]

impl<S> From<Vector2<S>> for Vector3<S> where
    S: Zero
[src]

impl<S> From<Vector2<S>> for Vector4<S> where
    S: Zero
[src]

impl<S> From<Vector2D<f32, UnknownUnit>> for Vector2<S> where
    S: From<f32>, 
[src]

impl<S: Hash> Hash for Vector2<S>[src]

impl<S> Index<Range<usize>> for Vector2<S>[src]

type Output = [S]

The returned type after indexing.

impl<S> Index<RangeFrom<usize>> for Vector2<S>[src]

type Output = [S]

The returned type after indexing.

impl<S> Index<RangeFull> for Vector2<S>[src]

type Output = [S]

The returned type after indexing.

impl<S> Index<RangeTo<usize>> for Vector2<S>[src]

type Output = [S]

The returned type after indexing.

impl<S> Index<usize> for Vector2<S>[src]

type Output = S

The returned type after indexing.

impl<S> IndexMut<Range<usize>> for Vector2<S>[src]

impl<S> IndexMut<RangeFrom<usize>> for Vector2<S>[src]

impl<S> IndexMut<RangeFull> for Vector2<S>[src]

impl<S> IndexMut<RangeTo<usize>> for Vector2<S>[src]

impl<S> IndexMut<usize> for Vector2<S>[src]

impl<S> InnerSpace for Vector2<S> where
    S: BaseFloat
[src]

impl<S> Into<[S; 2]> for Vector2<S>[src]

impl<S> Into<(S, S)> for Vector2<S>[src]

impl<S> Into<Point2<S>> for Vector2<S>[src]

impl Into<Point2D<f32, UnknownUnit>> for Vector2[src]

impl<S> Into<Point2D<f64, UnknownUnit>> for Vector2<S> where
    S: Into<f64>, 
[src]

impl Into<Size2D<f32, UnknownUnit>> for Vector2[src]

impl<S> Into<Vector2<S>> for Vector2<S>[src]

impl Into<Vector2D<f32, UnknownUnit>> for Vector2[src]

impl<S> MetricSpace for Vector2<S> where
    S: BaseFloat
[src]

type Metric = S

The metric to be returned by the distance function.

impl<S> Mul<S> for Vector2<S> where
    S: Copy + Mul<Output = S>, 
[src]

type Output = Vector2<S>

The resulting type after applying the * operator.

impl<S> Mul<Vector2<S>> for Vector2<S> where
    S: Mul<Output = S>, 
[src]

type Output = Vector2<S>

The resulting type after applying the * operator.

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

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

impl<S> Neg for Vector2<S> where
    S: Neg<Output = S>, 
[src]

type Output = Vector2<S>

The resulting type after applying the - operator.

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

impl<S> RelativeEq<Vector2<S>> for Vector2<S> where
    S: RelativeEq,
    S::Epsilon: Copy
[src]

impl<S> Rem<S> for Vector2<S> where
    S: Copy + Rem<Output = S>, 
[src]

type Output = Vector2<S>

The resulting type after applying the % operator.

impl<S> Rem<Vector2<S>> for Vector2<S> where
    S: Rem<Output = S>, 
[src]

type Output = Vector2<S>

The resulting type after applying the % operator.

impl<S> RemAssign<S> for Vector2<S> where
    S: Copy + RemAssign
[src]

impl<S> RemAssign<Vector2<S>> for Vector2<S> where
    S: Copy + RemAssign
[src]

impl<S> Serialize for Vector2<S> where
    S: Serialize
[src]

impl<S> StructuralEq for Vector2<S>[src]

impl<S> StructuralPartialEq for Vector2<S>[src]

impl<S> Sub<Vector2<S>> for Vector2<S> where
    S: Sub<Output = S>, 
[src]

type Output = Vector2<S>

The resulting type after applying the - operator.

impl<S> SubAssign<Vector2<S>> for Vector2<S> where
    S: SubAssign
[src]

impl<'a, S: 'a> Sum<&'a Vector2<S>> for Vector2<S> where
    S: 'a + Clone + Zero + Add<Output = S>, 
[src]

impl<S> Sum<Vector2<S>> for Vector2<S> where
    S: Zero + Add<Output = S>, 
[src]

impl<S> UlpsEq<Vector2<S>> for Vector2<S> where
    S: UlpsEq,
    S::Epsilon: Copy
[src]

impl<S> VectorSpace for Vector2<S> where
    S: BaseNum
[src]

type Scalar = S

The associated scalar.

impl<S> Zero for Vector2<S> where
    S: PartialEq + Zero
[src]

Auto Trait Implementations

impl<S> RefUnwindSafe for Vector2<S> where
    S: RefUnwindSafe

impl<S> Send for Vector2<S> where
    S: Send

impl<S> Sync for Vector2<S> where
    S: Sync

impl<S> Unpin for Vector2<S> where
    S: Unpin

impl<S> UnwindSafe for Vector2<S> where
    S: UnwindSafe

Blanket Implementations

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
    D: AdaptFrom<S, Swp, Dwp, T>,
    Dwp: WhitePoint,
    Swp: WhitePoint,
    T: Component + Float
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> ConvertInto<U> for T where
    U: ConvertFrom<T>, 
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> NodeId for T where
    T: 'static + Copy + Clone + PartialEq<T> + Eq + Hash + Send
[src]

impl<T, Rhs> NumAssignOps<Rhs> for T where
    T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>, 
[src]

impl<T, Rhs, Output> NumOps<Rhs, Output> for T where
    T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>, 
[src]

impl<T> SetParameter for T

impl<T> SetParameter for T

impl<T> Style for T where
    T: Any + Debug + PartialEq<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> Zero for T where
    T: Zero