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> Point<T>where
T: Copy,
impl<T> Point<T>where
T: Copy,
Sourcepub fn get(&self, coord: Orientation2D) -> T
pub fn get(&self, coord: Orientation2D) -> T
Get a specific coordinate of the point.
Sourcepub fn set(&mut self, coord: Orientation2D, value: T)
pub fn set(&mut self, coord: Orientation2D, value: T)
Set a specific coordinate of the point.
Source§impl<T> Point<T>where
T: Zero,
impl<T> Point<T>where
T: Zero,
Source§impl<T> Point<T>
impl<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 iron_shapes::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 vectors 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 iron_shapes::point::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 = Vector<T>>§
Sourcepub fn norm1(&self) -> T
pub fn norm1(&self) -> T
Get 1-norm of vector, i.e. the sum of the absolute values of its components.
§Examples
use iron_shapes::vector::Vector;
let a = Vector::new(-2, 3);
assert_eq!(a.norm1(), 5);
Sourcepub fn orientation_of(&self, other: Vector<T>) -> Orientation
pub fn orientation_of(&self, other: Vector<T>) -> Orientation
Check if other
is oriented clockwise or counter-clockwise respective to self
.
§Examples
use iron_shapes::vector::Vector;
use iron_shapes::types::Orientation;
let a = Vector::new(1, 0);
let b = Vector::new(1, 1);
let c = Vector::new(1, -1);
let d = Vector::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 norm2_squared(&self) -> T
pub fn norm2_squared(&self) -> T
Get squared 2-norm of vector.
§Examples
use iron_shapes::vector::Vector;
let a = Vector::new(2, 3);
assert_eq!(a.norm2_squared(), 2*2+3*3);
Sourcepub fn dot(&self, other: Vector<T>) -> T
pub fn dot(&self, other: Vector<T>) -> T
Calculate scalar product.
§Examples
use iron_shapes::vector::Vector;
let a = Vector::new(1, 2);
let b = Vector::new(3, 4);
assert_eq!(a.dot(b), 1*3 + 2*4);
Sourcepub fn cross_prod(&self, other: Vector<T>) -> T
pub fn cross_prod(&self, other: Vector<T>) -> T
Calculate cross product.
§Examples
use iron_shapes::vector::Vector;
let a = Vector::new(2, 0);
let b = Vector::new(0, 2);
assert_eq!(a.cross_prod(b), 4);
assert_eq!(b.cross_prod(a), -4);
Sourcepub fn cast_to_float<F>(&self) -> Vector<F>
pub fn cast_to_float<F>(&self) -> Vector<F>
Convert vector into a vector with floating point data type.
Sourcepub fn norm2(&self) -> T
pub fn norm2(&self) -> T
Get 2-norm of vector (length of vector).
§Examples
use iron_shapes::vector::Vector;
let a = Vector::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) -> Vector<T>
pub fn normalized(&self) -> Vector<T>
Sourcepub fn normal(&self) -> Vector<T>
pub fn normal(&self) -> Vector<T>
Return the normal vector onto this vector.
The normal has length 1
.
§Panics
Panics if the vector has length 0.
Sourcepub fn length<F>(&self) -> Fwhere
F: Float,
pub fn length<F>(&self) -> Fwhere
F: Float,
Calculate length of vector.
Similar to Vector::norm2
but does potentially return another data type for the length.
§Examples
use iron_shapes::vector::Vector;
let a = Vector::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> BoundingBox<T> for Point<T>where
T: Copy,
impl<T> BoundingBox<T> for Point<T>where
T: Copy,
Source§fn bounding_box(&self) -> Rect<T>
fn bounding_box(&self) -> Rect<T>
Source§impl<T> MapPointwise<T> for Point<T>where
T: Copy,
Point wise transformation for a single point.
impl<T> MapPointwise<T> for Point<T>where
T: Copy,
Point wise transformation for a single point.
Source§impl<T> MulAssign<T> for Point<T>
In-place scalar multiplication.
impl<T> MulAssign<T> for Point<T>
In-place scalar multiplication.
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*=
operation. Read moreSource§impl<T> Ord for Point<T>where
T: Ord,
Compare points.
impl<T> Ord for Point<T>where
T: Ord,
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)
.
Source§impl<T> PartialOrd for Point<T>where
T: PartialOrd,
Compare points.
impl<T> PartialOrd for Point<T>where
T: PartialOrd,
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)
.
Source§impl<C> PointBase<C> for Point<<C as CoordinateBase>::Coord>where
C: CoordinateBase,
impl<C> PointBase<C> for Point<<C as CoordinateBase>::Coord>where
C: CoordinateBase,
Source§fn new(
x: <C as CoordinateBase>::Coord,
y: <C as CoordinateBase>::Coord,
) -> Point<<C as CoordinateBase>::Coord>
fn new( x: <C as CoordinateBase>::Coord, y: <C as CoordinateBase>::Coord, ) -> Point<<C as CoordinateBase>::Coord>
Source§fn get(&self, orient: Orientation2D) -> <C as CoordinateBase>::Coord
fn get(&self, orient: Orientation2D) -> <C as CoordinateBase>::Coord
Source§fn set(&mut self, orient: Orientation2D, value: <C as CoordinateBase>::Coord)
fn set(&mut self, orient: Orientation2D, value: <C as CoordinateBase>::Coord)
Source§fn x(&self) -> <C as CoordinateBase>::Coord
fn x(&self) -> <C as CoordinateBase>::Coord
Source§fn y(&self) -> <C as CoordinateBase>::Coord
fn y(&self) -> <C as CoordinateBase>::Coord
Source§impl<C> PointConcept<C> for Point<<C as CoordinateBase>::Coord>where
C: CoordinateConcept,
impl<C> PointConcept<C> for Point<<C as CoordinateBase>::Coord>where
C: CoordinateConcept,
Source§fn projected_distance(
&self,
other: &Self,
orient: Orientation2D,
) -> <C as CoordinateConcept>::CoordinateDifference
fn projected_distance( &self, other: &Self, orient: Orientation2D, ) -> <C as CoordinateConcept>::CoordinateDifference
other
point.Source§fn manhattan_distance(
&self,
other: &Self,
) -> <C as CoordinateConcept>::CoordinateDifference
fn manhattan_distance( &self, other: &Self, ) -> <C as CoordinateConcept>::CoordinateDifference
Source§fn distance_squared(
&self,
other: &Self,
) -> <C as CoordinateConcept>::CoordinateDistance
fn distance_squared( &self, other: &Self, ) -> <C as CoordinateConcept>::CoordinateDistance
Source§fn euclidian_distance(
&self,
other: &Self,
) -> <C as CoordinateConcept>::CoordinateDistance
fn euclidian_distance( &self, other: &Self, ) -> <C as CoordinateConcept>::CoordinateDistance
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> TryBoundingBox<T> for Point<T>where
T: Copy,
impl<T> TryBoundingBox<T> for Point<T>where
T: Copy,
Source§fn try_bounding_box(&self) -> Option<Rect<T>>
fn try_bounding_box(&self) -> Option<Rect<T>>
Source§impl<T, Dst> TryCastCoord<T, Dst> for Point<T>
impl<T, Dst> TryCastCoord<T, Dst> for Point<T>
impl<T> Copy for Point<T>where
T: Copy,
impl<T> Eq for Point<T>where
T: Eq,
impl<T> StructuralPartialEq for Point<T>
Auto Trait Implementations§
impl<T> Freeze for Point<T>where
T: Freeze,
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
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