Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-render

Source of release 0.6.2

0.6.2 / src / gfx / rect_css_pixels_2.lucb

#==============================================================================================
#
#   rect_css_pixels_2 - Gfx::Rect<Web::CSSPixels> (CSSPixelRect): edges to conversions
#
#   DESCRIPTION:
#       Port of Libraries/LibGfx/Rect.h (lines 349-593) for T = CSSPixels: edges, intersection
#       and union, corners and centering, conversions. rect_css_pixels_1.lucb has the first half
#       of the class. Not here: `from_two_points` (it calls AK::abs, which does not accept a
#       CSSPixels) and `to_byte_string` (Rect.cpp defines it only for int and float); the
#       `to_rounded<CSSPixels>` specialization is in pixel_units.lucb, as in PixelUnits.h.
#
#==============================================================================================

# mark: Edges ===================================================================================

## Ported from Libraries/LibGfx/Rect.h:349 Gfx::Rect::first_edge_for_orientation for CssPixelRect.
pub func css_pixel_rect_first_edge_for_orientation(this: const CssPixelRect*, orientation: Orientation) -> CssPixels:
    if orientation == Orientation.vertical:
        return css_pixel_rect_top(this)
    return css_pixel_rect_left(this)

## Ported from Libraries/LibGfx/Rect.h:356 Gfx::Rect::last_edge_for_orientation for CssPixelRect.
pub func css_pixel_rect_last_edge_for_orientation(this: const CssPixelRect*, orientation: Orientation) -> CssPixels:
    if orientation == Orientation.vertical:
        return css_pixel_rect_bottom(this)
    return css_pixel_rect_right(this)

## Ported from Libraries/LibGfx/Rect.h:363 Gfx::Rect::left for CssPixelRect.
pub func css_pixel_rect_left(this: const CssPixelRect*) -> CssPixels:
    return css_pixel_rect_x(this)

## Ported from Libraries/LibGfx/Rect.h:364 Gfx::Rect::right for CssPixelRect.
pub func css_pixel_rect_right(this: const CssPixelRect*) -> CssPixels:
    return css_pixel_rect_x(this).add(css_pixel_rect_width(this))

## Ported from Libraries/LibGfx/Rect.h:365 Gfx::Rect::top for CssPixelRect.
pub func css_pixel_rect_top(this: const CssPixelRect*) -> CssPixels:
    return css_pixel_rect_y(this)

## Ported from Libraries/LibGfx/Rect.h:366 Gfx::Rect::bottom for CssPixelRect.
pub func css_pixel_rect_bottom(this: const CssPixelRect*) -> CssPixels:
    return css_pixel_rect_y(this).add(css_pixel_rect_height(this))

## Ported from Libraries/LibGfx/Rect.h:368 Gfx::Rect::set_left for CssPixelRect.
pub func css_pixel_rect_set_left(this: CssPixelRect*, left: CssPixels):
    css_pixel_rect_set_x(this, left)

## Ported from Libraries/LibGfx/Rect.h:369 Gfx::Rect::set_top for CssPixelRect.
pub func css_pixel_rect_set_top(this: CssPixelRect*, top: CssPixels):
    css_pixel_rect_set_y(this, top)

## Ported from Libraries/LibGfx/Rect.h:370 Gfx::Rect::set_right for CssPixelRect.
pub func css_pixel_rect_set_right(this: CssPixelRect*, right: CssPixels):
    css_pixel_rect_set_width(this, right.sub(css_pixel_rect_x(this)))

## Ported from Libraries/LibGfx/Rect.h:371 Gfx::Rect::set_bottom for CssPixelRect.
pub func css_pixel_rect_set_bottom(this: CssPixelRect*, bottom: CssPixels):
    css_pixel_rect_set_height(this, bottom.sub(css_pixel_rect_y(this)))

## Ported from Libraries/LibGfx/Rect.h:373 Gfx::Rect::set_right_without_resize for CssPixelRect.
pub func css_pixel_rect_set_right_without_resize(this: CssPixelRect*, new_right: CssPixels):
    let delta = new_right.sub(css_pixel_rect_right(this))
    css_pixel_rect_translate_by_css_pixels_css_pixels(this, delta, css_pixels_from_int(0))

## Ported from Libraries/LibGfx/Rect.h:379 Gfx::Rect::set_bottom_without_resize for CssPixelRect.
pub func css_pixel_rect_set_bottom_without_resize(this: CssPixelRect*, new_bottom: CssPixels):
    let delta = new_bottom.sub(css_pixel_rect_bottom(this))
    css_pixel_rect_translate_by_css_pixels_css_pixels(this, css_pixels_from_int(0), delta)

# mark: Intersection ============================================================================

## Ported from Libraries/LibGfx/Rect.h:385 Gfx::Rect::intersects_vertically for CssPixelRect.
pub func css_pixel_rect_intersects_vertically(this: const CssPixelRect*, other: CssPixelRect) -> bool:
    return css_pixel_rect_top(this).lt(css_pixel_rect_bottom(&other)) and css_pixel_rect_top(&other).lt(css_pixel_rect_bottom(this))

