Struct kurbo::Vec2

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

A 2D vector.

This can be interpreted as a point in 2-space, a translation, a vector, or a complex number; the interpretation is not indicated in the type.

Fields§

§x: f64§y: f64

Implementations§

Create a new vector.

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.

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.

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 points.

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
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

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
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
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
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 !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. 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

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

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. 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.