Struct kurbo::Vec2[][src]

pub struct Vec2 {
    pub x: f64,
    pub y: f64,
}
Expand description

A 2D vector.

This is intended primarily for a vector in the mathematical sense, but it can be interpreted as a translation, and converted to and from a point (vector relative to the origin) and size.

Fields

x: f64

The x-coordinate.

y: f64

The y-coordinate.

Implementations

The vector (0, 0).

Create a new vector.

Convert this vector into a Point.

Convert this vector into a Size.

Dot product of two vectors.

Cross product of two vectors.

This is signed so that (0, 1) × (1, 0) = 1.

Magnitude of vector.

Magnitude squared of vector.

Angle of vector.

If the vector is interpreted as a complex number, this is the argument. The angle is expressed in radians.

A unit vector of the given angle.

With th at zero, the result is the positive X unit vector, and at π/2, it is the positive Y unit vector. The angle is expressed in radians.

Thus, in a Y-down coordinate system (as is common for graphics), it is a clockwise rotation, and in Y-up (traditional for math), it is anti-clockwise. This convention is consistent with Affine::rotate.

Linearly interpolate between two vectors.

Returns a vector of magnitude 1.0 with the same angle as self; i.e. a unit/direction vector.

This produces NaN values when the magnitude is 0.

Returns a new Vec2, with x and y rounded to the nearest integer.

Examples
use kurbo::Vec2;
let a = Vec2::new(3.3, 3.6).round();
let b = Vec2::new(3.0, -3.1).round();
assert_eq!(a.x, 3.0);
assert_eq!(a.y, 4.0);
assert_eq!(b.x, 3.0);
assert_eq!(b.y, -3.0);

Returns a new Vec2, with x and y rounded up to the nearest integer, unless they are already an integer.

Examples
use kurbo::Vec2;
let a = Vec2::new(3.3, 3.6).ceil();
let b = Vec2::new(3.0, -3.1).ceil();
assert_eq!(a.x, 4.0);
assert_eq!(a.y, 4.0);
assert_eq!(b.x, 3.0);
assert_eq!(b.y, -3.0);

Returns a new Vec2, with x and y rounded down to the nearest integer, unless they are already an integer.

Examples
use kurbo::Vec2;
let a = Vec2::new(3.3, 3.6).floor();
let b = Vec2::new(3.0, -3.1).floor();
assert_eq!(a.x, 3.0);
assert_eq!(a.y, 3.0);
assert_eq!(b.x, 3.0);
assert_eq!(b.y, -4.0);

Returns a new Vec2, with x and y rounded away from zero to the nearest integer, unless they are already an integer.

Examples
use kurbo::Vec2;
let a = Vec2::new(3.3, 3.6).expand();
let b = Vec2::new(3.0, -3.1).expand();
assert_eq!(a.x, 4.0);
assert_eq!(a.y, 4.0);
assert_eq!(b.x, 3.0);
assert_eq!(b.y, -4.0);

Returns a new Vec2, with x and y rounded towards zero to the nearest integer, unless they are already an integer.

Examples
use kurbo::Vec2;
let a = Vec2::new(3.3, 3.6).trunc();
let b = Vec2::new(3.0, -3.1).trunc();
assert_eq!(a.x, 3.0);
assert_eq!(a.y, 3.0);
assert_eq!(b.x, 3.0);
assert_eq!(b.y, -3.0);

Is this Vec2 finite?

Is this Vec2 NaN?

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

In this context adding a Vec2 applies the corresponding translation to the ellipse.

The resulting type after applying the + operator.

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Note: division by a scalar is implemented by multiplying by the reciprocal.

This is more efficient but has different roundoff behavior than division.

The resulting type after applying the / operator.

Performs the /= operation. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

The name of the generated JSON Schema. Read more

Generates a JSON Schema for this type. Read more

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

In this context subtracting a Vec2 applies the corresponding translation to the ellipse.

The resulting type after applying the - operator.

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.