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>

pub fn new(x: T, y: T) -> Point<T>

Create a new point with `x` and `y` coordinates.

§

impl<T> Point<T>where T: Copy,

pub fn v(&self) -> Vector<T>

Return the location of this point as a vector.

pub fn get(&self, coord: Orientation2D) -> T

Get a specific coordinate of the point.

pub fn set(&mut self, coord: Orientation2D, value: T)

Set a specific coordinate of the point.

§

impl<T> Point<T>where T: Zero,

pub fn zero() -> Point<T>

Get zero-Point.

Examples
``````use iron_shapes::point::Point;

let a = Point::zero();
let b = Point::new(0, 0);

assert_eq!(a, b);``````

pub fn is_zero(&self) -> bool

Check if this is the zero-Point.

Examples
``````use iron_shapes::point::*;

assert!(Point::<usize>::zero().is_zero());``````
§

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

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

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));``````
§

impl<T> Point<T>where T: Copy + Sub<T, Output = T> + NumCast,

pub fn distance<F>(self, other: &Point<T>) -> Fwhere F: Float,

Compute the Euclidean distance betwen two points.

§

impl<T> Point<T>where T: Copy + NumCast,

pub fn cast_to_float<F>(&self) -> Point<F>where F: Float + NumCast,

Convert Point into a Point with floating point data type.

Methods from Deref<Target = Vector<T>>§

pub fn norm1(&self) -> 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);``````

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

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 dot(&self, other: Vector<T>) -> T

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);``````

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,

Convert vector into a vector with floating point data type.

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>

Return a vector with the same direction but length 1.

Panics

Panics if the vector has length 0.

pub fn normal(&self) -> Vector<T>

Return the normal vector onto this vector. The normal has length `1`.

Panics

Panics if the vector has length 0.

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>>,

§

type Output = Point<T>

The resulting type after applying the `+` operator.
§

fn add(self, rhs: V) -> Point<T>

Performs the `+` operation. Read more
§

§

Performs the `+=` operation. Read more
§

impl<T> BoundingBox<T> for Point<T>where T: Copy,

§

fn bounding_box(&self) -> Rect<T>

Return the bounding box of this geometry.
§

impl<T> Clone for Point<T>where T: Clone,

§

fn clone(&self) -> Point<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from `source`. Read more
§

impl<T> Debug for Point<T>where T: Debug,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<T> Default for Point<T>where T: Default,

§

fn default() -> Point<T>

Returns the “default value” for a type. Read more
§

impl<T> Deref for Point<T>

§

type Target = Vector<T>

The resulting type after dereferencing.
§

fn deref(&self) -> &<Point<T> as Deref>::Target

Dereferences the value.
§

impl<T> DerefMut for Point<T>

§

fn deref_mut(&mut self) -> &mut <Point<T> as Deref>::Target

Mutably dereferences the value.
§

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>,

Deserialize this value from the given Serde deserializer. Read more
§

impl<T> Display for Point<T>where T: Display,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<T> Div<T> for Point<T>where T: Copy + Div<T, Output = T>,

Scalar division.

§

type Output = Point<T>

The resulting type after applying the `/` operator.
§

fn div(self, rhs: T) -> Point<T>

Performs the `/` operation. Read more
§

impl<'a, T> From<&'a (T, T)> for Point<T>where T: Copy,

§

