pub struct ScaleFactor(pub f64);Expand description
Scale factor for converting between logical and physical coordinates.
Common values:
- 1.0: Standard DPI (96 DPI on Windows, 72 DPI on macOS historically)
- 2.0: Retina/HiDPI displays
- 1.5, 1.25: Common Windows scaling factors
§Safety
The scale factor must be positive (greater than 0). Methods like inverse()
and coordinate conversions will produce infinity or NaN if the scale is 0.
Use try_new() or is_valid() to validate scale factors from untrusted input.
§Example
use astrelis_core::geometry::ScaleFactor;
let scale = ScaleFactor(2.0);
assert_eq!(scale.0, 2.0);
assert_eq!(scale.inverse().0, 0.5);
// Validate scale factors from user input
let scale = ScaleFactor::try_new(2.0).expect("Invalid scale");Tuple Fields§
§0: f64Implementations§
Source§impl ScaleFactor
impl ScaleFactor
Sourcepub const fn new(scale: f64) -> Self
pub const fn new(scale: f64) -> Self
Create a new scale factor.
§Panics
In debug builds, panics if the scale is not positive (> 0) or is NaN. In release builds, invalid values may cause division by zero or NaN propagation.
Sourcepub fn try_new(scale: f64) -> Option<Self>
pub fn try_new(scale: f64) -> Option<Self>
Try to create a new scale factor, returning None if invalid.
Returns None if:
- The scale is zero or negative
- The scale is NaN or infinity
§Example
use astrelis_core::geometry::ScaleFactor;
assert!(ScaleFactor::try_new(2.0).is_some());
assert!(ScaleFactor::try_new(0.0).is_none());
assert!(ScaleFactor::try_new(-1.0).is_none());
assert!(ScaleFactor::try_new(f64::NAN).is_none());Trait Implementations§
Source§impl Clone for ScaleFactor
impl Clone for ScaleFactor
Source§fn clone(&self) -> ScaleFactor
fn clone(&self) -> ScaleFactor
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ScaleFactor
impl Debug for ScaleFactor
Source§impl Default for ScaleFactor
impl Default for ScaleFactor
Source§impl From<ScaleFactor> for f32
impl From<ScaleFactor> for f32
Source§fn from(scale: ScaleFactor) -> Self
fn from(scale: ScaleFactor) -> Self
Converts to this type from the input type.
Source§impl From<ScaleFactor> for f64
impl From<ScaleFactor> for f64
Source§fn from(scale: ScaleFactor) -> Self
fn from(scale: ScaleFactor) -> Self
Converts to this type from the input type.
Source§impl From<f32> for ScaleFactor
impl From<f32> for ScaleFactor
Source§impl From<f64> for ScaleFactor
impl From<f64> for ScaleFactor
Source§impl PartialEq for ScaleFactor
impl PartialEq for ScaleFactor
Source§impl PartialOrd for ScaleFactor
impl PartialOrd for ScaleFactor
impl Copy for ScaleFactor
impl StructuralPartialEq for ScaleFactor
Auto Trait Implementations§
impl Freeze for ScaleFactor
impl RefUnwindSafe for ScaleFactor
impl Send for ScaleFactor
impl Sync for ScaleFactor
impl Unpin for ScaleFactor
impl UnsafeUnpin for ScaleFactor
impl UnwindSafe for ScaleFactor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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