Struct libreda_db::layout::prelude::Point [−][src]
pub struct Point<T> where
T: CoordinateType, { /* fields omitted */ }Expand description
A point is defined by a x and y coordinate in the euclidean plane.
Implementations
Get zero-Point.
Examples
use iron_shapes::point::Point;
let a = Point::zero();
let b = Point::new(0, 0);
assert_eq!(a, b);Check if this is the zero-Point.
Examples
use iron_shapes::point::*;
assert!(Point::<usize>::zero().is_zero());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);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));Convert Point into a Point with floating point data type.
Methods from Deref<Target = Vector<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);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);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);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);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);Convert vector into a vector with floating point data type.
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);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
Point addition.
Performs the += operation. Read more
Return the bounding box of this geometry.
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<Point<T>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
pub 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
Scalar division.
Point wise transformation for a single point.
Scalar multiplication.
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).
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).
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
pub 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
Subtract a point.
Subtract a vector.
Performs the -= operation. Read more
Return the bounding box of this geometry if a bounding box is defined.
impl<T, Dst> TryCastCoord<T, Dst> for Point<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
impl<T, Dst> TryCastCoord<T, Dst> for Point<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
Auto Trait Implementations
impl<T> RefUnwindSafe for Point<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Point<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Rotate the geometrical shape by a multiple of 90 degrees.