Struct piet_common::kurbo::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: f64The x-coordinate.
y: f64The y-coordinate.
Implementations
impl Vec2
impl Vec2
pub fn cross(self, other: Vec2) -> f64
pub fn cross(self, other: Vec2) -> f64
Cross product of two vectors.
This is signed so that (0, 1) × (1, 0) = 1.
pub fn atan2(self) -> f64
pub fn atan2(self) -> f64
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.
pub fn normalize(self) -> Vec2
pub fn normalize(self) -> Vec2
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.
pub fn round(self) -> Vec2
pub fn round(self) -> Vec2
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);pub fn ceil(self) -> Vec2
pub fn ceil(self) -> Vec2
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);pub fn floor(self) -> Vec2
pub fn floor(self) -> Vec2
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);pub fn expand(self) -> Vec2
pub fn expand(self) -> Vec2
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);pub fn trunc(self) -> Vec2
pub fn trunc(self) -> Vec2
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
+ operator.fn add(self, other: TranslateScale) -> TranslateScale
fn add(self, other: TranslateScale) -> TranslateScale
+ operation. Read moreimpl Add<Vec2> for CircleSegment
impl Add<Vec2> for CircleSegment
type Output = CircleSegment
type Output = CircleSegment
+ operator.fn add(self, v: Vec2) -> CircleSegment
fn add(self, v: Vec2) -> CircleSegment
+ operation. Read moreimpl Add<Vec2> for RoundedRect
impl Add<Vec2> for RoundedRect
type Output = RoundedRect
type Output = RoundedRect
+ operator.fn add(self, v: Vec2) -> RoundedRect
fn add(self, v: Vec2) -> RoundedRect
+ operation. Read moreimpl Add<Vec2> for TranslateScale
impl Add<Vec2> for TranslateScale
type Output = TranslateScale
type Output = TranslateScale
+ operator.fn add(self, other: Vec2) -> TranslateScale
fn add(self, other: Vec2) -> TranslateScale
+ operation. Read moreimpl AddAssign<Vec2> for Point
impl AddAssign<Vec2> for Point
fn add_assign(&mut self, other: Vec2)
fn add_assign(&mut self, other: Vec2)
+= operation. Read moreimpl AddAssign<Vec2> for TranslateScale
impl AddAssign<Vec2> for TranslateScale
fn add_assign(&mut self, other: Vec2)
fn add_assign(&mut self, other: Vec2)
+= operation. Read moreimpl AddAssign<Vec2> for Vec2
impl AddAssign<Vec2> for Vec2
fn add_assign(&mut self, other: Vec2)
fn add_assign(&mut self, other: Vec2)
+= operation. Read moreimpl DivAssign<f64> for Vec2
impl DivAssign<f64> for Vec2
fn div_assign(&mut self, other: f64)
fn div_assign(&mut self, other: f64)
/= operation. Read moreimpl MulAssign<f64> for Vec2
impl MulAssign<f64> for Vec2
fn mul_assign(&mut self, other: f64)
fn mul_assign(&mut self, other: f64)
*= operation. Read moresourceimpl RoundFrom<(f32, f32)> for Vec2
impl RoundFrom<(f32, f32)> for Vec2
sourcefn round_from(p: (f32, f32)) -> Vec2
fn round_from(p: (f32, f32)) -> Vec2
sourceimpl RoundFrom<(f64, f64)> for Vec2
impl RoundFrom<(f64, f64)> for Vec2
sourcefn round_from(p: (f64, f64)) -> Vec2
fn round_from(p: (f64, f64)) -> Vec2
sourceimpl RoundFrom<Vec2> for (f32, f32)
impl RoundFrom<Vec2> for (f32, f32)
sourcefn round_from(p: Vec2) -> (f32, f32)
fn round_from(p: Vec2) -> (f32, f32)
sourceimpl RoundFrom<Vec2> for (f64, f64)
impl RoundFrom<Vec2> for (f64, f64)
sourcefn round_from(p: Vec2) -> (f64, f64)
fn round_from(p: Vec2) -> (f64, f64)
impl Sub<Vec2> for CircleSegment
impl Sub<Vec2> for CircleSegment
type Output = CircleSegment
type Output = CircleSegment
- operator.fn sub(self, v: Vec2) -> CircleSegment
fn sub(self, v: Vec2) -> CircleSegment
- operation. Read moreimpl Sub<Vec2> for RoundedRect
impl Sub<Vec2> for RoundedRect
type Output = RoundedRect
type Output = RoundedRect
- operator.fn sub(self, v: Vec2) -> RoundedRect
fn sub(self, v: Vec2) -> RoundedRect
- operation. Read moreimpl Sub<Vec2> for TranslateScale
impl Sub<Vec2> for TranslateScale
type Output = TranslateScale
type Output = TranslateScale
- operator.fn sub(self, other: Vec2) -> TranslateScale
fn sub(self, other: Vec2) -> TranslateScale
- operation. Read moreimpl SubAssign<Vec2> for Point
impl SubAssign<Vec2> for Point
fn sub_assign(&mut self, other: Vec2)
fn sub_assign(&mut self, other: Vec2)
-= operation. Read moreimpl SubAssign<Vec2> for TranslateScale
impl SubAssign<Vec2> for TranslateScale
fn sub_assign(&mut self, other: Vec2)
fn sub_assign(&mut self, other: Vec2)
-= operation. Read moreimpl SubAssign<Vec2> for Vec2
impl SubAssign<Vec2> for Vec2
fn sub_assign(&mut self, other: Vec2)
fn sub_assign(&mut self, other: Vec2)
-= operation. Read more