Struct TypedScale

Source
#[repr(C)]
pub struct TypedScale<T, Src, Dst>(pub T, _);
Expand description

A scaling factor between two different units of measurement.

This is effectively a type-safe float, intended to be used in combination with other types like length::Length to enforce conversion between systems of measurement at compile time.

Src and Dst represent the units before and after multiplying a value by a TypedScale. They may be types without values, such as empty enums. For example:

use euclid::TypedScale;
use euclid::Length;
enum Mm {};
enum Inch {};

let mm_per_inch: TypedScale<f32, Inch, Mm> = TypedScale::new(25.4);

let one_foot: Length<f32, Inch> = Length::new(12.0);
let one_foot_in_mm: Length<f32, Mm> = one_foot * mm_per_inch;

Tuple Fields§

§0: T

Implementations§

Source§

impl<T, Src, Dst> TypedScale<T, Src, Dst>

Source

pub fn new(x: T) -> TypedScale<T, Src, Dst>

Source§

impl<T, Src, Dst> TypedScale<T, Src, Dst>
where T: Clone,

Source

pub fn get(&self) -> T

Source§

impl<Src, Dst> TypedScale<f32, Src, Dst>

Source

pub const ONE: TypedScale<f32, Src, Dst>

Identity scaling, could be used to safely transit from one space to another.

Source§

impl<T, Src, Dst> TypedScale<T, Src, Dst>
where T: Clone + One + Div<Output = T>,

Source

pub fn inv(&self) -> TypedScale<T, Dst, Src>

The inverse TypedScale (1.0 / self).

Source§

impl<T, Src, Dst0> TypedScale<T, Src, Dst0>
where T: NumCast + Clone,

Source

pub fn cast<T1>(&self) -> TypedScale<T1, Src, Dst0>
where T1: NumCast + Clone,

Cast from one numeric representation to another, preserving the units.

Source

pub fn try_cast<T1>(&self) -> Option<TypedScale<T1, Src, Dst0>>
where T1: NumCast + Clone,

Fallible cast from one numeric representation to another, preserving the units.

Source§

impl<T, Src, Dst> TypedScale<T, Src, Dst>
where T: Copy + Clone + Mul<Output = T> + Neg<Output = T> + PartialEq + One,

Source

pub fn transform_point( &self, point: &TypedPoint2D<T, Src>, ) -> TypedPoint2D<T, Dst>

Returns the given point transformed by this scale.

Source

pub fn transform_vector( &self, vec: &TypedVector2D<T, Src>, ) -> TypedVector2D<T, Dst>

Returns the given vector transformed by this scale.

Source

pub fn transform_size(&self, size: &TypedSize2D<T, Src>) -> TypedSize2D<T, Dst>

Returns the given vector transformed by this scale.

Source

pub fn transform_rect(&self, rect: &TypedRect<T, Src>) -> TypedRect<T, Dst>

Returns the given rect transformed by this scale.

Source

pub fn inverse(&self) -> TypedScale<T, Dst, Src>

Returns the inverse of this scale.

Source

pub fn is_identity(&self) -> bool

Returns true if this scale has no effect.

Trait Implementations§

Source§

impl<T, Src, Dst> Add for TypedScale<T, Src, Dst>
where T: Clone + Add<Output = T>,

Source§

type Output = TypedScale<T, Src, Dst>

The resulting type after applying the + operator.
Source§

fn add(self, other: TypedScale<T, Src, Dst>) -> TypedScale<T, Src, Dst>

Performs the + operation. Read more
Source§

impl<T, Src, Dst> Clone for TypedScale<T, Src, Dst>
where T: Clone,

Source§

fn clone(&self) -> TypedScale<T, Src, Dst>

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<T, Src, Dst> Debug for TypedScale<T, Src, Dst>
where T: Debug,

Source§

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

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

impl<T, Src, Dst> Display for TypedScale<T, Src, Dst>
where T: Display,

Source§

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

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

impl<Src, Dst, T> Div<TypedScale<T, Src, Dst>> for Length<T, Dst>
where T: Clone + Div<Output = T>,

Source§

type Output = Length<T, Src>

The resulting type after applying the / operator.
Source§

fn div(self, scale: TypedScale<T, Src, Dst>) -> Length<T, Src>

Performs the / operation. Read more
Source§

impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedBox2D<T, U2>
where T: Copy + Div<Output = T>,

Source§

type Output = TypedBox2D<T, U1>

The resulting type after applying the / operator.
Source§

fn div(self, scale: TypedScale<T, U1, U2>) -> TypedBox2D<T, U1>

Performs the / operation. Read more
Source§

impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedBox3D<T, U2>
where T: Copy + Div<Output = T>,

Source§

type Output = TypedBox3D<T, U1>

The resulting type after applying the / operator.
Source§

fn div(self, scale: TypedScale<T, U1, U2>) -> TypedBox3D<T, U1>

Performs the / operation. Read more
Source§

impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedPoint2D<T, U2>
where T: Copy + Div<Output = T>,

Source§

type Output = TypedPoint2D<T, U1>

The resulting type after applying the / operator.
Source§

fn div(self, scale: TypedScale<T, U1, U2>) -> TypedPoint2D<T, U1>

Performs the / operation. Read more
Source§

impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedPoint3D<T, U2>
where T: Copy + Div<Output = T>,

Source§

type Output = TypedPoint3D<T, U1>

The resulting type after applying the / operator.
Source§

fn div(self, scale: TypedScale<T, U1, U2>) -> TypedPoint3D<T, U1>

Performs the / operation. Read more
Source§

impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedRect<T, U2>
where T: Copy + Div<Output = T>,

Source§

type Output = TypedRect<T, U1>

The resulting type after applying the / operator.
Source§

fn div(self, scale: TypedScale<T, U1, U2>) -> TypedRect<T, U1>

Performs the / operation. Read more
Source§

impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedSize2D<T, U2>
where T: Copy + Div<Output = T>,

Source§

type Output = TypedSize2D<T, U1>

The resulting type after applying the / operator.
Source§

fn div(self, scale: TypedScale<T, U1, U2>) -> TypedSize2D<T, U1>

Performs the / operation. Read more
Source§

impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedVector2D<T, U2>
where T: Copy + Div<Output = T>,

Source§

type Output = TypedVector2D<T, U1>

The resulting type after applying the / operator.
Source§

fn div( self, scale: TypedScale<T, U1, U2>, ) -> <TypedVector2D<T, U2> as Div<TypedScale<T, U1, U2>>>::Output

Performs the / operation. Read more
Source§

impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedVector3D<T, U2>
where T: Copy + Div<Output = T>,

Source§

type Output = TypedVector3D<T, U1>

The resulting type after applying the / operator.
Source§

fn div( self, scale: TypedScale<T, U1, U2>, ) -> <TypedVector3D<T, U2> as Div<TypedScale<T, U1, U2>>>::Output

Performs the / operation. Read more
Source§

impl<T, A, B, C> Mul<TypedScale<T, B, C>> for TypedScale<T, A, B>
where T: Clone + Mul<Output = T>,

Source§

type Output = TypedScale<T, A, C>

The resulting type after applying the * operator.
Source§

fn mul(self, other: TypedScale<T, B, C>) -> TypedScale<T, A, C>

Performs the * operation. Read more
Source§

impl<Src, Dst, T> Mul<TypedScale<T, Src, Dst>> for Length<T, Src>
where T: Clone + Mul<Output = T>,

Source§

type Output = Length<T, Dst>

The resulting type after applying the * operator.
Source§

fn mul(self, scale: TypedScale<T, Src, Dst>) -> Length<T, Dst>

Performs the * operation. Read more
Source§

impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedBox2D<T, U1>
where T: Copy + Mul<Output = T>,

Source§

type Output = TypedBox2D<T, U2>

The resulting type after applying the * operator.
Source§

fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedBox2D<T, U2>

Performs the * operation. Read more
Source§

impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedBox3D<T, U1>
where T: Copy + Mul<Output = T>,

Source§

type Output = TypedBox3D<T, U2>

The resulting type after applying the * operator.
Source§

fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedBox3D<T, U2>

Performs the * operation. Read more
Source§

impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedPoint2D<T, U1>
where T: Copy + Mul<Output = T>,

Source§

type Output = TypedPoint2D<T, U2>

The resulting type after applying the * operator.
Source§

fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedPoint2D<T, U2>

Performs the * operation. Read more
Source§

impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedPoint3D<T, U1>
where T: Copy + Mul<Output = T>,

Source§

type Output = TypedPoint3D<T, U2>

The resulting type after applying the * operator.
Source§

fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedPoint3D<T, U2>

Performs the * operation. Read more
Source§

impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedRect<T, U1>
where T: Copy + Mul<Output = T>,

Source§

type Output = TypedRect<T, U2>

The resulting type after applying the * operator.
Source§

fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedRect<T, U2>

Performs the * operation. Read more
Source§

impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedSize2D<T, U1>
where T: Copy + Mul<Output = T>,

Source§

type Output = TypedSize2D<T, U2>

The resulting type after applying the * operator.
Source§

fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedSize2D<T, U2>

Performs the * operation. Read more
Source§

impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedVector2D<T, U1>
where T: Copy + Mul<Output = T>,

Source§

type Output = TypedVector2D<T, U2>

The resulting type after applying the * operator.
Source§

fn mul( self, scale: TypedScale<T, U1, U2>, ) -> <TypedVector2D<T, U1> as Mul<TypedScale<T, U1, U2>>>::Output

Performs the * operation. Read more
Source§

impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedVector3D<T, U1>
where T: Copy + Mul<Output = T>,

Source§

type Output = TypedVector3D<T, U2>

The resulting type after applying the * operator.
Source§

fn mul( self, scale: TypedScale<T, U1, U2>, ) -> <TypedVector3D<T, U1> as Mul<TypedScale<T, U1, U2>>>::Output

Performs the * operation. Read more
Source§

impl<T, Src, Dst> PartialEq for TypedScale<T, Src, Dst>
where T: PartialEq,

Source§

fn eq(&self, other: &TypedScale<T, Src, Dst>) -> 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, Src, Dst> Sub for TypedScale<T, Src, Dst>
where T: Clone + Sub<Output = T>,

Source§

type Output = TypedScale<T, Src, Dst>

The resulting type after applying the - operator.
Source§

fn sub(self, other: TypedScale<T, Src, Dst>) -> TypedScale<T, Src, Dst>

Performs the - operation. Read more
Source§

impl<T, Src, Dst> Copy for TypedScale<T, Src, Dst>
where T: Copy,

Auto Trait Implementations§

§

impl<T, Src, Dst> Freeze for TypedScale<T, Src, Dst>
where T: Freeze,

§

impl<T, Src, Dst> RefUnwindSafe for TypedScale<T, Src, Dst>

§

impl<T, Src, Dst> Send for TypedScale<T, Src, Dst>
where T: Send, Src: Send, Dst: Send,

§

impl<T, Src, Dst> Sync for TypedScale<T, Src, Dst>
where T: Sync, Src: Sync, Dst: Sync,

§

impl<T, Src, Dst> Unpin for TypedScale<T, Src, Dst>
where T: Unpin, Src: Unpin, Dst: Unpin,

§

impl<T, Src, Dst> UnwindSafe for TypedScale<T, Src, Dst>
where T: UnwindSafe, Src: UnwindSafe, Dst: 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> 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.