Struct libreda_db::prelude::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
sourceimpl<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.
sourceimpl<T> Point<T> where
T: Zero,
impl<T> Point<T> where
T: Zero,
sourceimpl<T> Point<T> where
T: Add<T, Output = T> + Sub<T, Output = T> + Copy + Mul<T, Output = T>,
impl<T> Point<T> where
T: Add<T, Output = T> + Sub<T, Output = T> + Copy + Mul<T, Output = 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: 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 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> 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.
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 length<F>(&self) -> F where
F: Float,
pub fn length<F>(&self) -> F where
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
sourceimpl<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.
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> BoundingBox<T> for Point<T> where
T: Copy,
impl<T> BoundingBox<T> for Point<T> where
T: Copy,
sourcefn bounding_box(&self) -> Rect<T>
fn bounding_box(&self) -> Rect<T>
Return the bounding box of this geometry.
sourceimpl<'de, T> Deserialize<'de> for Point<T> where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Point<T> where
T: Deserialize<'de>,
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<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.
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 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)
.
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<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)
.
sourcefn partial_cmp(&self, rhs: &Point<T>) -> Option<Ordering>
fn partial_cmp(&self, rhs: &Point<T>) -> 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 as CoordinateBase>::Coord> where
C: CoordinateBase,
impl<C> PointBase<C> for Point<<C as CoordinateBase>::Coord> where
C: CoordinateBase,
sourcefn 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>
Construct a new point.
sourcefn get(&self, orient: Orientation2D) -> <C as CoordinateBase>::Coord
fn get(&self, orient: Orientation2D) -> <C as CoordinateBase>::Coord
Get a coordinate value.
sourcefn set(&mut self, orient: Orientation2D, value: <C as CoordinateBase>::Coord)
fn set(&mut self, orient: Orientation2D, value: <C as CoordinateBase>::Coord)
Set a coordinate value.
sourcefn x(&self) -> <C as CoordinateBase>::Coord
fn x(&self) -> <C as CoordinateBase>::Coord
Get the x-coordinate value.
sourcefn y(&self) -> <C as CoordinateBase>::Coord
fn y(&self) -> <C as CoordinateBase>::Coord
Get the y-coordinate value.
sourceimpl<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,
sourcefn projected_distance(
&self,
other: &Self,
orient: Orientation2D
) -> <C as CoordinateConcept>::CoordinateDifference
fn projected_distance(
&self,
other: &Self,
orient: Orientation2D
) -> <C as CoordinateConcept>::CoordinateDifference
Compute the x or y component of the vector from the point to the other
point.
sourcefn manhattan_distance(
&self,
other: &Self
) -> <C as CoordinateConcept>::CoordinateDifference
fn manhattan_distance(
&self,
other: &Self
) -> <C as CoordinateConcept>::CoordinateDifference
Compute the 1-norm of the vector pointing from the point to the other.
sourcefn distance_squared(
&self,
other: &Self
) -> <C as CoordinateConcept>::CoordinateDistance
fn distance_squared(
&self,
other: &Self
) -> <C as CoordinateConcept>::CoordinateDistance
Squared euclidean distance.
sourcefn euclidian_distance(
&self,
other: &Self
) -> <C as CoordinateConcept>::CoordinateDistance
fn euclidian_distance(
&self,
other: &Self
) -> <C as CoordinateConcept>::CoordinateDistance
Euclidean distance, i.e. 2-norm of the vector from the point to the other.
sourceimpl<T> Serialize for Point<T> where
T: Serialize,
impl<T> Serialize for Point<T> where
T: Serialize,
sourcefn 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,
Serialize this value into the given Serde serializer. Read more
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> TryBoundingBox<T> for Point<T> where
T: Copy,
impl<T> TryBoundingBox<T> for Point<T> where
T: Copy,
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.
sourceimpl<T, Dst> TryCastCoord<T, Dst> for Point<T> where
T: Copy + NumCast,
Dst: Copy + NumCast,
impl<T, Dst> TryCastCoord<T, Dst> for Point<T> where
T: Copy + NumCast,
Dst: Copy + NumCast,
impl<T> Copy for Point<T> where
T: Copy,
impl<T> Eq for Point<T> where
T: PartialEq<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.