fn from(coords: &'a (T, T)) -> Point<T>

Converts to this type from the input type.
§

impl<'a, T> From<&'a Point<T>> for Point<T>where T: Copy,

§

fn from(v: &'a Point<T>) -> Point<T>

Converts to this type from the input type.
§

impl<T> From<&Point<T>> for Vector<T>where T: Copy,

§

fn from(p: &Point<T>) -> Vector<T>

Converts to this type from the input type.
§

impl<T> From<&Vector<T>> for Point<T>where T: Copy,

§

fn from(v: &Vector<T>) -> Point<T>

Converts to this type from the input type.
§

impl<T> From<[T; 2]> for Point<T>where T: Copy,

§

fn from(coords: [T; 2]) -> Point<T>

Converts to this type from the input type.
§

impl<T> From<(T, T)> for Point<T>where T: Copy,

§

fn from(coords: (T, T)) -> Point<T>

Converts to this type from the input type.
§

impl<T> From<Point<T>> for Geometry<T>

§

fn from(x: Point<T>) -> Geometry<T>

Converts to this type from the input type.
§

impl<T> From<Point<T>> for Vector<T>

§

fn from(p: Point<T>) -> Vector<T>

Converts to this type from the input type.
§

impl<T> From<Vector<T>> for Point<T>

§

fn from(v: Vector<T>) -> Point<T>

Converts to this type from the input type.
§

impl<T> Hash for Point<T>where T: Hash,

§

fn hash<__H>(&self, state: &mut __H)where __H: Hasher,

Feeds this value into the given `Hasher`. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given `Hasher`. Read more
§

impl<T> MapPointwise<T> for Point<T>where T: Copy,

Point wise transformation for a single point.

§

fn transform<F>(&self, transformation: F) -> Point<T>where F: Fn(Point<T>) -> Point<T>,

Point wise transformation.

§

impl<T> Mul<T> for Point<T>where T: Copy + Mul<T, Output = T>,

Scalar multiplication.

§

type Output = Point<T>

The resulting type after applying the `*` operator.
§

fn mul(self, rhs: T) -> Point<T>

Performs the `*` operation. Read more
§

impl<T> MulAssign<T> for Point<T>where T: Copy + MulAssign<T>,

In-place scalar multiplication.

§

fn mul_assign(&mut self, rhs: T)

Performs the `*=` operation. Read more
§

impl<T> Neg for Point<T>where T: Copy + Neg<Output = T>,

§

type Output = Point<T>

The resulting type after applying the `-` operator.
§

fn neg(self) -> Point<T>

Performs the unary `-` operation. Read more
§

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)`.

§

fn cmp(&self, rhs: &Point<T>) -> Ordering

This method returns an `Ordering` between `self` and `other`. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
§

impl<T> PartialEq<Point<T>> for Point<T>where T: PartialEq<T>,

§

fn eq(&self, other: &Point<T>) -> bool

This method tests for `self` and `other` values to be equal, and is used by `==`.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

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>

This method returns an ordering between `self` and `other` values if one exists. Read more
1.0.0 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more
§

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>

Construct a new point.
§

fn get(&self, orient: Orientation2D) -> <C as CoordinateBase>::Coord

Get a coordinate value.
§

fn set(&mut self, orient: Orientation2D, value: <C as CoordinateBase>::Coord)

Set a coordinate value.
§

fn x(&self) -> <C as CoordinateBase>::Coord

Get the x-coordinate value.
§

fn y(&self) -> <C as CoordinateBase>::Coord

Get the y-coordinate value.
§

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

Compute the x or y component of the vector from the point to the `other` point.
§

fn manhattan_distance( &self, other: &Self ) -> <C as CoordinateConcept>::CoordinateDifference

Compute the 1-norm of the vector pointing from the point to the other.
§

fn distance_squared( &self, other: &Self ) -> <C as CoordinateConcept>::CoordinateDistance

Squared euclidean distance.
§

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.
§

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,

Serialize this value into the given Serde serializer. Read more
§

impl<T> Sub<Point<T>> for Point<T>where T: Copy + Sub<T, Output = T>,

Subtract a point.

§

type Output = Vector<T>

The resulting type after applying the `-` operator.
§

fn sub(self, rhs: Point<T>) -> <Point<T> as Sub<Point<T>>>::Output

Performs the `-` operation. Read more
§

impl<T> Sub<Vector<T>> for Point<T>where T: Copy + Sub<T, Output = T>,

Subtract a vector.

§

type Output = Point<T>

The resulting type after applying the `-` operator.
§

fn sub(self, rhs: Vector<T>) -> <Point<T> as Sub<Vector<T>>>::Output

Performs the `-` operation. Read more
§

impl<T, V> SubAssign<V> for Point<T>where T: Copy + SubAssign<T>, V: Into<Vector<T>>,

§

fn sub_assign(&mut self, rhs: V)

Performs the `-=` operation. Read more
§

impl<T> Sum<Point<T>> for Point<T>where T: Copy + Zero<Output = T> + Add<T>,

§

fn sum<I>(iter: I) -> Point<T>where I: Iterator<Item = Point<T>>,

Compute the sum of all points in the iterator. If the iterator is empty, (0, 0) is returned.

§

impl<T> TryBoundingBox<T> for Point<T>where T: Copy,

§

fn try_bounding_box(&self) -> Option<Rect<T>>

Return the bounding box of this geometry if a bounding box is defined.
§

impl<T, Dst> TryCastCoord<T, Dst> for Point<T>where T: Copy + NumCast, Dst: Copy + NumCast,

§

type Output = Point<Dst>

Output type of the cast. This is likely the same geometrical type just with other coordinate types.
§

fn try_cast(&self) -> Option<<Point<T> as TryCastCoord<T, Dst>>::Output>

Try to cast to target data type. Read more
§

fn cast(&self) -> Self::Output

Cast to target data type. Read more
§

§

§

§

§

§

§

§

§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls `U::from(self)`.

That is, this conversion is whatever the implementation of `From<T> for U` chooses to do.

§

impl<S, T> Mirror<T> for Swhere T: Copy + Zero + Sub<T, Output = T>, S: MapPointwise<T>,

§

fn mirror_x(&self) -> S

Return the geometrical object mirrored at the `x` axis.

§

fn mirror_y(&self) -> S

Return the geometrical object mirrored at the `y` axis.

§

impl<S, T> RotateOrtho<T> for Swhere T: Copy + Zero + Sub<T, Output = T>, S: MapPointwise<T>,

§

fn rotate_ortho(&self, a: Angle) -> S

Rotate the geometrical shape by a multiple of 90 degrees.
§

impl<S, T> Scale<T> for Swhere T: Copy + Mul<T, Output = T>, S: MapPointwise<T>,

§

fn scale(&self, factor: T) -> S

Scale the geometrical shape. Scaling center is the origin `(0, 0)`.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a `String`. Read more
§

impl<S, T> Translate<T> for Swhere T: Copy + Add<T, Output = T>, S: MapPointwise<T>,

§

fn translate(&self, v: Vector<T>) -> S

Translate the geometrical object by a vector `v`.
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

source§

source§

§