Skip to content

Commit

Permalink
Bump app_units; use from_f64_au
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Sep 8, 2017
1 parent 812cac7 commit 489bbb8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/style/Cargo.toml
Expand Up @@ -29,7 +29,7 @@ servo = ["serde", "heapsize", "heapsize_derive",
gecko_debug = ["nsstring_vendor/gecko_debug"]

[dependencies]
app_units = "0.5.3"
app_units = "0.5.5"
arrayvec = "0.3.20"
arraydeque = "0.2.3"
atomic_refcell = "0.1"
Expand Down
32 changes: 13 additions & 19 deletions components/style/values/specified/length.rs
Expand Up @@ -6,7 +6,7 @@
//!
//! [length]: https://drafts.csswg.org/css-values/#lengths

use app_units::{Au, MAX_AU, MIN_AU};
use app_units::Au;
use cssparser::{Parser, Token, BasicParseError};
use euclid::Size2D;
use font_metrics::FontMetricsQueryResult;
Expand Down Expand Up @@ -236,16 +236,6 @@ impl CharacterWidth {
}
}

/// Helper to convert a floating point length to application units
fn to_au_round(length: CSSFloat, au_per_unit: CSSFloat) -> Au {
Au(
((length * au_per_unit) as f64)
.min(MAX_AU.0 as f64)
.max(MIN_AU.0 as f64)
.round() as i32
)
}

/// Represents an absolute length with its unit
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
Expand Down Expand Up @@ -292,16 +282,20 @@ impl ToComputedValue for AbsoluteLength {
}
}

fn au_from_f32_round(x: f32) -> Au {
Au::from_f64_au((x as f64).round())
}

impl From<AbsoluteLength> for Au {
fn from(length: AbsoluteLength) -> Au {
match length {
AbsoluteLength::Px(value) => to_au_round(value, AU_PER_PX),
AbsoluteLength::In(value) => to_au_round(value, AU_PER_IN),
AbsoluteLength::Cm(value) => to_au_round(value, AU_PER_CM),
AbsoluteLength::Mm(value) => to_au_round(value, AU_PER_MM),
AbsoluteLength::Q(value) => to_au_round(value, AU_PER_Q),
AbsoluteLength::Pt(value) => to_au_round(value, AU_PER_PT),
AbsoluteLength::Pc(value) => to_au_round(value, AU_PER_PC),
AbsoluteLength::Px(value) => au_from_f32_round((value * AU_PER_PX)),
AbsoluteLength::In(value) => au_from_f32_round((value * AU_PER_IN)),
AbsoluteLength::Cm(value) => au_from_f32_round((value * AU_PER_CM)),
AbsoluteLength::Mm(value) => au_from_f32_round((value * AU_PER_MM)),
AbsoluteLength::Q(value) => au_from_f32_round((value * AU_PER_Q)),
AbsoluteLength::Pt(value) => au_from_f32_round((value * AU_PER_PT)),
AbsoluteLength::Pc(value) => au_from_f32_round((value * AU_PER_PC)),
}
}
}
Expand Down Expand Up @@ -360,7 +354,7 @@ impl PhysicalLength {

let inch = self.0 / MM_PER_INCH;

to_au_round(inch, physical_inch as f32)
au_from_f32_round(inch * physical_inch as f32)
}
}

Expand Down

0 comments on commit 489bbb8

Please sign in to comment.