Struct Point

Source
pub struct Point<const D: usize, T: ExtendedNumOps> {
    pub vec: [T; D],
}
Expand description

The basic input type for constructing and simplifying a polyline. It can have any number of components, and will work with components that implement the ExtendedNumOps type. Dimensionality must be determined at compile time.

This also implements some basic math operations between points, like:

  • addition
  • subtraction
  • component-wise multiplication
  • scalar multiplication

§Example

use simplify_polyline::*;

let point2d: Point<2, i32> = Point { vec: [1, 1] };
let another_point2d: Point<2, i32> = Point { vec: [2, 2] };

assert_eq!(point2d + another_point2d, Point { vec: [3, 3] });
assert_eq!(point2d - another_point2d, Point { vec: [-1, -1] });
assert_eq!(point2d * another_point2d, Point { vec: [2, 2] });
assert_eq!(point2d * 7, Point { vec: [7, 7] });

Fields§

§vec: [T; D]

The components of the point.

Implementations§

Source§

impl<const D: usize, T: ExtendedNumOps> Point<D, T>

Source

pub fn sq_dist(&self, other: &Point<D, T>) -> T

Computes the squared distance between two points.

Source

pub fn sq_dist_origin(&self) -> T

Computes the squared distance between this point, and the origin.

Source

pub fn value_sum(&self) -> T

Computes the sum of each value of the point.

Source

pub fn is_origin(&self) -> bool

Checks if the point is the origin point (all values at zero).

Trait Implementations§

Source§

impl<'a, 'b, const D: usize, T: ExtendedNumOps> Add<&'b Point<D, T>> for &'a Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the + operator.
Source§

fn add(self, other: &'b Point<D, T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<'b, const D: usize, T: ExtendedNumOps> Add<&'b Point<D, T>> for Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the + operator.
Source§

fn add(self, other: &'b Point<D, T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, const D: usize, T: ExtendedNumOps> Add<Point<D, T>> for &'a Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the + operator.
Source§

fn add(self, other: Point<D, T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<const D: usize, T: ExtendedNumOps> Add for Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<const D: usize, T: Clone + ExtendedNumOps> Clone for Point<D, T>

Source§

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

Returns a duplicate 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<const D: usize, T: Debug + ExtendedNumOps> Debug for Point<D, T>

Source§

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

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

impl<'a, 'b, const D: usize, T: ExtendedNumOps> Mul<&'b Point<D, T>> for &'a Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &'b Point<D, T>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'b, const D: usize, T: ExtendedNumOps> Mul<&'b Point<D, T>> for Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &'b Point<D, T>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, 'b, const D: usize, T: ExtendedNumOps> Mul<&'b T> for &'a Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &'b T) -> Self::Output

Performs the * operation. Read more
Source§

impl<'b, const D: usize, T: ExtendedNumOps> Mul<&'b T> for Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &'b T) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, const D: usize, T: ExtendedNumOps> Mul<Point<D, T>> for &'a Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Point<D, T>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, const D: usize, T: ExtendedNumOps> Mul<T> for &'a Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<const D: usize, T: ExtendedNumOps> Mul<T> for Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<const D: usize, T: ExtendedNumOps> Mul for Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<const D: usize, T: PartialEq + ExtendedNumOps> PartialEq for Point<D, T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, 'b, const D: usize, T: ExtendedNumOps> Sub<&'b Point<D, T>> for &'a Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the - operator.
Source§

fn sub(self, other: &'b Point<D, T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<'b, const D: usize, T: ExtendedNumOps> Sub<&'b Point<D, T>> for Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the - operator.
Source§

fn sub(self, other: &'b Point<D, T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<'a, const D: usize, T: ExtendedNumOps> Sub<Point<D, T>> for &'a Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<const D: usize, T: ExtendedNumOps> Sub for Point<D, T>

Source§

type Output = Point<D, T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<const D: usize, T: Copy + ExtendedNumOps> Copy for Point<D, T>

Source§

impl<const D: usize, T: Eq + ExtendedNumOps> Eq for Point<D, T>

Source§

impl<const D: usize, T: ExtendedNumOps> StructuralPartialEq for Point<D, T>

Auto Trait Implementations§

§

impl<const D: usize, T> Freeze for Point<D, T>
where T: Freeze,

§

impl<const D: usize, T> RefUnwindSafe for Point<D, T>
where T: RefUnwindSafe,

§

impl<const D: usize, T> Send for Point<D, T>
where T: Send,

§

impl<const D: usize, T> Sync for Point<D, T>
where T: Sync,

§

impl<const D: usize, T> Unpin for Point<D, T>
where T: Unpin,

§

impl<const D: usize, T> UnwindSafe for Point<D, T>
where 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

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.