pub struct Point<T> { /* private fields */ }Expand description
A point is defined by a x and y coordinate in the euclidean plane.
Implementations§
Source§impl<T: Copy> Point<T>
impl<T: Copy> Point<T>
pub fn vec2(&self) -> Vec2<T>
pub fn get(&self, coord: Orientation2D) -> T
pub fn set(&mut self, coord: Orientation2D, value: T)
Source§impl<T: Zero> Point<T>
impl<T: Zero> Point<T>
Source§impl<T: Copy + Mul<Output = T> + Add<Output = T> + Sub<Output = T>> Point<T>
impl<T: Copy + Mul<Output = T> + Add<Output = T> + Sub<Output = T>> Point<T>
Sourcepub fn distance_sq(self, other: &Point<T>) -> T
pub fn distance_sq(self, other: &Point<T>) -> T
Compute the squared distance to the other point.
§Examples
use reda_geometry::shape::Point;
let a = Point::new(0, 0);
let b = Point::new(2, 0);
assert_eq!(a.distance_sq(&b), 2*2);Sourcepub fn cross_prod3(&self, b: Point<T>, c: Point<T>) -> T
pub fn cross_prod3(&self, b: Point<T>, c: Point<T>) -> T
Calculate the cross product of the two vec2s defined by three points.
A positive value implies that self → a → b is counter-clockwise, negative implies
clockwise.
(b - self) x (c - b)
§Examples
use reda_geometry::shape::Point;
let a = Point::new(1,0);
let b = Point::new(1,1);
let c = Point::new(0,1);
let p = a.cross_prod3(b, c);
assert_eq!(p, (b-a).cross_prod(c - b));Methods from Deref<Target = Vec2<T>>§
pub fn is_zero(&self) -> bool
Sourcepub fn norm1(&self) -> T
pub fn norm1(&self) -> T
Get 1-norm of vec2, i.e. the sum of the absolute values of its components.
§Examples
use reda_geometry::base::Vec2;
let a = Vec2::new(-2, 3);
assert_eq!(a.norm1(), 5);Sourcepub fn orientation_of(&self, other: Self) -> Orientation
pub fn orientation_of(&self, other: Self) -> Orientation
Check if other is oriented clockwise or counter-clockwise respective to self.
§Examples
use reda_geometry::base::Vec2;
use reda_geometry::base::Orientation;
let a = Vec2::new(1, 0);
let b = Vec2::new(1, 1);
let c = Vec2::new(1, -1);
let d = Vec2::new(2, 0);
assert_eq!(a.orientation_of(b), Orientation::CounterClockWise);
assert_eq!(a.orientation_of(c), Orientation::ClockWise);
assert_eq!(a.orientation_of(d), Orientation::Straight);Sourcepub fn cross_prod(&self, other: Self) -> T
pub fn cross_prod(&self, other: Self) -> T
Calculate cross product.
§Examples
use reda_geometry::base::Vec2;
let a = Vec2::new(2, 0);
let b = Vec2::new(0, 2);
assert_eq!(a.cross_prod(b), 4);
assert_eq!(b.cross_prod(a), -4);Sourcepub fn norm2_squared(&self) -> T
pub fn norm2_squared(&self) -> T
Get squared 2-norm of vec2.
§Examples
use reda_geometry::base::Vec2;
let a = Vec2::new(2, 3);
assert_eq!(a.norm2_squared(), 2*2+3*3);Sourcepub fn dot(&self, other: Self) -> T
pub fn dot(&self, other: Self) -> T
Calculate scalar product.
§Examples
use reda_geometry::base::Vec2;
let a = Vec2::new(1, 2);
let b = Vec2::new(3, 4);
assert_eq!(a.dot(b), 1*3 + 2*4);Sourcepub fn norm2(&self) -> T
pub fn norm2(&self) -> T
Get 2-norm of vec2 (length of vec2).
§Examples
use reda_geometry::base::Vec2;
let a = Vec2::new(2.0, 3.0);
let norm2 = a.norm2();
let norm2_sq = norm2 * norm2;
let expected = a.norm2_squared();
assert!(norm2_sq < expected + 1e-12);
assert!(norm2_sq > expected - 1e-12);Sourcepub fn normalized(&self) -> Self
pub fn normalized(&self) -> Self
Sourcepub fn length<F: Float>(&self) -> F
pub fn length<F: Float>(&self) -> F
Calculate length of vec2.
Similar to Vec2::norm2 but does potentially return another data type for the length.
§Examples
use reda_geometry::base::Vec2;
let a = Vec2::new(2.0, 3.0);
let length: f64 = a.length();
let norm2_sq = length * length;
let expected = a.norm2_squared();
assert!(norm2_sq < expected + 1e-12);
assert!(norm2_sq > expected - 1e-12);Trait Implementations§
Source§impl<T, V> AddAssign<V> for Point<T>
impl<T, V> AddAssign<V> for Point<T>
Source§fn add_assign(&mut self, rhs: V)
fn add_assign(&mut self, rhs: V)
+= operation. Read moreSource§impl<T: Copy> BoundingBox<T> for Point<T>
impl<T: Copy> BoundingBox<T> for Point<T>
fn bounding_box(&self) -> Rect<T>
impl<T: Copy> Copy for Point<T>
impl<T: Eq> Eq for Point<T>
Source§impl<T> MulAssign<T> for Point<T>
impl<T> MulAssign<T> for Point<T>
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*= operation. Read moreSource§impl<T: Ord> Ord for Point<T>
Compare points.
impl<T: Ord> Ord for Point<T>
Compare points.
The ordering is determined by the x-coordinates. If it is the same for both points the y-coordinate is used.
Point a > Point b iff a.x > b.x || (a.x == b.x && a.y > b.y).
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialOrd> PartialOrd for Point<T>
Compare points.
impl<T: PartialOrd> PartialOrd for Point<T>
Compare points.
The ordering is determined by the x-coordinates. If it is the same for both points the y-coordinate is used.
Point a > Point b iff a.x > b.x || (a.x == b.x && a.y > b.y).
impl<T: PartialEq> StructuralPartialEq for Point<T>
Source§impl<T, V> SubAssign<V> for Point<T>
impl<T, V> SubAssign<V> for Point<T>
Source§fn sub_assign(&mut self, rhs: V)
fn sub_assign(&mut self, rhs: V)
-= operation. Read moreSource§impl<T: Copy> TryBoundingBox<T> for Point<T>
impl<T: Copy> TryBoundingBox<T> for Point<T>
fn try_bounding_box(&self) -> Option<Rect<T>>
Auto Trait Implementations§
impl<T> Freeze for Point<T>
impl<T> RefUnwindSafe for Point<T>where
Vec2<T>: RefUnwindSafe,
impl<T> Send for Point<T>
impl<T> Sync for Point<T>
impl<T> Unpin for Point<T>
impl<T> UnsafeUnpin for Point<T>where
Vec2<T>: UnsafeUnpin,
impl<T> UnwindSafe for Point<T>where
Vec2<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more