## Ported from Libraries/LibGfx/Rect.h:390 Gfx::Rect::intersects_horizontally for CssPixelRect.
pub func css_pixel_rect_intersects_horizontally(this: const CssPixelRect*, other: CssPixelRect) -> bool:
    return css_pixel_rect_left(this).lt(css_pixel_rect_right(&other)) and css_pixel_rect_left(&other).lt(css_pixel_rect_right(this))

## Ported from Libraries/LibGfx/Rect.h:395 Gfx::Rect::intersects for CssPixelRect.
pub func css_pixel_rect_intersects_css_pixel_rect(this: const CssPixelRect*, other: CssPixelRect) -> bool:
    return (css_pixel_rect_left(this).lt(css_pixel_rect_right(&other)) and css_pixel_rect_left(&other).lt(css_pixel_rect_right(this)) and css_pixel_rect_top(this).lt(css_pixel_rect_bottom(&other)) and css_pixel_rect_top(&other).lt(css_pixel_rect_bottom(this)))

## Ported from Libraries/LibGfx/Rect.h:403 Gfx::Rect::edge_adjacent_intersects for CssPixelRect.
pub func css_pixel_rect_edge_adjacent_intersects(this: const CssPixelRect*, other: CssPixelRect) -> bool:
    return (ak.max(css_pixel_rect_left(this), css_pixel_rect_left(&other)).le(ak.min(css_pixel_rect_right(this), css_pixel_rect_right(&other))) and ak.max(css_pixel_rect_top(this), css_pixel_rect_top(&other)).le(ak.min(css_pixel_rect_bottom(this), css_pixel_rect_bottom(&other))))

## Ported from Libraries/LibGfx/Rect.h:410 Gfx::Rect::intersects<Container> for CssPixelRect.
pub func css_pixel_rect_intersects_t_container(this: const CssPixelRect*, others: const CssPixelRect[]) -> bool:
    for other in others:
        if css_pixel_rect_intersects_css_pixel_rect(this, other):
            return true
    return false

## Ported from Libraries/LibGfx/Rect.h:420 Gfx::Rect::operator== for CssPixelRect (U = int).
pub func css_pixel_rect_eq(this: const CssPixelRect*, other: CssPixelRect) -> bool:
    return css_pixel_point_eq(&this.m_location, other.m_location) and css_pixel_size_eq(&this.m_size, other.m_size)

## Ported from Libraries/LibGfx/Rect.h:425 Gfx::Rect::operator* for CssPixelRect.
pub func css_pixel_rect_mul(this: const CssPixelRect*, factor: CssPixels) -> CssPixelRect:
    return CssPixelRect(css_pixel_point_mul(&this.m_location, factor), css_pixel_size_mul(&this.m_size, factor))

## Ported from Libraries/LibGfx/Rect.h:427 Gfx::Rect::operator*= for CssPixelRect.
pub func css_pixel_rect_mul_assign(this: CssPixelRect*, factor: CssPixels) -> CssPixelRect*:
    _ = css_pixel_point_mul_assign(&this.m_location, factor)
    _ = css_pixel_size_mul_assign(&this.m_size, factor)
    return this

## Ported from Libraries/LibGfx/Rect.h:434 Gfx::Rect::intersect for CssPixelRect.
pub func css_pixel_rect_intersect(this: CssPixelRect*, other: CssPixelRect):
    let l = ak.max(css_pixel_rect_left(this), css_pixel_rect_left(&other))
    let r = ak.min(css_pixel_rect_right(this), css_pixel_rect_right(&other))
    let t = ak.max(css_pixel_rect_top(this), css_pixel_rect_top(&other))
    let b = ak.min(css_pixel_rect_bottom(this), css_pixel_rect_bottom(&other))

    if l.gt(r) or t.gt(b):
        this.m_location = CssPixelPoint(css_pixels_from_int(0), css_pixels_from_int(0))
        this.m_size = CssPixelSize(css_pixels_from_int(0), css_pixels_from_int(0))
        return

    css_pixel_rect_set_x(this, l)
    css_pixel_rect_set_y(this, t)
    css_pixel_rect_set_right(this, r)
    css_pixel_rect_set_bottom(this, b)

## Ported from Libraries/LibGfx/Rect.h:458 Gfx::Rect::intersection for CssPixelRect.
pub func css_pixel_rect_intersection(a: CssPixelRect, b: CssPixelRect) -> CssPixelRect:
    var r = a
    css_pixel_rect_intersect(&r, b)
    return r

## Ported from Libraries/LibGfx/Rect.h:465 Gfx::Rect::intersected for CssPixelRect.
pub func css_pixel_rect_intersected(this: const CssPixelRect*, other: CssPixelRect) -> CssPixelRect:
    return css_pixel_rect_intersection(*this, other)

# mark: Union ===================================================================================

## Ported from Libraries/LibGfx/Rect.h:470 Gfx::Rect::unite for CssPixelRect.
pub func css_pixel_rect_unite(this: CssPixelRect*, other: CssPixelRect):
    if css_pixel_rect_is_empty(this):
        *this = other
        return
    if css_pixel_rect_is_empty(&other):
        return
    css_pixel_rect_unite_horizontally(this, other)
    css_pixel_rect_unite_vertically(this, other)

