diff options
Diffstat (limited to 'components/layout_2020/geom.rs')
-rw-r--r-- | components/layout_2020/geom.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/components/layout_2020/geom.rs b/components/layout_2020/geom.rs index 166ba7a0494..918cbf47fd2 100644 --- a/components/layout_2020/geom.rs +++ b/components/layout_2020/geom.rs @@ -60,6 +60,15 @@ pub(crate) mod flow_relative { } } +impl<T: Zero> physical::Vec2<T> { + pub fn zero() -> Self { + Self { + x: T::zero(), + y: T::zero(), + } + } +} + impl<T: fmt::Debug> fmt::Debug for physical::Vec2<T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // Not using f.debug_struct on purpose here, to keep {:?} output somewhat compact @@ -387,6 +396,33 @@ impl<T> physical::Rect<T> { } } +impl physical::Rect<Length> { + pub fn axis_aligned_bounding_box(&self, other: &Self) -> Self { + let top_left = physical::Vec2 { + x: self.top_left.x.min(other.top_left.x), + y: self.top_left.y.min(other.top_left.y), + }; + + let bottom_corner_x = (self.top_left.x + self.size.x).max(other.top_left.x + other.size.x); + let bottom_corner_y = (self.top_left.y + self.size.y).max(other.top_left.y + other.size.y); + let size = physical::Vec2 { + x: bottom_corner_x - top_left.x, + y: bottom_corner_y - top_left.y, + }; + + Self { top_left, size } + } +} + +impl<T: Zero> physical::Rect<T> { + pub fn zero() -> Self { + Self { + top_left: physical::Vec2::zero(), + size: physical::Vec2::zero(), + } + } +} + impl From<physical::Rect<Length>> for Rect<CSSPixel> { fn from(r: physical::Rect<Length>) -> Self { Rect { |