swf: Inline `Twips` methods
This commit is contained in:
parent
1f22f868a0
commit
49ea1b0f36
|
@ -46,6 +46,7 @@ impl Twips {
|
|||
///
|
||||
/// let twips = Twips::new(40);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub const fn new(twips: i32) -> Self {
|
||||
Self(twips)
|
||||
}
|
||||
|
@ -60,6 +61,7 @@ impl Twips {
|
|||
/// let twips = Twips::new(47);
|
||||
/// assert_eq!(twips.get(), 47);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub const fn get(self) -> i32 {
|
||||
self.0
|
||||
}
|
||||
|
@ -81,11 +83,13 @@ impl Twips {
|
|||
/// let twips = Twips::from_pixels(40.018);
|
||||
/// assert_eq!(twips.get(), 800);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn from_pixels(pixels: f64) -> Self {
|
||||
Self((pixels * Self::TWIPS_PER_PIXEL as f64) as i32)
|
||||
}
|
||||
|
||||
/// Converts the given number of `pixels` into twips.
|
||||
#[inline]
|
||||
pub const fn from_pixels_i32(pixels: i32) -> Self {
|
||||
Self(pixels * Self::TWIPS_PER_PIXEL)
|
||||
}
|
||||
|
@ -107,6 +111,7 @@ impl Twips {
|
|||
/// let twips = Twips::new(713);
|
||||
/// assert_eq!(twips.to_pixels(), 35.65);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn to_pixels(self) -> f64 {
|
||||
f64::from(self.0) / Self::TWIPS_PER_PIXEL as f64
|
||||
}
|
||||
|
@ -114,12 +119,14 @@ impl Twips {
|
|||
|
||||
impl std::ops::Add for Twips {
|
||||
type Output = Self;
|
||||
#[inline]
|
||||
fn add(self, other: Self) -> Self {
|
||||
Self(self.0 + other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::AddAssign for Twips {
|
||||
#[inline]
|
||||
fn add_assign(&mut self, other: Self) {
|
||||
self.0 += other.0
|
||||
}
|
||||
|
@ -127,12 +134,14 @@ impl std::ops::AddAssign for Twips {
|
|||
|
||||
impl std::ops::Sub for Twips {
|
||||
type Output = Self;
|
||||
#[inline]
|
||||
fn sub(self, other: Self) -> Self {
|
||||
Self(self.0 - other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::SubAssign for Twips {
|
||||
#[inline]
|
||||
fn sub_assign(&mut self, other: Self) {
|
||||
self.0 -= other.0
|
||||
}
|
||||
|
@ -140,12 +149,14 @@ impl std::ops::SubAssign for Twips {
|
|||
|
||||
impl std::ops::Mul<i32> for Twips {
|
||||
type Output = Self;
|
||||
#[inline]
|
||||
fn mul(self, other: i32) -> Self {
|
||||
Self(self.0 * other)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::MulAssign<i32> for Twips {
|
||||
#[inline]
|
||||
fn mul_assign(&mut self, other: i32) {
|
||||
self.0 *= other
|
||||
}
|
||||
|
@ -153,12 +164,14 @@ impl std::ops::MulAssign<i32> for Twips {
|
|||
|
||||
impl std::ops::Div<i32> for Twips {
|
||||
type Output = Self;
|
||||
#[inline]
|
||||
fn div(self, other: i32) -> Self {
|
||||
Self(self.0 / other)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DivAssign<i32> for Twips {
|
||||
#[inline]
|
||||
fn div_assign(&mut self, other: i32) {
|
||||
self.0 /= other
|
||||
}
|
||||
|
@ -166,12 +179,14 @@ impl std::ops::DivAssign<i32> for Twips {
|
|||
|
||||
impl std::ops::Neg for Twips {
|
||||
type Output = Self;
|
||||
#[inline]
|
||||
fn neg(self) -> Self {
|
||||
Twips(-self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Twips {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "{}", self.to_pixels())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue