Skip to main content

Point

Struct Point 

Source
#[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-----> x

Properties:

  • xcoord: The x-coordinate of the point
  • ycoord: 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: T1

x portion of the Point object

§ycoord: T2

y portion of the Point object

Implementations§

Source§

impl<T1, T2> Point<T1, T2>

Source

pub const fn new(xcoord: T1, ycoord: T2) -> Self

Creates a new Point with the given x and y coordinates

§Arguments
  • xcoord - The x-coordinate of the point
  • ycoord - The y-coordinate of the point
§Examples
use physdes::point::Point;
assert_eq!(Point::new(3, 4).xcoord, 3);
assert_eq!(Point::new(3, 4).ycoord, 4);
Source

pub fn xcoord(&self) -> &T1

Returns a reference to the x-coordinate

Source

pub fn ycoord(&self) -> &T2

Returns a reference to the y-coordinate

Source

pub fn xcoord_mut(&mut self) -> &mut T1

Returns a mutable reference to the x-coordinate

Source

pub fn ycoord_mut(&mut self) -> &mut T2

Returns a mutable reference to the y-coordinate

Source

pub fn flip_xy(&self) -> Point<T2, T1>
where T1: Clone, T2: Clone,

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

pub fn flip_y(&self) -> Point<T1, T2>
where T1: Clone + Neg<Output = T1>, T2: Clone,

Flips according to ycoord-axis (negates x-coordinate)

$$(x, y) \to (-x, y)$$

Returns a new Point with x-coordinate negated

§Examples
use physdes::point::Point;
let p = Point::new(3, 4);
assert_eq!(p.flip_y(), Point::new(-3, 4));
Source§

impl Point<Interval<i32>, Interval<i32>>

Source

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)$$

Source

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, T1: Clone + Num, T2: Clone + Num> Add<&'a Vector2<T1, T2>> for Point<T1, T2>

Source§

type Output = Point<T1, T2>

The resulting type after applying the + operator.
Source§

fn add(self, other: &Vector2<T1, T2>) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, 'b, T1: Clone + Num, T2: Clone + Num> Add<&'b Vector2<T1, T2>> for &'a Point<T1, T2>

Source§

type Output = Point<T1, T2>

The resulting type after applying the + operator.
Source§

fn add(self, other: &Vector2<T1, T2>) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, T1: Clone + Num, T2: Clone + Num> Add<Vector2<T1, T2>> for &'a Point<T1, T2>

Source§

type Output = Point<T1, T2>

The resulting type after applying the + operator.
Source§

fn add(self, other: Vector2<T1, T2>) -> Self::Output

Performs the + operation. Read more
Source§

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

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§

type Output = Point<T1, T2>

The resulting type after applying the + operator.
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

Source§

fn add_assign(&mut self, other: &'a Vector2<T1, T2>)

Performs the += operation. Read more
Source§

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>)

Performs the += operation. Read more
Source§

impl<T1: Clone, T2: Clone> Clone for Point<T1, T2>

Source§

fn clone(&self) -> Point<T1, T2>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T1, T2, U1, U2> Contain<Point<U1, U2>> for Point<T1, T2>
where T1: Contain<U1>, T2: Contain<U2>,

Source§

fn contains(&self, other: &Point<U1, U2>) -> bool

Source§

impl<T1: Copy, T2: Copy> Copy for Point<T1, T2>

Source§

impl<T1: Debug, T2: Debug> Debug for Point<T1, T2>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T1: Default, T2: Default> Default for Point<T1, T2>

Source§

fn default() -> Point<T1, T2>

Returns the “default value” for a type. Read more
Source§

impl<T1, T2> Displacement<Point<T1, T2>> for Point<T1, T2>
where T1: Displacement<T1, Output = T1>, T2: Displacement<T2, Output = T2>,

Source§

fn displace(&self, other: &Point<T1, T2>) -> Self::Output

Displacement vector between two points:

$$\vec{d} = (x_1 - x_2,; y_1 - y_2)$$

Source§

type Output = Vector2<T1, T2>

Source§

impl<T1: Display, T2: Display> Display for Point<T1, T2>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the point as (x, y).

Source§

impl<T1, T2, Alpha> Enlarge<Alpha> for Point<T1, T2>
where T1: Enlarge<Alpha, Output = Interval<T1>> + Copy, T2: Enlarge<Alpha, Output = Interval<T2>> + Copy, Alpha: Copy,

Source§

fn enlarge_with(&self, alpha: Alpha) -> Self::Output

Enlarges a point to a rectangle: $x \to [x-\alpha,; x+\alpha]$, $y \to [y-\alpha,; y+\alpha]$

Source§

type Output = Point<Interval<T1>, Interval<T2>>

Source§

impl<T1: Eq, T2: Eq> Eq for Point<T1, T2>

Source§

impl<T1: Hash, T2: Hash> Hash for Point<T1, T2>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T1, T2> Hull<Point<T1, T2>> for Point<T1, T2>
where T1: Hull<T1>, T2: Hull<T2>,

Source§

