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: Thexcoordproperty represents the x-coordinate of a point in a two-dimensional space. It is a generic typeT, which means it can be any type that implements the necessary traits for thePointstruct.ycoord: Theycoordproperty represents the y-coordinate of a point in a two-dimensional space. It is a generic typeT, which means it can be any type that implements the necessary traits for thePointstruct.
Fields§
§xcoord: Tx portion of the Point object
ycoord: Ty portion of the Point object
Implementations§
source§impl<T> Point<T>
impl<T> Point<T>
sourcepub const fn new(xcoord: T, ycoord: T) -> Self
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: Thexcoordparameter represents the x-coordinate of the point. It is of typeT, which means it can be any type that implements the necessary traits for mathematical operations.ycoord: Theycoordparameter 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<T: Clone + Num> Add<Vector2<T>> for Point<T>
impl<T: Clone + Num> Add<Vector2<T>> for Point<T>
source§fn add(self, other: Vector2<T>) -> Self::Output
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));source§impl<'a, T: Clone + NumAssign> AddAssign<&'a Vector2<T>> for Point<T>
impl<'a, T: Clone + NumAssign> AddAssign<&'a Vector2<T>> for Point<T>
source§fn add_assign(&mut self, other: &Vector2<T>)
fn add_assign(&mut self, other: &Vector2<T>)
Performs the
+= operation. Read moresource§impl<T: Clone + NumAssign> AddAssign<Vector2<T>> for Point<T>
impl<T: Clone + NumAssign> AddAssign<Vector2<T>> for Point<T>
source§fn add_assign(&mut self, other: Vector2<T>)
fn add_assign(&mut self, other: Vector2<T>)
Performs the
+= operation. Read moresource§impl<T: PartialEq> PartialEq<Point<T>> for Point<T>
impl<T: PartialEq> PartialEq<Point<T>> for Point<T>
source§impl<T: Clone + Num> Sub<Point<T>> for Point<T>
impl<T: Clone + Num> Sub<Point<T>> for Point<T>
source§fn sub(self, other: Self) -> Self::Output
fn sub(self, other: Self) -> Self::Output
Displacement of two Points
Arguments:
other: Theotherparameter is of the same type asselfand represents the other object that you want to subtract fromself.
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<T: Clone + Num> Sub<Vector2<T>> for Point<T>
impl<T: Clone + Num> Sub<Vector2<T>> for Point<T>
source§fn sub(self, other: Vector2<T>) -> Self::Output
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));source§impl<'a, T: Clone + NumAssign> SubAssign<&'a Vector2<T>> for Point<T>
impl<'a, T: Clone + NumAssign> SubAssign<&'a Vector2<T>> for Point<T>
source§fn sub_assign(&mut self, other: &Vector2<T>)
fn sub_assign(&mut self, other: &Vector2<T>)
Performs the
-= operation. Read moresource§impl<T: Clone + NumAssign> SubAssign<Vector2<T>> for Point<T>
impl<T: Clone + NumAssign> SubAssign<Vector2<T>> for Point<T>
source§fn sub_assign(&mut self, other: Vector2<T>)
fn sub_assign(&mut self, other: Vector2<T>)
Performs the
-= operation. Read moreimpl<T: Copy> Copy for Point<T>
impl<T: Eq> Eq for Point<T>
impl<T> StructuralEq for Point<T>
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> 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