Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "app_units"
version = "0.7.7"
version = "0.7.8"
authors = ["The Servo Project Developers"]
description = "Servo app units type (Au)"
documentation = "https://docs.rs/app_units/"
Expand Down
28 changes: 28 additions & 0 deletions src/app_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ impl Au {
Au::from_f64_au(float)
}

#[inline]
pub fn from_f32_px_trunc(px: f32) -> Au {
let float = (px * AU_PER_PX as f32).trunc();
Au::from_f64_au(float as f64)
}

#[inline]
pub fn from_f64_px_trunc(px: f64) -> Au {
let float = (px * AU_PER_PX as f64).trunc();
Au::from_f64_au(float)
}

#[inline]
pub fn abs(self) -> Self {
Au(self.0.abs())
Expand Down Expand Up @@ -412,6 +424,22 @@ fn convert() {
assert_eq!(Au::from_f64_px(6.), Au(360));
assert_eq!(Au::from_f64_px(6.12), Au(367));
assert_eq!(Au::from_f64_px(6.13), Au(368));

assert_eq!(Au::from_f32_px_trunc(5.0), Au(300));
assert_eq!(Au::from_f32_px_trunc(5.2), Au(312));
assert_eq!(Au::from_f32_px_trunc(5.5), Au(330));
assert_eq!(Au::from_f32_px_trunc(5.8), Au(348));
assert_eq!(Au::from_f32_px_trunc(6.), Au(360));
assert_eq!(Au::from_f32_px_trunc(6.12), Au(367));
assert_eq!(Au::from_f32_px_trunc(6.13), Au(367));

assert_eq!(Au::from_f64_px_trunc(5.), Au(300));
assert_eq!(Au::from_f64_px_trunc(5.2), Au(312));
assert_eq!(Au::from_f64_px_trunc(5.5), Au(330));
assert_eq!(Au::from_f64_px_trunc(5.8), Au(348));
assert_eq!(Au::from_f64_px_trunc(6.), Au(360));
assert_eq!(Au::from_f64_px_trunc(6.12), Au(367));
assert_eq!(Au::from_f64_px_trunc(6.13), Au(367));
}

#[test]
Expand Down
Loading