A few clean ups for Au type

This commit is contained in:
Glenn Watson 2015-09-28 15:51:21 +10:00
parent 7a3d2c8cb4
commit 5684a75187
3 changed files with 25 additions and 51 deletions

View file

@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::ToCss;
use euclid::length::Length;
use euclid::num::Zero;
use euclid::point::Point2D;
use euclid::rect::Rect;
@ -205,29 +204,12 @@ impl Au {
Au((px * AU_PER_PX) as i32)
}
#[inline]
pub fn from_page_px(px: Length<PagePx, f32>) -> Au {
Au((px.get() * (AU_PER_PX as f32)) as i32)
}
/// Rounds this app unit down to the pixel towards zero and returns it.
#[inline]
pub fn to_px(self) -> i32 {
self.0 / AU_PER_PX
}
/// Rounds this app unit down to the previous (left or top) pixel and returns it.
#[inline]
pub fn to_prev_px(self) -> i32 {
((self.0 as f64) / (AU_PER_PX as f64)).floor() as i32
}
/// Rounds this app unit up to the next (right or bottom) pixel and returns it.
#[inline]
pub fn to_next_px(self) -> i32 {
((self.0 as f64) / (AU_PER_PX as f64)).ceil() as i32
}
#[inline]
pub fn to_nearest_px(self) -> i32 {
((self.0 as f64) / (AU_PER_PX as f64)).round() as i32
@ -248,39 +230,17 @@ impl Au {
(self.0 as f64) / (AU_PER_PX as f64)
}
#[inline]
pub fn to_snapped(self) -> Au {
let res = self.0 % AU_PER_PX;
return if res >= 30i32 { return Au(self.0 - res + AU_PER_PX) }
else { return Au(self.0 - res) };
}
#[inline]
pub fn from_f32_px(px: f32) -> Au {
Au((px * (AU_PER_PX as f32)) as i32)
}
#[inline]
pub fn from_pt(pt: f64) -> Au {
Au::from_f64_px(pt_to_px(pt))
}
#[inline]
pub fn from_f64_px(px: f64) -> Au {
Au((px * (AU_PER_PX as f64)) as i32)
}
}
// assumes 72 points per inch, and 96 px per inch
pub fn pt_to_px(pt: f64) -> f64 {
pt / 72. * 96.
}
// assumes 72 points per inch, and 96 px per inch
pub fn px_to_pt(px: f64) -> f64 {
px / 96. * 72.
}
/// Returns true if the rect contains the given point. Points on the top or left sides of the rect
/// are considered inside the rectangle, while points on the right or bottom sides of the rect are
/// not considered inside the rectangle.