Struct physdes::point::Point

source ·
pub struct Point<T> {
    pub xcoord: T,
    pub ycoord: T,
}
Expand description

The code defines a generic Point struct with x and y coordinates.

Properties:

  • xcoord: The xcoord property represents the x-coordinate of a point in a two-dimensional space. It is a generic type T, which means it can be any type that implements the necessary traits for the Point struct.
  • ycoord: The ycoord property represents the y-coordinate of a point in a two-dimensional space. It is a generic type T, which means it can be any type that implements the necessary traits for the Point struct.

Fields§

§xcoord: T

x portion of the Point object

§ycoord: T

y portion of the Point object

Implementations§

source§

impl<T> Point<T>

source

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

The new function creates a new Point with the given x and y coordinates.

Arguments:

  • xcoord: The xcoord parameter represents the x-coordinate of the point. It is of type T, which means it can be any type that implements the necessary traits for mathematical operations.
  • ycoord: The ycoord parameter represents the y-coordinate of the point. It is used to specify the vertical position of the point in a two-dimensional coordinate system.

Returns:

The new function returns a new instance of the Point struct with the specified xcoord and ycoord values.

Examples
use physdes::point::Point;
assert_eq!(Point::new(3, 4).xcoord, 3);
assert_eq!(Point::new(3, 4).ycoord, 4);

Trait Implementations§

source§

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

§

type Output = Point<T>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

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

§

type Output = Point<T>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

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

§

type Output = Point<T>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T: Clone + Num> Add<Vector2<T>> for Point<T>

source§

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

Translate a new Point

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

type Output = Point<T>

The resulting type after applying the + operator.
source§

impl<'a, T: Clone + NumAssign> AddAssign<&'a Vector2<T>> for Point<T>

source§

fn add_assign(&mut self, other: &Vector2<T>)

Performs the += operation. Read more
source§

impl<T: Clone + NumAssign> AddAssign<Vector2<T>> for Point<T>

source§

fn add_assign(&mut self, other: Vector2<T>)

Performs the += operation. Read more
source§

impl<T: Clone> Clone for Point<T>

source§

fn clone(&self) -> Point<T>

Returns a copy 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<T: Debug> Debug for Point<T>

source§

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

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

impl<T: Default> Default for Point<T>

source§

fn default() -> Point<T>

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

impl<T: Hash> Hash for Point<T>

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<'a, T: Clone + Num + Neg<Output = T>> Neg for &'a Point<T>

§

type Output = Point<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<T: Clone + Num + Neg<Output = T>> Neg for Point<T>

source§

fn neg(self) -> Self::Output

Negate a Points

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

type Output = Point<T>

The resulting type after applying the - operator.
source§

impl<T: PartialEq> PartialEq<Point<T>> for Point<T>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, T: Clone + Num> Sub<&'a Point<T>> for Point<T>

§

type Output = Vector2<T>

The resulting type after applying the - operator.
source§

fn sub(self, other: &Point<T>) -> Self::Output

Performs the - operation. Read more
source§

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

§

type Output = Point<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<'a, 'b, T: Clone + Num> Sub<&'b Point<T>> for &'a Point<T>

§

type Output = Vector2<T>

The resulting type after applying the - operator.
source§

fn sub(self, other: &Point<T>) -> Self::Output

Performs the - operation. Read more
source§

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

§

type Output = Point<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<'a, T: Clone + Num> Sub<Point<T>> for &'a Point<T>

§

type Output = Vector2<T>

The resulting type after applying the - operator.
source§

fn sub(self, other: Point<T>) -> Self::Output

Performs the - operation. Read more
source§

impl<T: Clone + Num> Sub<Point<T>> for Point<T>

source§

fn sub(self, other: Self) -> Self::Output

Displacement of two Points

Arguments:

  • other: The other parameter is of the same type as self and represents the other object that you want to subtract from self.
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));
§

type Output = Vector2<T>

The resulting type after applying the - operator.
source§

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

§

type Output = Point<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T: Clone + Num> Sub<Vector2<T>> for Point<T>

source§

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

Translate a new Point

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

type Output = Point<T>

The resulting type after applying the - operator.
source§

impl<'a, T: Clone + NumAssign> SubAssign<&'a Vector2<T>> for Point<T>

source§

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

Performs the -= operation. Read more
source§

impl<T: Clone + NumAssign> SubAssign<Vector2<T>> for Point<T>

source§

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

Performs the -= operation. Read more
source§

impl<T: Copy> Copy for Point<T>

source§

impl<T: Eq> Eq for Point<T>

source§

impl<T> StructuralEq for Point<T>

source§

impl<T> StructuralPartialEq for Point<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Point<T>where T: RefUnwindSafe,

§

impl<T> Send for Point<T>where T: Send,

§

impl<T> Sync for Point<T>where T: Sync,

§

impl<T> Unpin for Point<T>where T: Unpin,

§

impl<T> UnwindSafe for Point<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.