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 Mul<Point> for TransformationMatrix
impl Mul<Point> for TransformationMatrix
Source§impl Ord for Point
impl Ord for Point
Source§impl PartialOrd for Point
impl PartialOrd for Point
Source§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 TransformRef for Point
impl TransformRef for Point
Source§fn transform_ref(&self, trans: Transformation) -> Self
fn transform_ref(&self, trans: Transformation) -> Self
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.Source§impl TranslateRef for Point
impl TranslateRef for Point
Source§fn translate_ref(&self, p: Point) -> Self
fn translate_ref(&self, p: Point) -> Self
Translates the shape by
Point
, returning a new shape.impl Copy for Point
impl Eq 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> 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