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

Source§

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,

Source§

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,

Source§

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

Source§

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

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<T> Sub for Point2<T>
where T: Sub<Output = T>,

Source§

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

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.