Skip to main content

Point

Struct Point 

Source
pub struct Point<T> { /* private fields */ }
Expand description

A point is defined by a x and y coordinate in the euclidean plane.

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 vec2(&self) -> Vec2<T>

Source

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

Source

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

Source§

impl<T: Zero> Point<T>

Source

pub fn zero() -> Self

Get zero-Point.

§Examples
use reda_geometry::shape::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 reda_geometry::shape::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 reda_geometry::shape::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 vec2s 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 reda_geometry::shape::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 = Vec2<T>>§

Source

pub fn is_zero(&self) -> bool

Source

pub fn norm1(&self) -> T

Get 1-norm of vec2, i.e. the sum of the absolute values of its components.

§Examples
use reda_geometry::base::Vec2;
let a = Vec2::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 reda_geometry::base::Vec2;
use reda_geometry::base::Orientation;

let a = Vec2::new(1, 0);
let b = Vec2::new(1, 1);
let c = Vec2::new(1, -1);
let d = Vec2::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 cross_prod(&self, other: Self) -> T

Calculate cross product.

§Examples
use reda_geometry::base::Vec2;

let a = Vec2::new(2, 0);
let b = Vec2::new(0, 2);

assert_eq!(a.cross_prod(b), 4);
assert_eq!(b.cross_prod(a), -4);
Source

pub fn norm2_squared(&self) -> T

Get squared 2-norm of vec2.

§Examples
use reda_geometry::base::Vec2;
let a = Vec2::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 reda_geometry::base::Vec2;

let a = Vec2::new(1, 2);
let b = Vec2::new(3, 4);

assert_eq!(a.dot(b), 1*3 + 2*4);
Source

pub fn norm2(&self) -> T

Get 2-norm of vec2 (length of vec2).

§Examples
use reda_geometry::base::Vec2;
let a = Vec2::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 vec2 with the same direction but length 1.

§Panics

Panics if the vec2 has length 0.

Source

pub fn length<F: Float>(&self) -> F

Calculate length of vec2.

Similar to Vec2::norm2 but does potentially return another data type for the length.

§Examples
use reda_geometry::base::Vec2;
let a = Vec2::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);
Source

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

Convert vec2 into a vec2 with floating point data type.

Trait Implementations§

Source§

impl<T, V> Add<V> for Point<T>
where T: Copy + Add<Output = T>, V: Into<Point<T>>,

Source§

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

Source§

impl<Src: Copy + NumCast, Dst: Copy + NumCast> Cast<Src, Dst> for Point<Src>

Source§

type Output = Point<Dst>

Source§

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

Source§

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

Source§

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

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

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() -> Self

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

impl<T> Deref for Point<T>

Source§

type Target = Vec2<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<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.

Source§

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<T: Eq> Eq for Point<T>

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

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: Copy> From<&Vec2<T>> for Point<T>

Source§

fn from(v: &Vec2<T>) -> 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> From<Point<T>> for Vec2<T>

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: 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> 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<Vec2<T>> for Point<T>

Source§

fn from(v: Vec2<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: 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> MapPoint<T> for Point<T>

Source§

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

Source§

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

Source§

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

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

Source§

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 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

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

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: PartialOrd> PartialOrd 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 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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

Source§

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

Source§

type Output = Vec2<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<Vec2<T>> for Point<T>
where T: Copy + Sub<Output = T>,

Source§

type Output = Point<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

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

Source§

fn sub_assign(&mut self, rhs: V)

Performs the -= operation. Read more
Source§

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

Source§

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

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

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

Auto Trait Implementations§

§

impl<T> Freeze for Point<T>
where Vec2<T>: Freeze,

§

impl<T> RefUnwindSafe for Point<T>
where Vec2<T>: RefUnwindSafe,

§

impl<T> Send for Point<T>
where Vec2<T>: Send,

§

impl<T> Sync for Point<T>
where Vec2<T>: Sync,

§

impl<T> Unpin for Point<T>
where Vec2<T>: Unpin,

§

impl<T> UnsafeUnpin for Point<T>
where Vec2<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for Point<T>
where Vec2<T>: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<S, T> Mirror<T> for S
where T: Copy + Zero + Sub<Output = T>, S: MapPoint<T>,

Source§

fn mirror_x(&self) -> S

Source§

fn mirror_y(&self) -> S

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<S, T> Rotate<T> for S
where T: Copy + Zero + Sub<Output = T>, S: MapPoint<T>,

Source§

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

Source§

impl<S, T> Scale<T> for S
where T: Copy + Mul<Output = T>, S: MapPoint<T>,

Source§

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

Source§

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

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

impl<S, T> Translate<T> for S
where T: Copy + Add<Output = T>, S: MapPoint<T>,

Source§

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

Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.