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.

Properties:

  • xcoord: The x-coordinate of the point
  • ycoord: The y-coordinate of the point

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

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)

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

Trait Implementations§

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<&'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, 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

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

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>

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 · 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: 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§

type Output = Vector2<T1, T2>

Source§

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

Displace the current value by the provided other value.
Source§

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

Source§

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

Formats the value using the given formatter. Read more
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§

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

Source§

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

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§

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

Source§

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

Source§

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

Source§

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

Source§

fn intersect_with(&self, other: &Point<T1, T2>) -> Self::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

Calculates the minimum distance between the current value and the provided value. Read more
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: 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

§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: 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 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · 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

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 · 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 · 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 · 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 · 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 · 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<'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<&'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, 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)

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

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

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>

Source§

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

Performs the -= operation. Read more
Source§

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

Source§

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

Source§

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

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

The hull_with function in Rust calculates the convex hull of two intervals.

Arguments:

  • other: The other parameter in the hull_with function is a reference to an Interval<T> object.
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

The intersect_with function in Rust swaps the receiver and argument before calling the intersect_with method on the argument.

Arguments:

  • other: The other parameter in the intersect_with function represents another Interval<T> that you want to intersect with the current 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

The overlaps function in Rust checks if two intervals overlap with each other.

Arguments:

  • other: The other parameter is a reference to an Interval<T> struct, which represents another interval. The Interval<T> struct likely contains two fields, lb and ub, representing the lower and upper bounds of the interval, respectively. The overlaps method is used to

Returns:

The overlaps function is returning a boolean value. It checks if the current interval (self) overlaps with another interval (other) by comparing their lower bounds and upper bounds. If there is any overlap between the two intervals, it returns true, otherwise it returns false.

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.