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§
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);Sourcepub fn get_coord_mut(&mut self, axis: Axis) -> &mut f64
pub fn get_coord_mut(&mut self, axis: Axis) -> &mut f64
Get a mutable reference to the member matching the given axis.
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<'de> Deserialize<'de> for Point
impl<'de> Deserialize<'de> for Point
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§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 more