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: f64
The x coordinate.
y: f64
The y coordinate.
Implementations§
source§impl Point
impl Point
sourcepub const fn new(x: f64, y: f64) -> Point
pub const fn new(x: f64, y: f64) -> Point
Create a new Point
with the provided x
and y
coordinates.
sourcepub fn distance_squared(self, other: Point) -> f64
pub fn distance_squared(self, other: Point) -> f64
Squared Euclidean distance.
sourcepub 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);
sourcepub 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);
sourcepub 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);
sourcepub 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);
sourcepub 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§
source§impl AddAssign<Vec2> for Point
impl AddAssign<Vec2> for Point
source§fn add_assign(&mut self, other: Vec2)
fn add_assign(&mut self, other: Vec2)
+=
operation. Read moresource§impl PartialEq for Point
impl PartialEq for Point
source§impl SubAssign<Vec2> for Point
impl SubAssign<Vec2> for Point
source§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 UnwindSafe for Point
Blanket Implementations§
source§impl<T> AsAny for Twhere
T: Any,
impl<T> AsAny for Twhere
T: Any,
source§fn as_dyn_any(&self) -> &(dyn Any + 'static)
fn as_dyn_any(&self) -> &(dyn Any + 'static)
source§fn as_mut_dyn_any(&mut self) -> &mut (dyn Any + 'static)
fn as_mut_dyn_any(&mut self) -> &mut (dyn Any + 'static)
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§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
.source§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
.source§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.source§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.