#[repr(C)]pub struct Point<T1, T2> {
pub xcoord: T1,
pub ycoord: T2,
}Expand description
Generic Point struct with x and y coordinates
This struct represents a point in 2D space with coordinates of potentially different types. It provides various operations and functionalities for working with points, such as comparison operators, arithmetic operators, flipping, overlap checking, distance calculation, and more.
y
^
|
|
(x,y)*-----> x
|
|
O-----> xProperties:
xcoord: The x-coordinate of the pointycoord: The y-coordinate of the point
§Examples
use physdes::point::Point;
let p = Point::new(3, 4);
assert_eq!(p.xcoord, 3);
assert_eq!(p.ycoord, 4);Fields§
§xcoord: T1x portion of the Point object
ycoord: T2y portion of the Point object
Implementations§
Source§impl<T1, T2> Point<T1, T2>
impl<T1, T2> Point<T1, T2>
Sourcepub fn xcoord_mut(&mut self) -> &mut T1
pub fn xcoord_mut(&mut self) -> &mut T1
Returns a mutable reference to the x-coordinate
Sourcepub fn ycoord_mut(&mut self) -> &mut T2
pub fn ycoord_mut(&mut self) -> &mut T2
Returns a mutable reference to the y-coordinate
Sourcepub fn flip_xy(&self) -> Point<T2, T1>
pub fn flip_xy(&self) -> Point<T2, T1>
Flips the coordinates according to xcoord-ycoord diagonal line
$$(x, y) \to (y, x)$$
Returns a new Point with x and y coordinates swapped
§Examples
use physdes::point::Point;
let p = Point::new(1, 2);
assert_eq!(p.flip_xy(), Point::new(2, 1));Source§impl Point<Interval<i32>, Interval<i32>>
impl Point<Interval<i32>, Interval<i32>>
Sourcepub fn nearest_to(&self, other: &Point<i32, i32>) -> Point<i32, i32>
pub fn nearest_to(&self, other: &Point<i32, i32>) -> Point<i32, i32>
Returns the point on this rectangle that is nearest to other.
Clips each coordinate to the interval bounds:
$$x’ = \text{clip}(x,; lb_x,; ub_x), \quad y’ = \text{clip}(y,; lb_y,; ub_y)$$
Sourcepub fn blocks(&self, other: &Self) -> bool
pub fn blocks(&self, other: &Self) -> bool
Checks if this rectangle blocks the path represented by other rectangle.
A rectangle self blocks other if:
self.x contains other.x AND other.y contains self.y
OR
self.y contains other.y AND other.x contains self.x
This matches the Python blocks method semantics and is distinct from
simple rectangle overlap — it catches paths that must cross the keepout
regardless of L-shape choice.
Trait Implementations§
Source§impl<'a, 'b, T1: Clone + Num, T2: Clone + Num> Add<&'b Vector2<T1, T2>> for &'a Point<T1, T2>
impl<'a, 'b, T1: Clone + Num, T2: Clone + Num> Add<&'b Vector2<T1, T2>> for &'a Point<T1, T2>
Source§impl<T1: Clone + Num, T2: Clone + Num> Add<Vector2<T1, T2>> for Point<T1, T2>
impl<T1: Clone + Num, T2: Clone + Num> Add<Vector2<T1, T2>> for Point<T1, T2>
Source§fn add(self, other: Vector2<T1, T2>) -> Self::Output
fn add(self, other: Vector2<T1, T2>) -> Self::Output
Translate a point by a vector
$$P’ = (x + v_x,; y + v_y)$$
§Examples
use physdes::point::Point;
use physdes::vector2::Vector2;
assert_eq!(Point::new(3, 4) + Vector2::new(5, 3), Point::new(8, 7));
assert_eq!(Point::new(3, 4) + Vector2::new(-5, -3), Point::new(-2, 1));
assert_eq!(Point::new(3, 4) + Vector2::new(5, -3), Point::new(8, 1));
assert_eq!(Point::new(3, 4) + Vector2::new(-5, 3), Point::new(-2, 7));
assert_eq!(Point::new(3, 4) + Vector2::new(0, 0), Point::new(3, 4));
assert_eq!(Point::new(3, 4) + Vector2::new(0, 5), Point::new(3, 9));Source§impl<'a, T1: Clone + Num + AddAssign, T2: Clone + Num + AddAssign> AddAssign<&'a Vector2<T1, T2>> for Point<T1, T2>
Translates the point by adding a vector reference to its coordinates
impl<'a, T1: Clone + Num + AddAssign, T2: Clone + Num + AddAssign> AddAssign<&'a Vector2<T1, T2>> for Point<T1, T2>
Translates the point by adding a vector reference to its coordinates
Source§fn add_assign(&mut self, other: &'a Vector2<T1, T2>)
fn add_assign(&mut self, other: &'a Vector2<T1, T2>)
+= operation. Read moreSource§impl<T1: Clone + Num + AddAssign, T2: Clone + Num + AddAssign> AddAssign<Vector2<T1, T2>> for Point<T1, T2>
Translates the point by adding a vector to its coordinates
impl<T1: Clone + Num + AddAssign, T2: Clone + Num + AddAssign> AddAssign<Vector2<T1, T2>> for Point<T1, T2>
Translates the point by adding a vector to its coordinates
$$P \mathrel{+}= (v_x, v_y) \implies (x + v_x,; y + v_y)$$
Source§fn add_assign(&mut self, other: Vector2<T1, T2>)
fn add_assign(&mut self, other: Vector2<T1, T2>)
+= operation. Read moreimpl<T1: Copy, T2: Copy> Copy for Point<T1, T2>
Source§impl<T1, T2> Displacement<Point<T1, T2>> for Point<T1, T2>where
T1: Displacement<T1, Output = T1>,
T2: Displacement<T2, Output = T2>,
impl<T1, T2> Displacement<Point<T1, T2>> for Point<T1, T2>where
T1: Displacement<T1, Output = T1>,
T2: Displacement<T2, Output = T2>,
impl<T1: Eq, T2: Eq> Eq for Point<T1, T2>
Source§impl<T1, T2> Intersect<Point<T1, T2>> for Point<T1, T2>
impl<T1, T2> Intersect<Point<T1, T2>> for Point<T1, T2>
Source§fn intersect_with(&self, other: &Point<T1, T2>) -> Self::Output
fn intersect_with(&self, other: &Point<T1, T2>) -> Self::Output
Component-wise intersection of two points (when coordinates are intervals):
$$\text{intersect}(A,B) = (\max(A_x,B_x)..\min(A_x,B_x),; \max(A_y,B_y)..\min(A_y,B_y))$$
type Output = Point<<T1 as Intersect<T1>>::Output, <T2 as Intersect<T2>>::Output>
Source§impl<T1, T2, U1, U2> MinDist<Point<U1, U2>> for Point<T1, T2>
impl<T1, T2, U1, U2> MinDist<Point<U1, U2>> for Point<T1, T2>
Source§fn min_dist_with(&self, other: &Point<U1, U2>) -> u32
fn min_dist_with(&self, other: &Point<U1, U2>) -> u32
Manhattan distance: $d = |x_1 - x_2| + |y_1 - y_2|$
Source§impl<T1: Clone + Num + Neg<Output = T1>, T2: Clone + Num + Neg<Output = T2>> Neg for Point<T1, T2>
impl<T1: Clone + Num + Neg<Output = T1>, T2: Clone + Num + Neg<Output = T2>> Neg for Point<T1, T2>
Source§impl<T1: Clone + Num + Neg<Output = T1>, T2: Clone + Num + Neg<Output = T2>> Neg for &Point<T1, T2>
impl<T1: Clone + Num + Neg<Output = T1>, T2: Clone + Num + Neg<Output = T2>> Neg for &Point<T1, T2>
Source§impl<T1: Ord, T2: Ord> Ord for Point<T1, T2>
impl<T1: Ord, T2: Ord> Ord for Point<T1, T2>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T1: PartialEq, T2: PartialEq> PartialEq for Point<T1, T2>
impl<T1: PartialEq, T2: PartialEq> PartialEq for Point<T1, T2>
Source§impl<T1: PartialOrd, T2: PartialOrd> PartialOrd for Point<T1, T2>
impl<T1: PartialOrd, T2: PartialOrd> PartialOrd for Point<T1, T2>
impl<T1: PartialEq, T2: PartialEq> StructuralPartialEq for Point<T1, T2>
Source§impl<T1: Clone + Num, T2: Clone + Num> Sub for Point<T1, T2>
impl<T1: Clone + Num, T2: Clone + Num> Sub for Point<T1, T2>
Source§fn sub(self, other: Self) -> Self::Output
fn sub(self, other: Self) -> Self::Output
Calculate displacement vector between two points
$$\vec{d} = (x_1 - x_2,; y_1 - y_2)$$
§Examples
use physdes::point::Point;
use physdes::vector2::Vector2;
assert_eq!(Point::new(3, 4) - Point::new(5, 3), Vector2::new(-2, 1));
assert_eq!(Point::new(3, 4) - Point::new(-5, -3), Vector2::new(8, 7));
assert_eq!(Point::new(3, 4) - Point::new(5, -3), Vector2::new(-2, 7));
assert_eq!(Point::new(3, 4) - Point::new(-5, 3), Vector2::new(8, 1));
assert_eq!(Point::new(3, 4) - Point::new(0, 0), Vector2::new(3, 4));Source§impl<'a, 'b, T1: Clone + Num, T2: Clone + Num> Sub<&'b Vector2<T1, T2>> for &'a Point<T1, T2>
impl<'a, 'b, T1: Clone + Num, T2: Clone + Num> Sub<&'b Vector2<T1, T2>> for &'a Point<T1, T2>
Source§impl<T1: Clone + Num, T2: Clone + Num> Sub<Vector2<T1, T2>> for Point<T1, T2>
impl<T1: Clone + Num, T2: Clone + Num> Sub<Vector2<T1, T2>> for Point<T1, T2>
Source§fn sub(self, other: Vector2<T1, T2>) -> Self::Output
fn sub(self, other: Vector2<T1, T2>) -> Self::Output
Translate a point by a vector (subtraction)
$$P’ = (x - v_x,; y - v_y)$$
§Examples
use physdes::point::Point;
use physdes::vector2::Vector2;
assert_eq!(Point::new(3, 4) - Vector2::new(5, 3), Point::new(-2, 1));
assert_eq!(Point::new(3, 4) - Vector2::new(-5, -3), Point::new(8, 7));
assert_eq!(Point::new(3, 4) - Vector2::new(5, -3), Point::new(-2, 7));
assert_eq!(Point::new(3, 4) - Vector2::new(-5, 3), Point::new(8, 1));
assert_eq!(Point::new(3, 4) - Vector2::new(0, 0), Point::new(3, 4));
assert_eq!(Point::new(3, 4) - Vector2::new(0, 5), Point::new(3, -1));
assert_eq!(Point::new(3, 4) - Vector2::new(5, 0), Point::new(-2, 4));Source§impl<'a, T1: Clone + Num + SubAssign, T2: Clone + Num + SubAssign> SubAssign<&'a Vector2<T1, T2>> for Point<T1, T2>
Translates the point by subtracting a vector reference from its coordinates
impl<'a, T1: Clone + Num + SubAssign, T2: Clone + Num + SubAssign> SubAssign<&'a Vector2<T1, T2>> for Point<T1, T2>
Translates the point by subtracting a vector reference from its coordinates
Source§fn sub_assign(&mut self, other: &'a Vector2<T1, T2>)
fn sub_assign(&mut self, other: &'a Vector2<T1, T2>)
-= operation. Read moreSource§impl<T1: Clone + Num + SubAssign, T2: Clone + Num + SubAssign> SubAssign<Vector2<T1, T2>> for Point<T1, T2>
Translates the point by subtracting a vector from its coordinates
impl<T1: Clone + Num + SubAssign, T2: Clone + Num + SubAssign> SubAssign<Vector2<T1, T2>> for Point<T1, T2>
Translates the point by subtracting a vector from its coordinates
$$P \mathrel{-}= (v_x, v_y) \implies (x - v_x,; y - v_y)$$
Source§fn sub_assign(&mut self, other: Vector2<T1, T2>)
fn sub_assign(&mut self, other: Vector2<T1, T2>)
-= operation. Read moreAuto Trait Implementations§
impl<T1, T2> Freeze for Point<T1, T2>
impl<T1, T2> RefUnwindSafe for Point<T1, T2>where
T1: RefUnwindSafe,
T2: RefUnwindSafe,
impl<T1, T2> Send for Point<T1, T2>
impl<T1, T2> Sync for Point<T1, T2>
impl<T1, T2> Unpin for Point<T1, T2>
impl<T1, T2> UnsafeUnpin for Point<T1, T2>where
T1: UnsafeUnpin,
T2: UnsafeUnpin,
impl<T1, T2> UnwindSafe for Point<T1, T2>where
T1: UnwindSafe,
T2: UnwindSafe,
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§impl<T> Contain<Interval<T>> for Twhere
T: PartialOrd,
impl<T> Contain<Interval<T>> for Twhere
T: PartialOrd,
Source§fn contains(&self, _other: &Interval<T>) -> bool
fn contains(&self, _other: &Interval<T>) -> bool
The function contains always returns false and takes a reference to another Interval as
input.
Arguments:
_other: The_otherparameter is a reference to anIntervalobject of the same typeTas the current object.
Returns:
The contains function is returning a boolean value false.