## Ported from Libraries/LibGfx/Rect.h:482 Gfx::Rect::unite_horizontally for CssPixelRect.
pub func css_pixel_rect_unite_horizontally(this: CssPixelRect*, other: CssPixelRect):
    let new_left = ak.min(css_pixel_rect_left(this), css_pixel_rect_left(&other))
    let new_right = ak.max(css_pixel_rect_right(this), css_pixel_rect_right(&other))
    css_pixel_rect_set_left(this, new_left)
    css_pixel_rect_set_right(this, new_right)

## Ported from Libraries/LibGfx/Rect.h:490 Gfx::Rect::unite_vertically for CssPixelRect.
pub func css_pixel_rect_unite_vertically(this: CssPixelRect*, other: CssPixelRect):
    let new_top = ak.min(css_pixel_rect_top(this), css_pixel_rect_top(&other))
    let new_bottom = ak.max(css_pixel_rect_bottom(this), css_pixel_rect_bottom(&other))
    css_pixel_rect_set_top(this, new_top)
    css_pixel_rect_set_bottom(this, new_bottom)

## Ported from Libraries/LibGfx/Rect.h:498 Gfx::Rect::united for CssPixelRect.
pub func css_pixel_rect_united(this: const CssPixelRect*, other: CssPixelRect) -> CssPixelRect:
    var rect = *this
    css_pixel_rect_unite(&rect, other)
    return rect

# mark: Corners and centering ===================================================================

## Ported from Libraries/LibGfx/Rect.h:505 Gfx::Rect::top_left for CssPixelRect.
pub func css_pixel_rect_top_left(this: const CssPixelRect*) -> CssPixelPoint:
    return CssPixelPoint(css_pixel_rect_left(this), css_pixel_rect_top(this))

## Ported from Libraries/LibGfx/Rect.h:506 Gfx::Rect::top_right for CssPixelRect.
pub func css_pixel_rect_top_right(this: const CssPixelRect*) -> CssPixelPoint:
    return CssPixelPoint(css_pixel_rect_right(this), css_pixel_rect_top(this))

## Ported from Libraries/LibGfx/Rect.h:507 Gfx::Rect::bottom_left for CssPixelRect.
pub func css_pixel_rect_bottom_left(this: const CssPixelRect*) -> CssPixelPoint:
    return CssPixelPoint(css_pixel_rect_left(this), css_pixel_rect_bottom(this))

## Ported from Libraries/LibGfx/Rect.h:508 Gfx::Rect::bottom_right for CssPixelRect.
pub func css_pixel_rect_bottom_right(this: const CssPixelRect*) -> CssPixelPoint:
    return CssPixelPoint(css_pixel_rect_right(this), css_pixel_rect_bottom(this))

## Ported from Libraries/LibGfx/Rect.h:510 Gfx::Rect::centered_within for CssPixelRect.
pub func css_pixel_rect_centered_within(this: const CssPixelRect*, other: CssPixelRect) -> CssPixelRect:
    var rect = *this
    css_pixel_rect_center_horizontally_within(&rect, other)
    css_pixel_rect_center_vertically_within(&rect, other)
    return rect

## Ported from Libraries/LibGfx/Rect.h:518 Gfx::Rect::center_horizontally_within for CssPixelRect.
pub func css_pixel_rect_center_horizontally_within(this: CssPixelRect*, other: CssPixelRect):
    let center = css_pixel_rect_center(&other)
    css_pixel_rect_set_x(this, css_pixel_point_x(&center).sub(css_pixels_halved(css_pixel_rect_width(this))))

## Ported from Libraries/LibGfx/Rect.h:523 Gfx::Rect::center_vertically_within for CssPixelRect.
pub func css_pixel_rect_center_vertically_within(this: CssPixelRect*, other: CssPixelRect):
    let center = css_pixel_rect_center(&other)
    css_pixel_rect_set_y(this, css_pixel_point_y(&center).sub(css_pixels_halved(css_pixel_rect_height(this))))

# mark: Conversions =============================================================================

## Ported from Libraries/LibGfx/Rect.h:530 Gfx::Rect::to_type<int> for CssPixelRect (and the
## converting constructors Rect<int>(CSSPixelRect) and Rect<int>(CSSPixelPoint, CSSPixelSize), Rect.h:44-51).
pub func css_pixel_rect_to_type_i32(this: const CssPixelRect*) -> DevicePixelRect:
    return DevicePixelRect(css_pixel_point_to_type_i32(&this.m_location), css_pixel_size_to_type_i32(&this.m_size))

## Ported from Libraries/LibGfx/Rect.h:530 Gfx::Rect::to_type<float> for CssPixelRect (and the
## converting constructors Rect<float>(CSSPixelRect) and Rect<float>(CSSPixelPoint, CSSPixelSize), Rect.h:44-51).
pub func css_pixel_rect_to_type_f32(this: const CssPixelRect*) -> FloatRect:
    return FloatRect(css_pixel_point_to_type_f32(&this.m_location), css_pixel_size_to_type_f32(&this.m_size))