Struct kurbo::Vec2 [−][src]
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
Cross product of two vectors.
This is signed so that (0, 1) × (1, 0) = 1.
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
.
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);
Trait Implementations
type Output = TranslateScale
type Output = TranslateScale
The resulting type after applying the +
operator.
Performs the +
operation. Read more
type Output = RoundedRect
type Output = RoundedRect
The resulting type after applying the +
operator.
Performs the +
operation. Read more
type Output = TranslateScale
type Output = TranslateScale
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
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Performs the /=
operation. Read more
Performs the *=
operation. Read more
type Output = RoundedRect
type Output = RoundedRect
The resulting type after applying the -
operator.
Performs the -
operation. Read more
type Output = TranslateScale
type Output = TranslateScale
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
impl RefUnwindSafe for Vec2
impl UnwindSafe for Vec2
Blanket Implementations
Mutably borrows from an owned value. Read more