Skip to main content

Dim

Struct Dim 

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

TeX-style dimension: width, height, depth, italic correction, mu.

One unit is one em at the current math style unless a method says otherwise.

§Examples

use latex_rust::Dim;

let half = Dim::ratio(1, 2);
assert!(half.eq_dim(&(&Dim::one() / &Dim::from_i64(2))));
assert!(!Dim::zero().eq_dim(&Dim::one()));

Implementations§

Source§

impl Dim

Source

pub fn zero() -> Self

Zero em.

Source

pub fn one() -> Self

One em.

Source

pub fn from_i64(v: i64) -> Self

Integer em count.

Source

pub fn ratio(num: i64, den: i64) -> Self

Exact rational num / den em. den == 0 yields NaN.

Source

pub fn parse(s: &str) -> Self

Parse a decimal string (optional sign, fraction, e exponent).

Source

pub fn from_font_units(units: i64, units_per_em: u16) -> Self

Convert integer font units to em: units / units_per_em.

Source

pub fn mu() -> Self

One math unit (mu). TeX: 18 mu = 1 em.

Source

pub fn to_mu(&self) -> Self

Convert this em value to mu (* 18).

Source

pub fn from_mu(mu: &Self) -> Self

Convert a mu value to em (/ 18).

Source

pub fn abs(&self) -> Self

Absolute value.

Source

pub fn max(&self, other: &Self) -> Self

Maximum of two dimensions.

Source

pub fn min(&self, other: &Self) -> Self

Minimum of two dimensions.

Source

pub fn clamp_nonneg(&self) -> Self

max(self, 0).

Source

pub fn is_nan(&self) -> bool

True when the value is NaN.

Source

pub fn is_zero(&self) -> bool

True when the value compares equal to zero.

Source

pub fn as_ratio(&self) -> Option<(i128, i128)>

The exact rational value in em, as (numerator, denominator), or None if this dimension is NaN.

The denominator is positive and the fraction is in lowest terms. This is the only accessor that does not round: Self::to_dec_string formats a decimal expansion and Self::to_ieee32_bits rounds to binary32. An external renderer that wants to convert at its own pixel boundary, rather than take the crate’s rounding, should start here.

§Examples
use latex_rust::Dim;

assert_eq!(Dim::ratio(2, 6).as_ratio(), Some((1, 3)));
assert_eq!(Dim::ratio(1, -2).as_ratio(), Some((-1, 2)));
assert_eq!(Dim::zero().as_ratio(), Some((0, 1)));
assert_eq!(Dim::ratio(1, 0).as_ratio(), None);
Source

pub fn to_dec_string(&self) -> String

Decimal string (exact terminating expansion, or scientific).

Source

pub fn to_svg_string(&self) -> String

Compact decimal for SVG attributes.

Source

pub fn from_ieee32_bits(bits: u32) -> Self

Layout dimension from an IEEE-754 binary32 bit pattern (outline boundary).

Source

pub fn to_ieee32_bits(&self) -> u32

Round to IEEE-754 binary32 bits for PNG / raster emission only.

Source

pub fn floor_to_u32(&self) -> Result<u32, Error>

Largest u32 that is not greater than self. Negative and NaN fail.

Source

pub fn ceil_to_u32(&self) -> Result<u32, Error>

Smallest u32 that is not less than self.

Source

pub fn cmp(&self, other: &Self) -> Option<Ordering>

Compare two dimensions. None if either is NaN.

Source

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

True when self and other compare equal.

Trait Implementations§

Source§

impl Add for Dim

Source§

type Output = Dim

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Dim) -> Dim

Performs the + operation. Read more
Source§

impl Add for &Dim

Source§

type Output = Dim

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Dim) -> Dim

Performs the + operation. Read more
Source§

impl Add<&Dim> for Dim

Source§

type Output = Dim

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Dim) -> Dim

Performs the + operation. Read more
Source§

impl Add<Dim> for &Dim

Source§

type Output = Dim

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Dim) -> Dim

Performs the + operation. Read more
Source§

impl Clone for Dim

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

Source§

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

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

impl Display for Dim

Source§

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

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

impl Div for Dim

Source§

type Output = Dim

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Dim) -> Dim

Performs the / operation. Read more
Source§

impl Div for &Dim

Source§

type Output = Dim

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Dim) -> Dim

Performs the / operation. Read more
Source§

impl Div<&Dim> for Dim

Source§

type Output = Dim

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Dim) -> Dim

Performs the / operation. Read more
Source§

impl Div<Dim> for &Dim

Source§

type Output = Dim

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Dim) -> Dim

Performs the / operation. Read more
Source§

impl Eq for Dim

Source§

impl Mul for Dim

Source§

type Output = Dim

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dim) -> Dim

Performs the * operation. Read more
Source§

impl Mul for &Dim

Source§

type Output = Dim

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Dim) -> Dim

Performs the * operation. Read more
Source§

impl Mul<&Dim> for Dim

Source§

type Output = Dim

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Dim) -> Dim

Performs the * operation. Read more
Source§

impl Mul<Dim> for &Dim

Source§

type Output = Dim

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dim) -> Dim

Performs the * operation. Read more
Source§

impl Neg for Dim

Source§

type Output = Dim

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Dim

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 PartialOrd for Dim

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub for Dim

Source§

type Output = Dim

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Dim) -> Dim

Performs the - operation. Read more
Source§

impl Sub for &Dim

Source§

type Output = Dim

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Dim) -> Dim

Performs the - operation. Read more
Source§

impl Sub<&Dim> for Dim

Source§

type Output = Dim

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Dim) -> Dim

Performs the - operation. Read more
Source§

impl Sub<Dim> for &Dim

Source§

type Output = Dim

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Dim) -> Dim

Performs the - operation. Read more

Auto Trait Implementations§

§

impl Freeze for Dim

§

impl RefUnwindSafe for Dim

§

impl Send for Dim

§

impl Sync for Dim

§

impl Unpin for Dim

§

impl UnsafeUnpin for Dim

§

impl UnwindSafe for Dim

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> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

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

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.