Struct visioncortex::Point2

source ·
pub struct Point2<T> {
    pub x: T,
    pub y: T,
}
Expand description

Generic point in 2D space

Fields§

§x: T§y: T

Implementations§

source§

impl<T> Point2<T>

source

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

source§

impl<T> Point2<T>
where T: Add<Output = T> + Mul<Output = T>,

source

pub fn dot(self, v: Self) -> T

source§

impl<T> Point2<T>
where T: Add<Output = T>,

source

pub fn translate(self, vector: Self) -> Self

source§

impl<T> Point2<T>
where T: Add<Output = T> + Copy + Neg<Output = T> + Sub<Output = T>,

source

pub fn rotate_90deg(&self, origin: Self, clockwise: bool) -> Self

Assumes a coordinate system with origin at the top-left. The behavior is undefined otherwise.

source§

impl<T> Point2<T>
where T: Float,

source

pub fn rotate(&self, origin: Self, angle: T) -> Self

source

pub fn norm(self) -> T

The L2-norm

source

pub fn distance_to(&self, other: Point2<T>) -> T

The euclidean distance

source§

impl<T> Point2<T>
where T: Default + Float,

source

pub fn get_normalized(&self) -> Self

source§

impl Point2<i32>

source§

impl Point2<f64>

source

pub fn to_point_i32(&self) -> PointI32

source

pub fn to_point_f32(&self) -> PointF32

Trait Implementations§

source§

impl<T> Add for Point2<T>
where T: Add<Output = T>,

§

type Output = Point2<T>

The resulting type after applying the + operator.
source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
source§

impl<T> AddAssign for Point2<T>
where T: AddAssign,

source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
source§

impl<T: Clone> Clone for Point2<T>

source§

fn clone(&self) -> Point2<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<F> Coordinate for Point2<F>
where F: Add<Output = F> + Copy + Default + Float + From<f64> + Into<f64> + Mul<f64, Output = F> + PartialEq + Sub<Output = F>,

source§

fn from_components(components: &[f64]) -> Self

Creates a new coordinate from the specified set of components
source§

fn origin() -> Self

Returns the origin coordinate
source§

fn len() -> usize

The number of components in this coordinate
source§

fn get(&self, index: usize) -> f64

Retrieves the component at the specified index
source§

fn from_biggest_components(p1: Self, p2: Self) -> Self

Returns a point made up of the biggest components of the two points
source§

fn from_smallest_components(p1: Self, p2: Self) -> Self

Returns a point made up of the smallest components of the two points
source§

fn distance_to(&self, target: &Self) -> f64

Computes the distance between this coordinate and another of the same type
source§

fn dot(&self, target: &Self) -> f64

Computes the dot product for this vector along with another vector
source§

fn magnitude(&self) -> f64

Computes the magnitude of this vector
source§

fn to_unit_vector(&self) -> Self

Treating this as a vector, returns a unit vector in the same direction
source§

fn is_nan(&self) -> bool

Returns true if this coordinate has a NaN component
source§

fn round(self, accuracy: f64) -> Self

Round this coordinate so that it is accurate to a certain precision
source§

fn is_near_to(&self, other: &Self, max_distance: f64) -> bool

True if this point is within max_distance of another point
source§

fn smooth(points: &[Self], weights: &[f64]) -> Vec<Self>

Generates a smoothed version of a set of coordinates, using the specified weights (weights should add up to 1.0). Read more
source§

impl<F> Coordinate2D for Point2<F>
where F: Copy + Into<f64>,

source§

fn x(&self) -> f64

source§

fn y(&self) -> f64

source§

fn coords(&self) -> (f64, f64)

source§

impl<T: Debug> Debug for Point2<T>

source§

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

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

impl<T: Default> Default for Point2<T>

source§

fn default() -> Point2<T>

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

impl<T, F> Div<F> for Point2<T>
where T: Div<F, Output = T>, F: Float,

§

type Output = Point2<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: F) -> Self::Output

Performs the / operation. Read more
source§

impl<T, F> DivAssign<F> for Point2<T>
where T: DivAssign<F>, F: Float,

source§

fn div_assign(&mut self, rhs: F)

Performs the /= operation. Read more
source§

impl<T: Hash> Hash for Point2<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, F> Mul<F> for Point2<T>
where T: Mul<F, Output = T>, F: Float,

§

type Output = Point2<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T, F> MulAssign<F> for Point2<T>
where T: MulAssign<F>, F: Float,

source§

fn mul_assign(&mut self, rhs: F)

Performs the *= operation. Read more
source§

impl<T> Neg for Point2<T>
where T: Neg<Output = T>,

§

type Output = Point2<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<T: PartialEq> PartialEq for Point2<T>

source§

fn eq(&self, other: &Point2<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> Sub for Point2<T>
where T: Sub<Output = T>,

§

type Output = Point2<T>

The resulting type after applying the - operator.
source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
source§

impl<T> SubAssign for Point2<T>
where T: SubAssign,

source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
source§

impl<T> ToSvgString for Point2<T>
where T: Copy + NumberFormat,

source§

fn to_svg_string(&self, precision: Option<u32>) -> String

source§

impl<T: Copy> Copy for Point2<T>

source§

impl<T: Eq> Eq for Point2<T>

source§

impl<T> StructuralPartialEq for Point2<T>

Auto Trait Implementations§

§

impl<T> Freeze for Point2<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Point2<T>
where T: RefUnwindSafe,

§

impl<T> Send for Point2<T>
where T: Send,

§

impl<T> Sync for Point2<T>
where T: Sync,

§

impl<T> Unpin for Point2<T>
where T: Unpin,

§

impl<T> UnwindSafe for Point2<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> 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<Point> Normalize for Point
where Point: Coordinate2D,

source§

fn to_normal(_point: &Point, tangent: &Point) -> Vec<f64>

Computes the normal at a point, given its tangent
source§

impl<T> ToOwned for T
where 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.