Struct Point
pub struct Point {
pub x: f64,
pub y: f64,
}Expand description
A 2D point.
This type represents a point in 2D space. It has the same layout as Vec2, but
its meaning is different: Vec2 represents a change in location (for example velocity).
In general, kurbo overloads math operators where it makes sense, for example implementing
Affine * Point as the point under the affine transformation. However Point + Point and
f64 * Point are not implemented, because the operations do not make geometric sense. If you
need to apply these operations, then 1) check what you’re doing makes geometric sense, then 2)
use Point::to_vec2 to convert the point to a Vec2.
Fields§
§x: f64The x coordinate.
y: f64The y coordinate.
Implementations§
§impl Point
impl Point
pub fn distance(self, other: Point) -> f64
pub fn distance(self, other: Point) -> f64
Euclidean distance.
See Vec2::hypot for the same operation on Vec2.
pub fn distance_squared(self, other: Point) -> f64
pub fn distance_squared(self, other: Point) -> f64
Squared Euclidean distance.
See Vec2::hypot2 for the same operation on Vec2.
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);pub const fn get_coord_mut(&mut self, axis: Axis) -> &mut f64
pub const fn get_coord_mut(&mut self, axis: Axis) -> &mut f64
Get a mutable reference to the member matching the given axis.
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))
+= 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)
+= operation. Read more§impl Mul<Point> for TranslateScale
impl Mul<Point> for TranslateScale
§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))
-= 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)
-= operation. Read moreimpl Copy for Point
impl StructuralPartialEq for Point
Auto Trait Implementations§
impl Freeze for Point
impl RefUnwindSafe for Point
impl Send for Point
impl Sync for Point
impl Unpin for Point
impl UnsafeUnpin for Point
impl UnwindSafe for Point
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more