pub struct Point {
pub x: i64,
pub y: i64,
}
Expand description
A point in two-dimensional space.
Fields§
§x: i64
The x-coordinate of the point.
y: i64
The y-coordinate of the point.
Implementations§
source§impl Point
impl Point
sourcepub const fn from_dir_coords(dir: Dir, a: i64, b: i64) -> Self
pub const fn from_dir_coords(dir: Dir, a: i64, b: i64) -> Self
Creates a new point from the given direction and coordinates.
If dir
is Dir::Horiz
, a
becomes the x-coordinate and b
becomes the y-coordinate.
If dir
is Dir::Vert
, a
becomes the y-coordinate and b
becomes the x-coordinate.
sourcepub const fn zero() -> Self
pub const fn zero() -> Self
Returns the origin, (0, 0)
.
§Example
let origin = Point::zero();
assert_eq!(origin, Point::new(0, 0));
sourcepub fn snap_to_grid(&self, grid: i64) -> Self
pub fn snap_to_grid(&self, grid: i64) -> Self
Snaps the x and y coordinates of this point to the nearest multiple of grid
.
sourcepub fn snap_x_to_grid(&self, grid: i64) -> Self
pub fn snap_x_to_grid(&self, grid: i64) -> Self
Snaps only the x-coordinate of this point to the nearest multiple of grid
.
sourcepub fn snap_y_to_grid(&self, grid: i64) -> Self
pub fn snap_y_to_grid(&self, grid: i64) -> Self
Snaps only the y-coordinate of this point to the nearest multiple of grid
.
Trait Implementations§
source§impl AddAssign<Dims> for Point
impl AddAssign<Dims> for Point
source§fn add_assign(&mut self, rhs: Dims)
fn add_assign(&mut self, rhs: Dims)
Performs the
+=
operation. Read moresource§impl AddAssign for Point
impl AddAssign for Point
source§fn add_assign(&mut self, rhs: Point)
fn add_assign(&mut self, rhs: Point)
Performs the
+=
operation. Read moresource§impl Contains<Point> for Polygon
impl Contains<Point> for Polygon
source§fn contains(&self, p: &Point) -> Containment
fn contains(&self, p: &Point) -> Containment
Determines if a point is contained within a polygon.
§Example
let points = vec![
Point { x: -4, y: 0 },
Point { x: 0, y: 0 },
Point { x: 1, y: 2 },
Point { x: 2, y: 2 },
Point { x: -4, y: 5 },
];
let p1 = Point::new(0,0);
let p2 = Point::new(0,4);
let p3 = Point::new(-5,3);
let p4 = Point::new(-2,4);
let p5 = Point::new(-2,2);
let polygon = Polygon::from_verts(points);
assert_eq!(polygon.contains(&p1), Containment::Full);
assert_eq!(polygon.contains(&p2), Containment::None);
assert_eq!(polygon.contains(&p3), Containment::None);
assert_eq!(polygon.contains(&p4), Containment::Full);
assert_eq!(polygon.contains(&p5), Containment::Full);
source§fn partially_intersects(&self, other: &T) -> bool
fn partially_intersects(&self, other: &T) -> bool
Returns true if
other
is fully or partially enclosed in this shape.source§impl Contains<Point> for Rect
impl Contains<Point> for Rect
source§fn contains(&self, other: &Point) -> Containment
fn contains(&self, other: &Point) -> Containment
source§fn partially_intersects(&self, other: &T) -> bool
fn partially_intersects(&self, other: &T) -> bool
Returns true if
other
is fully or partially enclosed in this shape.source§impl Contains<Point> for Ring
impl Contains<Point> for Ring
source§fn contains(&self, other: &Point) -> Containment
fn contains(&self, other: &Point) -> Containment
source§fn partially_intersects(&self, other: &T) -> bool
fn partially_intersects(&self, other: &T) -> bool
Returns true if
other
is fully or partially enclosed in this shape.source§impl Contains<Point> for Shape
impl Contains<Point> for Shape
source§fn contains(&self, p: &Point) -> Containment
fn contains(&self, p: &Point) -> Containment
source§fn partially_intersects(&self, other: &T) -> bool
fn partially_intersects(&self, other: &T) -> bool
Returns true if
other
is fully or partially enclosed in this shape.source§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>,
Deserialize this value from the given Serde deserializer. Read more
source§impl HasTransformedView for Point
impl HasTransformedView for Point
§type TransformedView = Point
type TransformedView = Point
An object storing a transformed view of
Self
.source§fn transformed_view(&self, trans: Transformation) -> Self::TransformedView
fn transformed_view(&self, trans: Transformation) -> Self::TransformedView
Produces a transformed view of
self
.source§impl Ord for Point
impl Ord for Point
source§impl PartialEq for Point
impl PartialEq for Point
source§impl PartialOrd for Point
impl PartialOrd for Point
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl SubAssign for Point
impl SubAssign for Point
source§fn sub_assign(&mut self, rhs: Point)
fn sub_assign(&mut self, rhs: Point)
Performs the
-=
operation. Read moresource§impl TransformMut for Point
impl TransformMut for Point
source§fn transform_mut(&mut self, trans: Transformation)
fn transform_mut(&mut self, trans: Transformation)
Applies matrix-vector
Transformation
trans
.source§impl TranslateMut for Point
impl TranslateMut for Point
source§fn translate_mut(&mut self, p: Point)
fn translate_mut(&mut self, p: Point)
Translates the shape by a
Point
through mutation.impl Copy for Point
impl Eq 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> AlignRect for Twhere
T: AlignRectMut,
impl<T> AlignRect for Twhere
T: AlignRectMut,
source§impl<T> AlignRectMut for Twhere
T: Translate,
impl<T> AlignRectMut for Twhere
T: Translate,
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
Mutably borrows from an owned value. Read more