Skip to main content

Scale

Struct Scale 

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

A stateless f64 data domain mapped to an f64 drawing-coordinate range.

Domain and range may ascend or descend but must have distinct finite endpoints. Logarithmic domains/values must be positive and their log endpoints distinct. Values extrapolate by default; Self::clamp bounds both mapping directions. Units are authored by the caller: this type does not convert meters to AU or add perspective, an orbital model, a clock, or previous-frame state.

use motion_content::diagram::Scale;
let scale = Scale::log10((0.1, 1000.0), (100.0, 860.0))?;
assert!((scale.map(10.0)? - 480.0).abs() < 0.001);
assert!((scale.invert(480.0)? - 10.0).abs() < 1e-10);

Implementations§

Source§

impl Scale

Source

pub fn linear( domain: (f64, f64), range: (f64, f64), ) -> Result<Self, ValidationError>

Validates a linear mapping; endpoints may run in either direction.

Source

pub fn log10( domain: (f64, f64), range: (f64, f64), ) -> Result<Self, ValidationError>

Validates a base-ten logarithmic mapping with positive domain endpoints.

Source

pub fn clamp(self, enabled: bool) -> Self

Replaces clamping for both map and invert; disabled by default. Nonpositive log inputs remain invalid even with clamping enabled.

Source

pub fn domain(self) -> (f64, f64)

Returns the original, ordered data endpoints, without unit conversion.

Source

pub fn range(self) -> (f64, f64)

Returns the ordered drawing-coordinate endpoints.

Source

pub fn map(self, value: f64) -> Result<f64, ValidationError>

Maps a finite data value to drawing coordinates, preserving endpoints exactly. Extrapolation that cannot be represented as a finite f64 returns an error.

Source

pub fn invert(self, coordinate: f64) -> Result<f64, ValidationError>

Maps finite drawing coordinates back into data units, with the same clamp policy.

Source

pub fn ticks(self, count: usize) -> Result<Vec<f64>, ValidationError>

Returns 2 through 256 uniformly spaced positions in transformed data space. Linear values are arithmetic; log values are geometric. Endpoints are exact. These are not automatically rounded “nice” ticks. Requests whose data values collapse at f64 precision fail rather than returning duplicates.

Source

pub fn nice_ticks(self, max_count: usize) -> Result<Vec<f64>, ValidationError>

Returns at most max_count aligned ticks without changing domain or range. Accepts 2..=256. Linear steps use 1, 2 or 5 times a power of ten; logarithmic steps use integer powers of ten, skipping decades when needed. Log domains containing fewer than two decade powers use linear nice steps. Endpoints are not forced; a narrow domain may yield zero or one tick. Unrepresentable steps/indices or collapsed values return an error.

Trait Implementations§

Source§

impl Clone for Scale

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Scale

Source§

impl Debug for Scale

Source§

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

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

impl PartialEq for Scale

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Scale

Auto Trait Implementations§

§

impl Forget for Scale

§

impl Freeze for Scale

§

impl Move for Scale

§

impl RefUnwindSafe for Scale

§

impl Send for Scale

§

impl Sync for Scale

§

impl Unpin for Scale

§

impl UnsafeUnpin for Scale

§

impl UnwindSafe for Scale

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.