Struct iron_shapes::point::Point
source · [−]pub struct Point<T> { /* private fields */ }
Expand description
A point is defined by a x and y coordinate in the euclidean plane.
Implementations
sourceimpl<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 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 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 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 cross_prod(&self, other: Self) -> T
pub fn cross_prod(&self, other: Self) -> 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: CoordinateType + Float + NumCast>(&self) -> Vector<F>
pub fn cast_to_float<F: CoordinateType + Float + NumCast>(&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) -> Self
pub fn normalized(&self) -> Self
sourcepub fn length<F: Float>(&self) -> F
pub fn length<F: Float>(&self) -> F
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
sourceimpl<T, V> Add<V> for Point<T> where
T: Copy + Add<Output = T>,
V: Into<Point<T>>,
impl<T, V> Add<V> for Point<T> where
T: Copy + Add<Output = T>,
V: Into<Point<T>>,
Point addition.
sourceimpl<T, V> AddAssign<V> for Point<T> where
T: Copy + AddAssign<T>,
V: Into<Vector<T>>,
impl<T, V> AddAssign<V> for Point<T> where
T: Copy + AddAssign<T>,
V: Into<Vector<T>>,
sourcefn add_assign(&mut self, rhs: V)
fn add_assign(&mut self, rhs: V)
Performs the +=
operation. Read more
sourceimpl<T: Copy> BoundingBox<T> for Point<T>
impl<T: Copy> BoundingBox<T> for Point<T>
sourcefn bounding_box(&self) -> Rect<T>
fn bounding_box(&self) -> Rect<T>
Return the bounding box of this geometry.
sourceimpl<T: Copy> MapPointwise<T> for Point<T>
impl<T: Copy> MapPointwise<T> for Point<T>
Point wise transformation for a single point.
sourceimpl<T> MulAssign<T> for Point<T> where
T: Copy + MulAssign<T>,
impl<T> MulAssign<T> for Point<T> where
T: Copy + MulAssign<T>,
In-place scalar multiplication.
sourcefn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
Performs the *=
operation. Read more
sourceimpl<T: Ord> Ord for Point<T>
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)
.
sourceimpl<T: PartialOrd> PartialOrd<Point<T>> for Point<T>
impl<T: PartialOrd> PartialOrd<Point<T>> 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)
.
sourcefn partial_cmp(&self, rhs: &Self) -> Option<Ordering>
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<C> PointBase<C> for Point<C::Coord> where
C: CoordinateBase,
impl<C> PointBase<C> for Point<C::Coord> where
C: CoordinateBase,
sourcefn get(&self, orient: Orientation2D) -> C::Coord
fn get(&self, orient: Orientation2D) -> C::Coord
Get a coordinate value.
sourcefn set(&mut self, orient: Orientation2D, value: C::Coord)
fn set(&mut self, orient: Orientation2D, value: C::Coord)
Set a coordinate value.
sourceimpl<C> PointConcept<C> for Point<C::Coord> where
C: CoordinateConcept,
impl<C> PointConcept<C> for Point<C::Coord> where
C: CoordinateConcept,
sourcefn projected_distance(
&self,
other: &Self,
orient: Orientation2D
) -> C::CoordinateDifference
fn projected_distance(
&self,
other: &Self,
orient: Orientation2D
) -> C::CoordinateDifference
Compute the x or y component of the vector from the point to the other
point.
sourcefn manhattan_distance(&self, other: &Self) -> C::CoordinateDifference
fn manhattan_distance(&self, other: &Self) -> C::CoordinateDifference
Compute the 1-norm of the vector pointing from the point to the other.
sourcefn distance_squared(&self, other: &Self) -> C::CoordinateDistance
fn distance_squared(&self, other: &Self) -> C::CoordinateDistance
Squared euclidean distance.
sourcefn euclidian_distance(&self, other: &Self) -> C::CoordinateDistance
fn euclidian_distance(&self, other: &Self) -> C::CoordinateDistance
Euclidean distance, i.e. 2-norm of the vector from the point to the other.
sourceimpl<T, V> SubAssign<V> for Point<T> where
T: Copy + SubAssign<T>,
V: Into<Vector<T>>,
impl<T, V> SubAssign<V> for Point<T> where
T: Copy + SubAssign<T>,
V: Into<Vector<T>>,
sourcefn sub_assign(&mut self, rhs: V)
fn sub_assign(&mut self, rhs: V)
Performs the -=
operation. Read more
sourceimpl<T: Copy> TryBoundingBox<T> for Point<T>
impl<T: Copy> TryBoundingBox<T> for Point<T>
sourcefn try_bounding_box(&self) -> Option<Rect<T>>
fn try_bounding_box(&self) -> Option<Rect<T>>
Return the bounding box of this geometry if a bounding box is defined.
impl<T: Copy> Copy for Point<T>
impl<T: PartialEq> Eq 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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<S, T> RotateOrtho<T> for S where
T: Copy + Zero + Sub<T, Output = T>,
S: MapPointwise<T>,
impl<S, T> RotateOrtho<T> for S where
T: Copy + Zero + Sub<T, Output = T>,
S: MapPointwise<T>,
sourcefn rotate_ortho(&self, a: Angle) -> S
fn rotate_ortho(&self, a: Angle) -> S
Rotate the geometrical shape by a multiple of 90 degrees.