Struct iron_shapes::point::Point
source · pub struct Point<T> {
location: Vector<T>,
}Expand description
A point is defined by a x and y coordinate in the euclidean plane.
Fields§
§location: Vector<T>Store the location as a translation from the origin.
Implementations§
source§impl<T: Copy> Point<T>
impl<T: Copy> Point<T>
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: 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§
source§impl<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.
source§impl<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>>,
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>
source§fn bounding_box(&self) -> Rect<T>
fn bounding_box(&self) -> Rect<T>
source§impl<'de, T> Deserialize<'de> for Point<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Point<T>where T: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl<T: Copy> MapPointwise<T> for Point<T>
impl<T: Copy> MapPointwise<T> for Point<T>
Point wise transformation for a single point.
source§impl<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.
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>
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).
source§impl<T: PartialEq> PartialEq<Point<T>> for Point<T>
impl<T: PartialEq> PartialEq<Point<T>> for Point<T>
source§impl<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).
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<C> PointBase<C> for Point<C::Coord>where
C: CoordinateBase,
impl<C> PointBase<C> for Point<C::Coord>where C: CoordinateBase,
source§fn get(&self, orient: Orientation2D) -> C::Coord
fn get(&self, orient: Orientation2D) -> C::Coord
source§fn set(&mut self, orient: Orientation2D, value: C::Coord)
fn set(&mut self, orient: Orientation2D, value: C::Coord)
source§impl<C> PointConcept<C> for Point<C::Coord>where
C: CoordinateConcept,
impl<C> PointConcept<C> for Point<C::Coord>where C: CoordinateConcept,
source§fn projected_distance(
&self,
other: &Self,
orient: Orientation2D
) -> C::CoordinateDifference
fn projected_distance( &self, other: &Self, orient: Orientation2D ) -> C::CoordinateDifference
other point.source§fn manhattan_distance(&self, other: &Self) -> C::CoordinateDifference
fn manhattan_distance(&self, other: &Self) -> C::CoordinateDifference
source§fn distance_squared(&self, other: &Self) -> C::CoordinateDistance
fn distance_squared(&self, other: &Self) -> C::CoordinateDistance
source§fn euclidian_distance(&self, other: &Self) -> C::CoordinateDistance
fn euclidian_distance(&self, other: &Self) -> C::CoordinateDistance
source§impl<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>>,
source§fn sub_assign(&mut self, rhs: V)
fn sub_assign(&mut self, rhs: V)
-= operation. Read more