Struct libreda_db::prelude::Point
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>
Implementations§
§impl<T> Point<T>where
T: Copy,
impl<T> Point<T>where T: Copy,
pub fn get(&self, coord: Orientation2D) -> T
pub fn get(&self, coord: Orientation2D) -> T
Get a specific coordinate of the point.
pub fn set(&mut self, coord: Orientation2D, value: T)
pub fn set(&mut self, coord: Orientation2D, value: T)
Set a specific coordinate of the point.
§impl<T> Point<T>where
T: Add<T, Output = T> + Copy + Sub<T, Output = T> + Mul<T, Output = T>,
impl<T> Point<T>where T: Add<T, Output = T> + Copy + Sub<T, Output = T> + Mul<T, Output = T>,
pub 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);
pub 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>>§
pub 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);
pub 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);
pub 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);
pub fn cast_to_float<F>(&self) -> Vector<F>where
F: CoordinateType + Float + NumCast,
pub fn cast_to_float<F>(&self) -> Vector<F>where F: CoordinateType + Float + NumCast,
Convert vector into a vector with floating point data type.
pub 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);
pub fn normalized(&self) -> Vector<T>
pub fn normalized(&self) -> Vector<T>
pub 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§
§impl<T, V> Add<V> for Point<T>where
T: Copy + Add<T, Output = T>,
V: Into<Point<T>>,
impl<T, V> Add<V> for Point<T>where T: Copy + Add<T, Output = T>, V: Into<Point<T>>,
Point addition.
§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>>,
§fn add_assign(&mut self, rhs: V)
fn add_assign(&mut self, rhs: V)
+=
operation. Read more§impl<T> BoundingBox<T> for Point<T>where
T: Copy,
impl<T> BoundingBox<T> for Point<T>where T: Copy,
§fn bounding_box(&self) -> Rect<T>
fn bounding_box(&self) -> Rect<T>
§impl<'de, T> Deserialize<'de> for Point<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Point<T>where T: Deserialize<'de>,
§fn deserialize<__D>(
__deserializer: __D
) -> Result<Point<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>( __deserializer: __D ) -> Result<Point<T>, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,
§impl<T> MapPointwise<T> for Point<T>where
T: Copy,
impl<T> MapPointwise<T> for Point<T>where T: Copy,
Point wise transformation for a single point.
§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.
§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*=
operation. Read more§impl<T> Ord for Point<T>where
T: Ord,
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)
.
§impl<T> PartialOrd<Point<T>> for Point<T>where
T: PartialOrd<T>,
impl<T> PartialOrd<Point<T>> for Point<T>where T: PartialOrd<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)
.
§fn partial_cmp(&self, rhs: &Point<T>) -> Option<Ordering>
fn partial_cmp(&self, rhs: &Point<T>) -> Option<Ordering>
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 more§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,
§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>
§fn get(&self, orient: Orientation2D) -> <C as CoordinateBase>::Coord
fn get(&self, orient: Orientation2D) -> <C as CoordinateBase>::Coord
§fn set(&mut self, orient: Orientation2D, value: <C as CoordinateBase>::Coord)
fn set(&mut self, orient: Orientation2D, value: <C as CoordinateBase>::Coord)
§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,
§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.§fn manhattan_distance(
&self,
other: &Self
) -> <C as CoordinateConcept>::CoordinateDifference
fn manhattan_distance( &self, other: &Self ) -> <C as CoordinateConcept>::CoordinateDifference
§fn distance_squared(
&self,
other: &Self
) -> <C as CoordinateConcept>::CoordinateDistance
fn distance_squared( &self, other: &Self ) -> <C as CoordinateConcept>::CoordinateDistance
§fn euclidian_distance(
&self,
other: &Self
) -> <C as CoordinateConcept>::CoordinateDistance
fn euclidian_distance( &self, other: &Self ) -> <C as CoordinateConcept>::CoordinateDistance
§impl<T> Serialize for Point<T>where
T: Serialize,
impl<T> Serialize for Point<T>where T: Serialize,
§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where __S: Serializer,
§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>>,
§fn sub_assign(&mut self, rhs: V)
fn sub_assign(&mut self, rhs: V)
-=
operation. Read more