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) -> Self
pub const fn new(x: f64, y: f64) -> Self
Create a new Point
with the provided x
and y
coordinates.
sourcepub fn distance(self, other: Point) -> f64
pub fn distance(self, other: Point) -> f64
Euclidean distance.
See Vec2::hypot
for the same operation on Vec2
.
sourcepub 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
.
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 Mul<Point> for TranslateScale
impl Mul<Point> for TranslateScale
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> 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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)