Auto merge of #17696 - jyc:image-orientation-redux, r=Manishearth

Sync Servo / Gecko image-orientation rounding; pass as enum.

Make Servo's rounding of image-orientation values agree with Gecko's,
and pass orientations directly as an enum instead of as angles.

Depends on a Gecko change to be subsequently landed in m-c.

Were reviewed here: https://reviewboard.mozilla.org/r/155336/

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix [Bugzilla Bug 1355380](https://bugzilla.mozilla.org/show_bug.cgi?id=1355380) (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because they

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17696)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-07-14 18:54:45 -07:00 committed by GitHub
commit 3fb309c755
4 changed files with 85 additions and 29 deletions

View file

@ -13,7 +13,8 @@ use media_queries::Device;
use properties;
use properties::{ComputedValues, StyleBuilder};
use std::f32;
use std::f32::consts::PI;
use std::f64;
use std::f64::consts::PI;
use std::fmt;
use style_traits::ToCss;
use super::{CSSFloat, CSSInteger, RGBA};
@ -313,17 +314,27 @@ impl Angle {
/// Return the amount of radians this angle represents.
#[inline]
pub fn radians(&self) -> CSSFloat {
const RAD_PER_DEG: CSSFloat = PI / 180.0;
const RAD_PER_GRAD: CSSFloat = PI / 200.0;
const RAD_PER_TURN: CSSFloat = PI * 2.0;
self.radians64().min(f32::MAX as f64).max(f32::MIN as f64) as f32
}
/// Return the amount of radians this angle represents as a 64-bit float.
/// Gecko stores angles as singles, but does this computation using doubles.
/// See nsCSSValue::GetAngleValueInRadians.
/// This is significant enough to mess up rounding to the nearest
/// quarter-turn for 225 degrees, for example.
#[inline]
pub fn radians64(&self) -> f64 {
const RAD_PER_DEG: f64 = PI / 180.0;
const RAD_PER_GRAD: f64 = PI / 200.0;
const RAD_PER_TURN: f64 = PI * 2.0;
let radians = match *self {
Angle::Degree(val) => val * RAD_PER_DEG,
Angle::Gradian(val) => val * RAD_PER_GRAD,
Angle::Turn(val) => val * RAD_PER_TURN,
Angle::Radian(val) => val,
Angle::Degree(val) => val as f64 * RAD_PER_DEG,
Angle::Gradian(val) => val as f64 * RAD_PER_GRAD,
Angle::Turn(val) => val as f64 * RAD_PER_TURN,
Angle::Radian(val) => val as f64,
};
radians.min(f32::MAX).max(f32::MIN)
radians.min(f64::MAX).max(f64::MIN)
}
/// Returns an angle that represents a rotation of zero radians.