dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / layout / css_pixel_bounding_box.lucb
#==============================================================================================
#
# css_pixel_bounding_box - Gfx::BoundingBox<CSSPixels>: the smallest rectangle around points
#
# DESCRIPTION:
# Port of LibGfx/BoundingBox.h (lines 1-64) for CSSPixels, the one instantiation LibWeb
# uses (SVGFormattingContext's container boxes, SVGPaintable's clip path bounds).
# luce-browser-render's gfx does not instantiate it, so the engine keeps it beside its
# users (DESIGN.md ยง2.8: geometry templates become concrete structs).
#
#==============================================================================================
## Gfx::BoundingBox<CSSPixels> (Libraries/LibGfx/BoundingBox.h:15): the extent of the points added so far.
pub struct CssPixelBoundingBox:
pub var m_min_x: gfx.CssPixels
pub var m_min_y: gfx.CssPixels
pub var m_max_x: gfx.CssPixels
pub var m_max_y: gfx.CssPixels
pub var m_has_no_points: bool
## Ported from Libraries/LibGfx/BoundingBox.h:17 Gfx::BoundingBox::BoundingBox: no points yet.
pub func css_pixel_bounding_box_new() -> CssPixelBoundingBox:
let zero = gfx.CssPixels.from_int(0)
return CssPixelBoundingBox(m_min_x = zero, m_min_y = zero, m_max_x = zero, m_max_y = zero, m_has_no_points = true)
## Ported from Libraries/LibGfx/BoundingBox.h:19 Gfx::BoundingBox::add_point.
pub func css_pixel_bounding_box_add_point(this: CssPixelBoundingBox*, x: gfx.CssPixels, y: gfx.CssPixels):
if this.m_has_no_points:
this.m_min_x = x
this.m_max_x = x
this.m_min_y = y
this.m_max_y = y
this.m_has_no_points = false
else:
this.m_min_x = ak.min(this.m_min_x, x)
this.m_min_y = ak.min(this.m_min_y, y)
this.m_max_x = ak.max(this.m_max_x, x)
this.m_max_y = ak.max(this.m_max_y, y)
## Ported from Libraries/LibGfx/BoundingBox.h:33 Gfx::BoundingBox::x.
pub func css_pixel_bounding_box_x(this: const CssPixelBoundingBox*) -> gfx.CssPixels:
return this.m_min_x
## Ported from Libraries/LibGfx/BoundingBox.h:34 Gfx::BoundingBox::y.
pub func css_pixel_bounding_box_y(this: const CssPixelBoundingBox*) -> gfx.CssPixels:
return this.m_min_y
## Ported from Libraries/LibGfx/BoundingBox.h:35 Gfx::BoundingBox::width.
pub func css_pixel_bounding_box_width(this: const CssPixelBoundingBox*) -> gfx.CssPixels:
return this.m_max_x.sub(this.m_min_x)
## Ported from Libraries/LibGfx/BoundingBox.h:36 Gfx::BoundingBox::height.
pub func css_pixel_bounding_box_height(this: const CssPixelBoundingBox*) -> gfx.CssPixels:
return this.m_max_y.sub(this.m_min_y)
## Ported from Libraries/LibGfx/BoundingBox.h:37 Gfx::BoundingBox::has_no_points.
pub func css_pixel_bounding_box_has_no_points(this: const CssPixelBoundingBox*) -> bool:
return this.m_has_no_points
## Ported from Libraries/LibGfx/BoundingBox.h:39 Gfx::BoundingBox::add_point(Point<T>).
pub func css_pixel_bounding_box_add_point_css_pixel_point(this: CssPixelBoundingBox*, point: gfx.CssPixelPoint):
css_pixel_bounding_box_add_point(this, point.m_x, point.m_y)
## Ported from Libraries/LibGfx/BoundingBox.h:44 Gfx::BoundingBox::to_rect (and operator Rect<T>).
pub func css_pixel_bounding_box_to_rect(this: const CssPixelBoundingBox*) -> gfx.CssPixelRect:
var rect: gfx.CssPixelRect = ---
gfx.css_pixel_rect_construct_css_pixels(&rect, css_pixel_bounding_box_x(this), css_pixel_bounding_box_y(this), css_pixel_bounding_box_width(this), css_pixel_bounding_box_height(this))
return rect