pub struct Point {
pub x: f64,
pub y: f64,
}
Expand description
A 2D point.
Fields§
§x: f64
The x coordinate.
y: f64
The y coordinate.
Implementations§
§impl Point
impl Point
pub fn distance_squared(self, other: Point) -> f64
pub fn distance_squared(self, other: Point) -> f64
Squared Euclidean distance.
pub fn round(self) -> Point
pub fn round(self) -> Point
Returns a new Point
,
with x
and y
rounded to the nearest integer.
Examples
use kurbo::Point;
let a = Point::new(3.3, 3.6).round();
let b = Point::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) -> Point
pub fn ceil(self) -> Point
Returns a new Point
,
with x
and y
rounded up to the nearest integer,
unless they are already an integer.
Examples
use kurbo::Point;
let a = Point::new(3.3, 3.6).ceil();
let b = Point::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) -> Point
pub fn floor(self) -> Point
Returns a new Point
,
with x
and y
rounded down to the nearest integer,
unless they are already an integer.
Examples
use kurbo::Point;
let a = Point::new(3.3, 3.6).floor();
let b = Point::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) -> Point
pub fn expand(self) -> Point
Returns a new Point
,
with x
and y
rounded away from zero to the nearest integer,
unless they are already an integer.
Examples
use kurbo::Point;
let a = Point::new(3.3, 3.6).expand();
let b = Point::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) -> Point
pub fn trunc(self) -> Point
Returns a new Point
,
with x
and y
rounded towards zero to the nearest integer,
unless they are already an integer.
Examples
use kurbo::Point;
let a = Point::new(3.3, 3.6).trunc();
let b = Point::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 AddAssign<(f64, f64)> for Point
impl AddAssign<(f64, f64)> for Point
§fn add_assign(&mut self, _: (f64, f64))
fn add_assign(&mut self, _: (f64, f64))
Performs the
+=
operation. Read more§impl AddAssign<Vec2> for Point
impl AddAssign<Vec2> for Point
§fn add_assign(&mut self, other: Vec2)
fn add_assign(&mut self, other: Vec2)
Performs the
+=
operation. Read more§impl Mul<Point> for TranslateScale
impl Mul<Point> for TranslateScale
source§impl Scalable for Point
impl Scalable for Point
§impl SubAssign<(f64, f64)> for Point
impl SubAssign<(f64, f64)> for Point
§fn sub_assign(&mut self, _: (f64, f64))
fn sub_assign(&mut self, _: (f64, f64))
Performs the
-=
operation. Read more§impl SubAssign<Vec2> for Point
impl SubAssign<Vec2> for Point
§fn sub_assign(&mut self, other: Vec2)
fn sub_assign(&mut self, other: Vec2)
Performs the
-=
operation. Read moresource§impl ValueType for Point
impl ValueType for Point
source§fn try_from_value(value: &Value) -> Result<Self, ValueTypeError>
fn try_from_value(value: &Value) -> Result<Self, ValueTypeError>
Attempt to convert the generic
Value
into this type.impl Copy for Point
impl StructuralPartialEq for Point
Auto Trait Implementations§
impl RefUnwindSafe for Point
impl Send for Point
impl Sync for Point
impl Unpin for Point
impl UnwindSafe for Point
Blanket Implementations§
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IsDefault for Twhere
T: Default + PartialEq<T> + Copy,
impl<T> IsDefault for Twhere T: Default + PartialEq<T> + Copy,
source§fn is_default(&self) -> bool
fn is_default(&self) -> bool
Checks that type has a default value.
§impl<T> RoundFrom<T> for T
impl<T> RoundFrom<T> for T
§fn round_from(x: T) -> T
fn round_from(x: T) -> T
Performs the conversion.
§impl<T, U> RoundInto<U> for Twhere
U: RoundFrom<T>,
impl<T, U> RoundInto<U> for Twhere U: RoundFrom<T>,
§fn round_into(self) -> U
fn round_into(self) -> U
Performs the conversion.