From 1e3217e8042ae7fda1f4fa6c9ba1884c62597748 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 8 Sep 2017 13:33:21 -0700 Subject: [PATCH] Bug 1341102 - Revendor rust deps; r=bustage MozReview-Commit-ID: 2EcVsnJ5VFN --- .../rust/app_units/.cargo-checksum.json | 2 +- third_party/rust/app_units/Cargo.toml | 12 ++++++------ third_party/rust/app_units/src/app_unit.rs | 18 +++++++++++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/third_party/rust/app_units/.cargo-checksum.json b/third_party/rust/app_units/.cargo-checksum.json index f0394858dc0d..9dfaf88aaab5 100644 --- a/third_party/rust/app_units/.cargo-checksum.json +++ b/third_party/rust/app_units/.cargo-checksum.json @@ -1 +1 @@ -{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".travis.yml":"6b96b2c6bfd7e1acef4b825a2813fc4277859eb9400a16800db8835c25e4087d","Cargo.toml":"1648e6342e3879aaf3add2a9341915ca1650037df830907dc1e2b768aa087036","README.md":"9f048d969f9f8333cdcdb892744cd0816e4f2922c8817fa5e9e07f9472fe1050","src/app_unit.rs":"7e75ca0ad78d26c6538029c7ddae650f7b76c2f7210735e6da6e52920494fdb4","src/lib.rs":"2df7d863c47d8b22f9af66caeafa87e6a206ee713a8aeaa55c5a80a42a92513b"},"package":"7ff4f3fe57393a150b39b026b6f6f4b9a6c4f49b52d0a4e2d61d08d926358438"} \ No newline at end of file +{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".travis.yml":"6b96b2c6bfd7e1acef4b825a2813fc4277859eb9400a16800db8835c25e4087d","Cargo.toml":"41d47153a6043d3e4599f827888e1ac43c204e52ed5f6998b1e275fcae21a3cc","README.md":"9f048d969f9f8333cdcdb892744cd0816e4f2922c8817fa5e9e07f9472fe1050","src/app_unit.rs":"0f4fde2c0481b6dd021f48c8ef548090e7c577c02c429c41626c2b5e7a006949","src/lib.rs":"2df7d863c47d8b22f9af66caeafa87e6a206ee713a8aeaa55c5a80a42a92513b"},"package":"ed0a4de09a3b8449515e649f3bb84f72ea15fc2d10639beb0776a09b7d308074"} \ No newline at end of file diff --git a/third_party/rust/app_units/Cargo.toml b/third_party/rust/app_units/Cargo.toml index 9e1659edbad0..5fbe898f8e4e 100644 --- a/third_party/rust/app_units/Cargo.toml +++ b/third_party/rust/app_units/Cargo.toml @@ -12,20 +12,20 @@ [package] name = "app_units" -version = "0.5.3" +version = "0.5.6" authors = ["The Servo Project Developers"] description = "Servo app units type (Au)" documentation = "http://doc.servo.org/app_units/" license = "MPL-2.0" repository = "https://github.com/servo/app_units" -[dependencies.serde] -version = "1.0" +[dependencies.rustc-serialize] +version = "0.3" [dependencies.num-traits] version = "0.1.32" -[dependencies.rustc-serialize] -version = "0.3" - [dependencies.heapsize] version = ">=0.3, < 0.5" + +[dependencies.serde] +version = "1.0" diff --git a/third_party/rust/app_units/src/app_unit.rs b/third_party/rust/app_units/src/app_unit.rs index 9b850316cbce..60ea8d49b100 100644 --- a/third_party/rust/app_units/src/app_unit.rs +++ b/third_party/rust/app_units/src/app_unit.rs @@ -189,17 +189,24 @@ impl Au { #[inline] fn clamp_self(&mut self) { - *self = self.clamp() + *self = Au::clamp(*self) } #[inline] pub fn scale_by(self, factor: f32) -> Au { let new_float = ((self.0 as f64) * factor as f64).round(); - Au::clamp_from_f64_au(new_float) + Au::from_f64_au(new_float) } #[inline] - fn clamp_from_f64_au(float: f64) -> Self { + /// Scale, but truncate (useful for viewport-relative units) + pub fn scale_by_trunc(self, factor: f32) -> Au { + let new_float = ((self.0 as f64) * factor as f64).trunc(); + Au::from_f64_au(new_float) + } + + #[inline] + pub fn from_f64_au(float: f64) -> Self { // We *must* operate in f64. f32 isn't precise enough // to handle MAX_AU Au(float.min(MAX_AU.0 as f64) @@ -247,13 +254,13 @@ impl Au { #[inline] pub fn from_f32_px(px: f32) -> Au { let float = (px * AU_PER_PX as f32).round(); - Au::clamp_from_f64_au(float as f64) + Au::from_f64_au(float as f64) } #[inline] pub fn from_f64_px(px: f64) -> Au { let float = (px * AU_PER_PX as f64).round(); - Au::clamp_from_f64_au(float) + Au::from_f64_au(float) } #[inline] @@ -303,6 +310,7 @@ fn scale() { assert_eq!(Au(12).scale_by(1.5), Au(18)); assert_eq!(Au(12).scale_by(1.7), Au(20)); assert_eq!(Au(12).scale_by(1.8), Au(22)); + assert_eq!(Au(12).scale_by_trunc(1.8), Au(21)); } #[test]