Struct druid::Vec2 [−]
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
impl Vec2
impl Vec2
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.
pub fn from_angle(th: f64) -> Vec2
pub fn from_angle(th: f64) -> Vec2
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 magnitutde 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
impl Add<TranslateScale> for Vec2
impl Add<TranslateScale> for Vec2
type Output = TranslateScale
type Output = TranslateScale
The resulting type after applying the +
operator.
pub fn add(self, other: TranslateScale) -> TranslateScale
pub fn add(self, other: TranslateScale) -> TranslateScale
Performs the +
operation. Read more
impl Add<Vec2> for CircleSegment
impl Add<Vec2> for CircleSegment
type Output = CircleSegment
type Output = CircleSegment
The resulting type after applying the +
operator.
pub fn add(self, v: Vec2) -> CircleSegment
pub fn add(self, v: Vec2) -> CircleSegment
Performs the +
operation. Read more
impl Add<Vec2> for TranslateScale
impl Add<Vec2> for TranslateScale
type Output = TranslateScale
type Output = TranslateScale
The resulting type after applying the +
operator.
pub fn add(self, other: Vec2) -> TranslateScale
pub fn add(self, other: Vec2) -> TranslateScale
Performs the +
operation. Read more
impl Add<Vec2> for RoundedRect
impl Add<Vec2> for RoundedRect
type Output = RoundedRect
type Output = RoundedRect
The resulting type after applying the +
operator.
pub fn add(self, v: Vec2) -> RoundedRect
pub fn add(self, v: Vec2) -> RoundedRect
Performs the +
operation. Read more
Performs the +=
operation. Read more
pub fn add_assign(&mut self, other: Vec2)
pub fn add_assign(&mut self, other: Vec2)
Performs the +=
operation. Read more
impl AddAssign<Vec2> for TranslateScale
impl AddAssign<Vec2> for TranslateScale
pub fn add_assign(&mut self, other: Vec2)
pub fn add_assign(&mut self, other: Vec2)
Performs the +=
operation. Read more
pub fn add_assign(&mut self, other: Vec2)
pub fn add_assign(&mut self, other: Vec2)
Performs the +=
operation. Read more
pub fn div_assign(&mut self, other: f64)
pub fn div_assign(&mut self, other: f64)
Performs the /=
operation. Read more
pub fn mul_assign(&mut self, other: f64)
pub fn mul_assign(&mut self, other: f64)
Performs the *=
operation. Read more
Converts a Vec2
from display points into pixels,
using the x axis scale factor for x
and the y axis scale factor for y
.
impl Sub<Vec2> for TranslateScale
impl Sub<Vec2> for TranslateScale
type Output = TranslateScale
type Output = TranslateScale
The resulting type after applying the -
operator.
pub fn sub(self, other: Vec2) -> TranslateScale
pub fn sub(self, other: Vec2) -> TranslateScale
Performs the -
operation. Read more
impl Sub<Vec2> for CircleSegment
impl Sub<Vec2> for CircleSegment
type Output = CircleSegment
type Output = CircleSegment
The resulting type after applying the -
operator.
pub fn sub(self, v: Vec2) -> CircleSegment
pub fn sub(self, v: Vec2) -> CircleSegment
Performs the -
operation. Read more
impl Sub<Vec2> for RoundedRect
impl Sub<Vec2> for RoundedRect
type Output = RoundedRect
type Output = RoundedRect
The resulting type after applying the -
operator.
pub fn sub(self, v: Vec2) -> RoundedRect
pub fn sub(self, v: Vec2) -> RoundedRect
Performs the -
operation. Read more
Performs the -=
operation. Read more
pub fn sub_assign(&mut self, other: Vec2)
pub fn sub_assign(&mut self, other: Vec2)
Performs the -=
operation. Read more
pub fn sub_assign(&mut self, other: Vec2)
pub fn sub_assign(&mut self, other: Vec2)
Performs the -=
operation. Read more
impl SubAssign<Vec2> for TranslateScale
impl SubAssign<Vec2> for TranslateScale
pub fn sub_assign(&mut self, other: Vec2)
pub fn sub_assign(&mut self, other: Vec2)
Performs the -=
operation. Read more
impl StructuralPartialEq for Vec2
Auto Trait Implementations
impl RefUnwindSafe for Vec2
impl UnwindSafe for Vec2
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
impl<T> RoundFrom<T> for T
impl<T> RoundFrom<T> for T
pub fn round_from(x: T) -> T
pub fn round_from(x: T) -> T
Performs the conversion.
pub fn round_into(self) -> U
pub fn round_into(self) -> U
Performs the conversion.
type Output = T
type Output = T
Should always be Self
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more