fn hull_with(&self, other: &Point<T1, T2>) -> Self::Output

Component-wise hull (bounding box) of two points:

$$\text{hull}(A,B) = (\min(A_x,B_x)..\max(A_x,B_x),; \min(A_y,B_y)..\max(A_y,B_y))$$

Source§

type Output = Point<<T1 as Hull<T1>>::Output, <T2 as Hull<T2>>::Output>

Source§

impl<T1, T2> Intersect<Point<T1, T2>> for Point<T1, T2>
where T1: Intersect<T1>, T2: Intersect<T2>,

Source§

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))$$

Source§

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>
where T1: MinDist<U1>, T2: MinDist<U2>,

Source§

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>

Source§

fn neg(self) -> Self::Output

Negate a Point

$$-P = (-x,; -y)$$

§Examples
use physdes::point::Point;

assert_eq!(-Point::new(3, 4), Point::new(-3, -4));
assert_eq!(-Point::new(0, 0), Point::new(0, 0));
Source§

type Output = Point<T1, T2>

The resulting type after applying the - operator.
Source§

impl<T1: Clone + Num + Neg<Output = T1>, T2: Clone + Num + Neg<Output = T2>> Neg for &Point<T1, T2>

Source§

type Output = Point<T1, T2>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T1: Ord, T2: Ord> Ord for Point<T1, T2>

Source§

fn cmp(&self, other: &Point<T1, T2>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T1, T2, U1, U2> Overlap<Point<U1, U2>> for Point<T1, T2>
where T1: Overlap<U1>, T2: Overlap<U2>,

Source§

fn overlaps(&self, other: &Point<U1, U2>) -> bool

Points overlap iff both coordinates overlap: $x_1 \cap x_2 \land y_1 \cap y_2$

Source§

impl<T1: PartialEq, T2: PartialEq> PartialEq for Point<T1, T2>

Source§

fn eq(&self, other: &Point<T1, T2>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T1: PartialOrd, T2: PartialOrd> PartialOrd for Point<T1, T2>

Source§

fn partial_cmp(&self, other: &Point<T1, T2>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T1: PartialEq, T2: PartialEq> StructuralPartialEq for Point<T1, T2>

Source§

impl<T1: Clone + Num, T2: Clone + Num> Sub for Point<T1, T2>

Source§

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§

type Output = Vector2<T1, T2>

The resulting type after applying the - operator.
Source§

impl<'a, T1: Clone + Num, T2: Clone + Num> Sub<&'a Vector2<T1, T2>> for Point<T1, T2>

Source§

type Output = Point<T1, T2>

The resulting type after applying the - operator.
Source§

fn sub(self, other: &Vector2<T1, T2>) -> Self::Output

Performs the - operation. Read more
Source§

impl<'a, 'b, T1: Clone + Num, T2: Clone + Num> Sub<&'b Vector2<T1, T2>> for &'a Point<T1, T2>

Source§

type Output = Point<T1, T2>

The resulting type after applying the - operator.
Source§

fn sub(self, other: &Vector2<T1, T2>) -> Self::Output

Performs the - operation. Read more
Source§

impl<'a, T1: Clone + Num, T2: Clone + Num> Sub<Vector2<T1, T2>> for &'a Point<T1, T2>

Source§

type Output = Point<T1, T2>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Vector2<T1, T2>) -> Self::Output

Performs the - operation. Read more
Source§

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

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§

type Output = Point<T1, T2>

The resulting type after applying the - operator.
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

Source§

fn sub_assign(&mut self, other: &'a Vector2<T1, T2>)

Performs the -= operation. Read more
Source§

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>)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<T1, T2> Freeze for Point<T1, T2>
where T1: Freeze, T2: Freeze,

§

impl<T1, T2> RefUnwindSafe for Point<T1, T2>

§

impl<T1, T2> Send for Point<T1, T2>
where T1: Send, T2: Send,

§

impl<T1, T2> Sync for Point<T1, T2>
where T1: Sync, T2: Sync,

§

impl<T1, T2> Unpin for Point<T1, T2>
where T1: Unpin, T2: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Contain<Interval<T>> for T
where T: PartialOrd,

Source§

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 _other parameter is a reference to an Interval object of the same type T as the current object.

Returns:

The contains function is returning a boolean value false.

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Hull<Interval<T>> for T
where T: Copy + Ord,

Source§

fn hull_with(&self, other: &Interval<T>) -> <T as Hull<Interval<T>>>::Output

Computes the hull of a scalar value with an interval (delegates to Interval::hull_with).

Source§

type Output = Interval<T>

Source§

impl<T> Intersect<Interval<T>> for T
where T: Copy + Ord,

Source§

fn intersect_with( &self, other: &Interval<T>, ) -> <T as Intersect<Interval<T>>>::Output

Computes the intersection of a scalar value with an interval.

Source§

type Output = Interval<T>

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Overlap<Interval<T>> for T
where T: PartialOrd,

Source§

fn overlaps(&self, other: &Interval<T>) -> bool

Checks if this value falls within the given interval.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.