Used foo.0 tuple access notation instead of let Au(a) = a;

This commit is contained in:
Simon Sapin 2015-05-05 18:42:02 +02:00
parent b1ecba9f3d
commit 4f618c45a5

View file

@ -129,9 +129,7 @@ impl Add for Au {
#[inline] #[inline]
fn add(self, other: Au) -> Au { fn add(self, other: Au) -> Au {
let Au(s) = self; Au(self.0.wrapping_add(other.0))
let Au(o) = other;
Au(s.wrapping_add(o))
} }
} }
@ -140,9 +138,7 @@ impl Sub for Au {
#[inline] #[inline]
fn sub(self, other: Au) -> Au { fn sub(self, other: Au) -> Au {
let Au(s) = self; Au(self.0.wrapping_sub(other.0))
let Au(o) = other;
Au(s.wrapping_sub(o))
} }
} }
@ -152,8 +148,7 @@ impl Mul<i32> for Au {
#[inline] #[inline]
fn mul(self, other: i32) -> Au { fn mul(self, other: i32) -> Au {
let Au(s) = self; Au(self.0.wrapping_mul(other))
Au(s.wrapping_mul(other))
} }
} }
@ -162,8 +157,7 @@ impl Div<i32> for Au {
#[inline] #[inline]
fn div(self, other: i32) -> Au { fn div(self, other: i32) -> Au {
let Au(s) = self; Au(self.0 / other)
Au(s / other)
} }
} }
@ -172,8 +166,7 @@ impl Rem<i32> for Au {
#[inline] #[inline]
fn rem(self, other: i32) -> Au { fn rem(self, other: i32) -> Au {
let Au(s) = self; Au(self.0 % other)
Au(s % other)
} }
} }
@ -182,8 +175,7 @@ impl Neg for Au {
#[inline] #[inline]
fn neg(self) -> Au { fn neg(self) -> Au {
let Au(s) = self; Au(-self.0)
Au(-s)
} }
} }
@ -196,8 +188,7 @@ impl Au {
#[inline] #[inline]
pub fn scale_by(self, factor: f32) -> Au { pub fn scale_by(self, factor: f32) -> Au {
let Au(s) = self; Au(((self.0 as f32) * factor) as i32)
Au(((s as f32) * factor) as i32)
} }
#[inline] #[inline]
@ -213,48 +204,41 @@ impl Au {
/// Rounds this app unit down to the pixel towards zero and returns it. /// Rounds this app unit down to the pixel towards zero and returns it.
#[inline] #[inline]
pub fn to_px(&self) -> i32 { pub fn to_px(&self) -> i32 {
let Au(a) = *self; self.0 / 60
(a / 60)
} }
/// Rounds this app unit down to the previous (left or top) pixel and returns it. /// Rounds this app unit down to the previous (left or top) pixel and returns it.
#[inline] #[inline]
pub fn to_prev_px(&self) -> i32 { pub fn to_prev_px(&self) -> i32 {
let Au(s) = *self; ((self.0 as f64) / 60f64).floor() as i32
((s as f64) / 60f64).floor() as i32
} }
/// Rounds this app unit up to the next (right or bottom) pixel and returns it. /// Rounds this app unit up to the next (right or bottom) pixel and returns it.
#[inline] #[inline]
pub fn to_next_px(&self) -> i32 { pub fn to_next_px(&self) -> i32 {
let Au(s) = *self; ((self.0 as f64) / 60f64).ceil() as i32
((s as f64) / 60f64).ceil() as i32
} }
#[inline] #[inline]
pub fn to_nearest_px(&self) -> i32 { pub fn to_nearest_px(&self) -> i32 {
let Au(s) = *self; ((self.0 as f64) / 60f64).round() as i32
((s as f64) / 60f64).round() as i32
} }
#[inline] #[inline]
pub fn to_f32_px(&self) -> f32 { pub fn to_f32_px(&self) -> f32 {
let Au(s) = *self; (self.0 as f32) / 60f32
(s as f32) / 60f32
} }
#[inline] #[inline]
pub fn to_f64_px(&self) -> f64 { pub fn to_f64_px(&self) -> f64 {
let Au(s) = *self; (self.0 as f64) / 60f64
(s as f64) / 60f64
} }
#[inline] #[inline]
pub fn to_snapped(&self) -> Au { pub fn to_snapped(&self) -> Au {
let Au(s) = *self; let res = self.0 % 60i32;
let res = s % 60i32; return if res >= 30i32 { return Au(self.0 - res + 60i32) }
return if res >= 30i32 { return Au(s - res + 60i32) } else { return Au(self.0 - res) };
else { return Au(s - res) };
} }
#[inline] #[inline]