#[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>
impl<T, Src, Dst> TypedScale<T, Src, Dst>
pub fn new(x: T) -> TypedScale<T, Src, Dst>
Source§impl<Src, Dst> TypedScale<f32, Src, Dst>
impl<Src, Dst> TypedScale<f32, Src, Dst>
Sourcepub const ONE: TypedScale<f32, Src, Dst>
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>
impl<T, Src, Dst> TypedScale<T, Src, Dst>
Sourcepub fn inv(&self) -> TypedScale<T, Dst, Src>
pub fn inv(&self) -> TypedScale<T, Dst, Src>
The inverse TypedScale (1.0 / self).
Source§impl<T, Src, Dst0> TypedScale<T, Src, Dst0>
impl<T, Src, Dst0> TypedScale<T, Src, Dst0>
Sourcepub fn cast<T1>(&self) -> TypedScale<T1, Src, Dst0>
pub fn cast<T1>(&self) -> TypedScale<T1, Src, Dst0>
Cast from one numeric representation to another, preserving the units.
Source§impl<T, Src, Dst> TypedScale<T, Src, Dst>
impl<T, Src, Dst> TypedScale<T, Src, Dst>
Sourcepub fn transform_point(
&self,
point: &TypedPoint2D<T, Src>,
) -> TypedPoint2D<T, Dst>
pub fn transform_point( &self, point: &TypedPoint2D<T, Src>, ) -> TypedPoint2D<T, Dst>
Returns the given point transformed by this scale.
Sourcepub fn transform_vector(
&self,
vec: &TypedVector2D<T, Src>,
) -> TypedVector2D<T, Dst>
pub fn transform_vector( &self, vec: &TypedVector2D<T, Src>, ) -> TypedVector2D<T, Dst>
Returns the given vector transformed by this scale.
Sourcepub fn transform_size(&self, size: &TypedSize2D<T, Src>) -> TypedSize2D<T, Dst>
pub fn transform_size(&self, size: &TypedSize2D<T, Src>) -> TypedSize2D<T, Dst>
Returns the given vector transformed by this scale.
Sourcepub fn transform_rect(&self, rect: &TypedRect<T, Src>) -> TypedRect<T, Dst>
pub fn transform_rect(&self, rect: &TypedRect<T, Src>) -> TypedRect<T, Dst>
Returns the given rect transformed by this scale.
Sourcepub fn inverse(&self) -> TypedScale<T, Dst, Src>
pub fn inverse(&self) -> TypedScale<T, Dst, Src>
Returns the inverse of this scale.
Sourcepub fn is_identity(&self) -> bool
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>
impl<T, Src, Dst> Add for TypedScale<T, Src, Dst>
Source§type Output = TypedScale<T, Src, Dst>
type Output = TypedScale<T, Src, Dst>
+
operator.Source§fn add(self, other: TypedScale<T, Src, Dst>) -> TypedScale<T, Src, Dst>
fn add(self, other: TypedScale<T, Src, Dst>) -> TypedScale<T, Src, Dst>
+
operation. Read moreSource§impl<T, Src, Dst> Clone for TypedScale<T, Src, Dst>where
T: Clone,
impl<T, Src, Dst> Clone for TypedScale<T, Src, Dst>where
T: Clone,
Source§fn clone(&self) -> TypedScale<T, Src, Dst>
fn clone(&self) -> TypedScale<T, Src, Dst>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T, Src, Dst> Debug for TypedScale<T, Src, Dst>where
T: Debug,
impl<T, Src, Dst> Debug for TypedScale<T, Src, Dst>where
T: Debug,
Source§impl<T, Src, Dst> Display for TypedScale<T, Src, Dst>where
T: Display,
impl<T, Src, Dst> Display for TypedScale<T, Src, Dst>where
T: Display,
Source§impl<Src, Dst, T> Div<TypedScale<T, Src, Dst>> for Length<T, Dst>
impl<Src, Dst, T> Div<TypedScale<T, Src, Dst>> for Length<T, Dst>
Source§impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedBox2D<T, U2>
impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedBox2D<T, U2>
Source§type Output = TypedBox2D<T, U1>
type Output = TypedBox2D<T, U1>
/
operator.Source§fn div(self, scale: TypedScale<T, U1, U2>) -> TypedBox2D<T, U1>
fn div(self, scale: TypedScale<T, U1, U2>) -> TypedBox2D<T, U1>
/
operation. Read moreSource§impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedBox3D<T, U2>
impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedBox3D<T, U2>
Source§type Output = TypedBox3D<T, U1>
type Output = TypedBox3D<T, U1>
/
operator.Source§fn div(self, scale: TypedScale<T, U1, U2>) -> TypedBox3D<T, U1>
fn div(self, scale: TypedScale<T, U1, U2>) -> TypedBox3D<T, U1>
/
operation. Read moreSource§impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedPoint2D<T, U2>
impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedPoint2D<T, U2>
Source§type Output = TypedPoint2D<T, U1>
type Output = TypedPoint2D<T, U1>
/
operator.Source§fn div(self, scale: TypedScale<T, U1, U2>) -> TypedPoint2D<T, U1>
fn div(self, scale: TypedScale<T, U1, U2>) -> TypedPoint2D<T, U1>
/
operation. Read moreSource§impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedPoint3D<T, U2>
impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedPoint3D<T, U2>
Source§type Output = TypedPoint3D<T, U1>
type Output = TypedPoint3D<T, U1>
/
operator.Source§fn div(self, scale: TypedScale<T, U1, U2>) -> TypedPoint3D<T, U1>
fn div(self, scale: TypedScale<T, U1, U2>) -> TypedPoint3D<T, U1>
/
operation. Read moreSource§impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedRect<T, U2>
impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedRect<T, U2>
Source§impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedSize2D<T, U2>
impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedSize2D<T, U2>
Source§type Output = TypedSize2D<T, U1>
type Output = TypedSize2D<T, U1>
/
operator.Source§fn div(self, scale: TypedScale<T, U1, U2>) -> TypedSize2D<T, U1>
fn div(self, scale: TypedScale<T, U1, U2>) -> TypedSize2D<T, U1>
/
operation. Read moreSource§impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedVector2D<T, U2>
impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedVector2D<T, U2>
Source§type Output = TypedVector2D<T, U1>
type Output = TypedVector2D<T, U1>
/
operator.Source§fn div(
self,
scale: TypedScale<T, U1, U2>,
) -> <TypedVector2D<T, U2> as Div<TypedScale<T, U1, U2>>>::Output
fn div( self, scale: TypedScale<T, U1, U2>, ) -> <TypedVector2D<T, U2> as Div<TypedScale<T, U1, U2>>>::Output
/
operation. Read moreSource§impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedVector3D<T, U2>
impl<T, U1, U2> Div<TypedScale<T, U1, U2>> for TypedVector3D<T, U2>
Source§type Output = TypedVector3D<T, U1>
type Output = TypedVector3D<T, U1>
/
operator.Source§fn div(
self,
scale: TypedScale<T, U1, U2>,
) -> <TypedVector3D<T, U2> as Div<TypedScale<T, U1, U2>>>::Output
fn div( self, scale: TypedScale<T, U1, U2>, ) -> <TypedVector3D<T, U2> as Div<TypedScale<T, U1, U2>>>::Output
/
operation. Read moreSource§impl<T, A, B, C> Mul<TypedScale<T, B, C>> for TypedScale<T, A, B>
impl<T, A, B, C> Mul<TypedScale<T, B, C>> for TypedScale<T, A, B>
Source§type Output = TypedScale<T, A, C>
type Output = TypedScale<T, A, C>
*
operator.Source§fn mul(self, other: TypedScale<T, B, C>) -> TypedScale<T, A, C>
fn mul(self, other: TypedScale<T, B, C>) -> TypedScale<T, A, C>
*
operation. Read moreSource§impl<Src, Dst, T> Mul<TypedScale<T, Src, Dst>> for Length<T, Src>
impl<Src, Dst, T> Mul<TypedScale<T, Src, Dst>> for Length<T, Src>
Source§impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedBox2D<T, U1>
impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedBox2D<T, U1>
Source§type Output = TypedBox2D<T, U2>
type Output = TypedBox2D<T, U2>
*
operator.Source§fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedBox2D<T, U2>
fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedBox2D<T, U2>
*
operation. Read moreSource§impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedBox3D<T, U1>
impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedBox3D<T, U1>
Source§type Output = TypedBox3D<T, U2>
type Output = TypedBox3D<T, U2>
*
operator.Source§fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedBox3D<T, U2>
fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedBox3D<T, U2>
*
operation. Read moreSource§impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedPoint2D<T, U1>
impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedPoint2D<T, U1>
Source§type Output = TypedPoint2D<T, U2>
type Output = TypedPoint2D<T, U2>
*
operator.Source§fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedPoint2D<T, U2>
fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedPoint2D<T, U2>
*
operation. Read moreSource§impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedPoint3D<T, U1>
impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedPoint3D<T, U1>
Source§type Output = TypedPoint3D<T, U2>
type Output = TypedPoint3D<T, U2>
*
operator.Source§fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedPoint3D<T, U2>
fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedPoint3D<T, U2>
*
operation. Read moreSource§impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedRect<T, U1>
impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedRect<T, U1>
Source§impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedSize2D<T, U1>
impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedSize2D<T, U1>
Source§type Output = TypedSize2D<T, U2>
type Output = TypedSize2D<T, U2>
*
operator.Source§fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedSize2D<T, U2>
fn mul(self, scale: TypedScale<T, U1, U2>) -> TypedSize2D<T, U2>
*
operation. Read moreSource§impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedVector2D<T, U1>
impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedVector2D<T, U1>
Source§type Output = TypedVector2D<T, U2>
type Output = TypedVector2D<T, U2>
*
operator.Source§fn mul(
self,
scale: TypedScale<T, U1, U2>,
) -> <TypedVector2D<T, U1> as Mul<TypedScale<T, U1, U2>>>::Output
fn mul( self, scale: TypedScale<T, U1, U2>, ) -> <TypedVector2D<T, U1> as Mul<TypedScale<T, U1, U2>>>::Output
*
operation. Read moreSource§impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedVector3D<T, U1>
impl<T, U1, U2> Mul<TypedScale<T, U1, U2>> for TypedVector3D<T, U1>
Source§type Output = TypedVector3D<T, U2>
type Output = TypedVector3D<T, U2>
*
operator.Source§fn mul(
self,
scale: TypedScale<T, U1, U2>,
) -> <TypedVector3D<T, U1> as Mul<TypedScale<T, U1, U2>>>::Output
fn mul( self, scale: TypedScale<T, U1, U2>, ) -> <TypedVector3D<T, U1> as Mul<TypedScale<T, U1, U2>>>::Output
*
operation. Read moreSource§impl<T, Src, Dst> PartialEq for TypedScale<T, Src, Dst>where
T: PartialEq,
impl<T, Src, Dst> PartialEq for TypedScale<T, Src, Dst>where
T: PartialEq,
Source§impl<T, Src, Dst> Sub for TypedScale<T, Src, Dst>
impl<T, Src, Dst> Sub for TypedScale<T, Src, Dst>
Source§type Output = TypedScale<T, Src, Dst>
type Output = TypedScale<T, Src, Dst>
-
operator.Source§fn sub(self, other: TypedScale<T, Src, Dst>) -> TypedScale<T, Src, Dst>
fn sub(self, other: TypedScale<T, Src, Dst>) -> TypedScale<T, Src, Dst>
-
operation. Read more