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> Point<T>

source

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

Create a new point with x and y coordinates.

source§

impl<T: Copy> Point<T>

source

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

Return the location of this point as a vector.

source

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

Get a specific coordinate of the point.

source

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

Set a specific coordinate of the point.

source§

impl<T: Zero> Point<T>

source

pub fn zero() -> Self

Get zero-Point.

Examples
use iron_shapes::point::Point;

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

assert_eq!(a, b);
source

pub fn is_zero(&self) -> bool

Check if this is the zero-Point.

Examples
use iron_shapes::point::*;

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

impl<T: Copy + Mul<Output = T> + Add<Output = T> + Sub<Output = T>> Point<T>

source

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

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 selfab 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));
source§

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

source

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

Compute the Euclidean distance betwen two points.

source§

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

source

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

Convert Point into a Point with floating point data type.

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

source

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

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

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

pub fn dot(&self, other: Self) -> 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);
source

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

pub fn cast_to_float<F: CoordinateType + Float + NumCast>(&self) -> Vector<F>

Convert vector into a vector with floating point data type.

source

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

pub fn normalized(&self) -> Self

Return a vector with the same direction but length 1.

Panics

Panics if the vector has length 0.

source

pub fn normal(&self) -> Self

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

Panics

Panics if the vector has length 0.

source

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

Point addition.

§

type Output = Point<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: V) -> Self

Performs the + operation. Read more
source§

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)

Performs the += operation. Read more
source§

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

source§

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

Return the bounding box of this geometry.
source§

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

source§

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

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

source§

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

Formats the value using the given formatter. Read more
source§

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

source§

fn default() -> Point<T>

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

impl<T> Deref for Point<T>

§

type Target = Vector<T>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T> DerefMut for Point<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

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

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

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

source§

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

Formats the value using the given formatter. Read more
source§

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

Scalar division.

§

type Output = Point<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self

Performs the / operation. Read more
source§

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

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

source§

fn from(coords: (T, T)) -> Self

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

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

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

Point wise transformation for a single point.

source§

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

Point wise transformation.

source§

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

Scalar multiplication.

§

type Output = Point<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Self

Performs the * operation. Read more
source§

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

In-place scalar multiplication.

source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
source§

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

§

type Output = Point<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

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§

fn cmp(&self, rhs: &Self) -> 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
source§

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

source§

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

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

source§

fn partial_cmp(&self, rhs: &Self) -> 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
source§

impl<C> PointBase<C> for Point<C::Coord>where C: CoordinateBase,

source§

fn new(x: C::Coord, y: C::Coord) -> Self

Construct a new point.
source§

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

Get a coordinate value.
source§

fn set(&mut self, orient: Orientation2D, value: C::Coord)

Set a coordinate value.
source§

fn x(&self) -> C::Coord

Get the x-coordinate value.
source§

fn y(&self) -> C::Coord

Get the y-coordinate value.
source§

impl<C> PointConcept<C> for Point<C::Coord>where C: CoordinateConcept,

source§

fn projected_distance( &self, other: &Self, orient: Orientation2D ) -> C::CoordinateDifference

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

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

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

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

Squared euclidean distance.
source§

fn euclidian_distance(&self, other: &Self) -> C::CoordinateDistance

Euclidean distance, i.e. 2-norm of the vector from the point to the other.
source§

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

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

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

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

Subtract a point.

§

type Output = Vector<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

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

Subtract a vector.

§

type Output = Point<T>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Vector<T>) -> Self::Output

Performs the - operation. Read more
source§

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)

Performs the -= operation. Read more
source§

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

source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

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

source§

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

source§

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

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

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

§

type Output = Point<Dst>

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

fn try_cast(&self) -> Option<Self::Output>

Try to cast to target data type. Read more
source§

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

Cast to target data type. Read more
source§

impl<T: Copy> Copy for Point<T>

source§

impl<T: Eq> Eq for Point<T>

source§

impl<T> StructuralEq for Point<T>

source§

impl<T> StructuralPartialEq for Point<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§

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.

source§

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

source§

fn mirror_x(&self) -> S

Return the geometrical object mirrored at the x axis.

source§

fn mirror_y(&self) -> S

Return the geometrical object mirrored at the y axis.

source§

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

source§

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

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

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

source§

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

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

source§

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§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

source§

impl<T> TextType for Twhere T: Eq + Hash + Clone + Debug,