Skip to main content

Point

Struct Point 

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

A 2D point with x and y coordinates, each carrying their own unit of measurement.

Implementations§

Source§

impl Point

Source

pub const fn integer(x: i32, y: i32, units: f64) -> Self

Creates a point with integer coordinates and the given units.

Source

pub const fn float(x: f64, y: f64, units: f64) -> Self

Creates a point with float coordinates and the given units.

Source

pub fn origin() -> Self

Creates a point at the origin (0, 0) with default integer units.

Source

pub const fn default_integer(x: i32, y: i32) -> Self

Creates a point with integer coordinates and default integer units (1e-9).

Source

pub const fn default_float(x: f64, y: f64) -> Self

Creates a point with float coordinates and default float units (1e-6).

Source

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

Create a point with two arbitrary units.

This is useful for when you want to create a point with different units. This is not highly recommended.

Source

pub const fn units(&self) -> (f64, f64)

Returns the units for both coordinates as (x_units, y_units).

Source

pub const fn set_units(&self, units: f64) -> Self

Returns a copy of this point with both coordinates set to the given units (without scaling).

Source

pub fn scale_units(&self, new_units: f64) -> Self

Returns a copy of this point with both coordinates scaled to the given units.

Source

pub const fn x(&self) -> Unit

Gets the x coordinate of the point.

Source

pub const fn y(&self) -> Unit

Gets the y coordinate of the point.

Source

pub const fn set_x(&mut self, x: Unit)

Sets the x coordinate of the point.

Source

pub const fn set_y(&mut self, y: Unit)

Sets the y coordinate of the point.

Source

pub fn to_integer_unit(&self) -> Self

Converts both coordinates to integer units.

§Returns

A new Point with both x and y coordinates converted to Unit::Integer

Source

pub fn to_float_unit(&self) -> Self

Converts both coordinates to float units.

§Returns

A new Point with both x and y coordinates converted to Unit::Float

Source

pub fn rotate_around_point(&self, angle: AngleInRadians, center: &Self) -> Self

Rotates the point around an arbitrary center point by the given angle in radians.

§Arguments
  • center - The center point to rotate around
  • angle - The rotation angle in radians (positive = counter-clockwise)
§Returns

A new Point representing the rotated position

Trait Implementations§

Source§

impl Add<Point> for &Point

Source§

type Output = Point

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for Point

Source§

type Output = Point

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Clone for Point

Source§

fn clone(&self) -> Point

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 Debug for Point

Source§

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

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

impl Default for Point

Source§

fn default() -> Point

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

impl Display for Point

Source§

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

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

impl Div<f64> for Point

Source§

type Output = Point

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Div<i32> for Point

Source§

type Output = Point

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Div<u32> for Point

Source§

type Output = Point

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Movable for Point

Source§

fn move_to(self, target: Point) -> Self

Moves the value to the given absolute target point.
Source§

fn move_by(self, delta: Point) -> Self

Moves the value by the given delta (relative translation).
Source§

impl Mul<f64> for Point

Source§

type Output = Point

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<i32> for Point

Source§

type Output = Point

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<u32> for Point

Source§

type Output = Point

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl PartialEq for Point

Source§

fn eq(&self, other: &Point) -> 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 Sub for Point

Source§

type Output = Point

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Transformable for Point

Source§

fn transform_impl(self, transformation: &Transformation) -> Self

Applies a transformation reference and returns the transformed value.
Source§

fn transform(self, transformation: impl Into<Transformation>) -> Self

Applies a transformation and returns the transformed value.
Source§

fn rotate(self, angle: AngleInRadians, centre: Point) -> Self

Rotates by the given angle (in radians) around the centre point.
Source§

fn scale(self, factor: f64, centre: Point) -> Self

Scales by the given factor around the centre point.
Source§

fn reflect(self, angle: f64, centre: Point) -> Self

Reflects across the axis defined by the given angle (in radians) through the centre point.
Source§

fn translate(self, delta: Point) -> Self

Translates by the given delta point.
Source§

impl Copy for Point

Source§

impl StructuralPartialEq for Point

Auto Trait Implementations§

§

impl Freeze for Point

§

impl RefUnwindSafe for Point

§

impl Send for Point

§

impl Sync for Point

§

impl Unpin for Point

§

impl UnsafeUnpin for Point

§

impl UnwindSafe for Point

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<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.