diff options
author | Pyfisch <pyfisch@gmail.com> | 2018-01-17 23:17:39 +0100 |
---|---|---|
committer | Pyfisch <pyfisch@gmail.com> | 2018-01-17 23:29:57 +0100 |
commit | af52233ae57af8c05eab1f60f208cf5b42a832bd (patch) | |
tree | a63d1f9a157595244252aff28e06319539e3e025 /components/geometry/lib.rs | |
parent | 8c7c5f6e79c4709807d254a6367fb546f6f8e186 (diff) | |
download | servo-af52233ae57af8c05eab1f60f208cf5b42a832bd.tar.gz servo-af52233ae57af8c05eab1f60f208cf5b42a832bd.zip |
Introduce MaxRect trait
It is implemented for LayoutRect and Rect<Au>.
Replaces the max_rect() function from servo_geometry.
Diffstat (limited to 'components/geometry/lib.rs')
-rw-r--r-- | components/geometry/lib.rs | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/components/geometry/lib.rs b/components/geometry/lib.rs index 61ded7c67d3..c22c9d16055 100644 --- a/components/geometry/lib.rs +++ b/components/geometry/lib.rs @@ -6,9 +6,12 @@ extern crate app_units; extern crate euclid; extern crate malloc_size_of; #[macro_use] extern crate malloc_size_of_derive; +extern crate webrender_api; use app_units::{Au, MAX_AU, MIN_AU}; use euclid::{Point2D, Rect, Size2D}; +use std::f32; +use webrender_api::{LayoutPoint, LayoutRect, LayoutSize}; // Units for use with euclid::length and euclid::scale_factor. @@ -32,9 +35,27 @@ pub enum DeviceIndependentPixel {} // originally proposed in 2002 as a standard unit of measure in Gecko. // See https://bugzilla.mozilla.org/show_bug.cgi?id=177805 for more info. -#[inline(always)] -pub fn max_rect() -> Rect<Au> { - Rect::new(Point2D::new(MIN_AU / 2, MIN_AU / 2), Size2D::new(MAX_AU, MAX_AU)) +pub trait MaxRect { + #[inline(always)] + fn max_rect() -> Self; +} + +impl MaxRect for Rect<Au> { + fn max_rect() -> Rect<Au> { + Rect::new( + Point2D::new(MIN_AU / 2, MIN_AU / 2), + Size2D::new(MAX_AU, MAX_AU) + ) + } +} + +impl MaxRect for LayoutRect { + fn max_rect() -> LayoutRect { + LayoutRect::new( + LayoutPoint::new(f32::MIN / 2.0, f32::MIN / 2.0), + LayoutSize::new(f32::MAX, f32::MAX), + ) + } } /// A helper function to convert a rect of `f32` pixels to a rect of app units. |