dymokomi/luce-browser-render
Source of release 0.6.2
0.6.2 / src / gfx / point_int.lucb
#==============================================================================================
#
# point_int - Gfx::Point<int> (IntPoint, also DevicePixelPoint)
#
# DESCRIPTION:
# Port of Libraries/LibGfx/Point.h (lines 20-261) and Point.cpp (lines 14-45) for T = int.
# The class template is instantiated per type (DESIGN.md ยง2.8): point_float.lucb and
# point_css_pixels.lucb hold the other two instantiations, function for function.
#
# Member templates over a second type U are instantiated for the types phase 1 uses:
# the converting constructor `Point(Point<U>)` and `to_type<U>()` are `to_type_f32` and
# `to_type_css_pixels`. `to_rounded<U>()` of an int point is the identity and nothing
# instantiates it; `to_ceiled`/`to_floored` require a floating-point T (so exist only for
# FloatPoint). As in C++, int overflow is not defined: it traps here.
#
#==============================================================================================
# mark: Construction and access =================================================================
## Ported from Libraries/LibGfx/Point.h:24 Gfx::Point::Point<T> for IntPoint.
pub func int_point_construct(this: IntPoint*, x: i32, y: i32):
this.m_x = x
this.m_y = y
## Ported from Libraries/LibGfx/Point.h:31 Gfx::Point::Point<T>(U x, U y) for IntPoint, with U = float.
pub func int_point_construct_f32(this: IntPoint*, x: f32, y: f32):
this.m_x = (i32)x
this.m_y = (i32)y
## Ported from Libraries/LibGfx/Point.h:44 Gfx::Point::x for IntPoint.
pub func int_point_x(this: const IntPoint*) -> i32:
return this.m_x
## Ported from Libraries/LibGfx/Point.h:45 Gfx::Point::y for IntPoint.
pub func int_point_y(this: const IntPoint*) -> i32:
return this.m_y
## Ported from Libraries/LibGfx/Point.h:47 Gfx::Point::set_x for IntPoint.
pub func int_point_set_x(this: IntPoint*, x: i32):
this.m_x = x
## Ported from Libraries/LibGfx/Point.h:48 Gfx::Point::set_y for IntPoint.
pub func int_point_set_y(this: IntPoint*, y: i32):
this.m_y = y
## Ported from Libraries/LibGfx/Point.h:50 Gfx::Point::is_zero for IntPoint.
pub func int_point_is_zero(this: const IntPoint*) -> bool:
return this.m_x == 0 and this.m_y == 0
# mark: Translation and scaling =================================================================
## Ported from Libraries/LibGfx/Point.h:52 Gfx::Point::translate_by for IntPoint.
pub func int_point_translate_by_i32_i32(this: IntPoint*, dx: i32, dy: i32):
this.m_x += dx
this.m_y += dy
## Ported from Libraries/LibGfx/Point.h:58 Gfx::Point::translate_by for IntPoint.
pub func int_point_translate_by_i32(this: IntPoint*, dboth: i32):
int_point_translate_by_i32_i32(this, dboth, dboth)
## Ported from Libraries/LibGfx/Point.h:59 Gfx::Point::translate_by for IntPoint.
pub func int_point_translate_by_int_point(this: IntPoint*, delta: IntPoint):
int_point_translate_by_i32_i32(this, int_point_x(&delta), int_point_y(&delta))
## Ported from Libraries/LibGfx/Point.h:61 Gfx::Point::scale_by for IntPoint.
pub func int_point_scale_by_i32_i32(this: IntPoint*, dx: i32, dy: i32):
this.m_x *= dx
this.m_y *= dy
## Ported from Libraries/LibGfx/Point.h:67 Gfx::Point::scale_by for IntPoint.
pub func int_point_scale_by_i32(this: IntPoint*, dboth: i32):
int_point_scale_by_i32_i32(this, dboth, dboth)
## Ported from Libraries/LibGfx/Point.h:68 Gfx::Point::scale_by for IntPoint.
pub func int_point_scale_by_int_point(this: IntPoint*, delta: IntPoint):
int_point_scale_by_i32_i32(this, int_point_x(&delta), int_point_y(&delta))
## Ported from Libraries/LibGfx/Point.h:70 Gfx::Point::translated for IntPoint.
pub func int_point_translated_int_point(this: const IntPoint*, delta: IntPoint) -> IntPoint:
var point = *this
int_point_translate_by_int_point(&point, delta)
return point
## Ported from Libraries/LibGfx/Point.h:77 Gfx::Point::translated for IntPoint.
pub func int_point_translated_i32_i32(this: const IntPoint*, dx: i32, dy: i32) -> IntPoint:
var point = *this
int_point_translate_by_i32_i32(&point, dx, dy)
return point
## Ported from Libraries/LibGfx/Point.h:84 Gfx::Point::translated for IntPoint.
pub func int_point_translated_i32(this: const IntPoint*, dboth: i32) -> IntPoint:
var point = *this
int_point_translate_by_i32_i32(&point, dboth, dboth)
return point
## Ported from Libraries/LibGfx/Point.h:91 Gfx::Point::scaled for IntPoint.
pub func int_point_scaled_i32(this: const IntPoint*, dboth: i32) -> IntPoint:
var point = *this
int_point_scale_by_i32(&point, dboth)
return point
## Ported from Libraries/LibGfx/Point.h:98 Gfx::Point::scaled for IntPoint.
pub func int_point_scaled_int_point(this: const IntPoint*, delta: IntPoint) -> IntPoint:
var point = *this
int_point_scale_by_int_point(&point, delta)
return point
## Ported from Libraries/LibGfx/Point.h:105 Gfx::Point::scaled for IntPoint.
pub func int_point_scaled_i32_i32(this: const IntPoint*, sx: i32, sy: i32) -> IntPoint:
var point = *this
int_point_scale_by_i32_i32(&point, sx, sy)
return point
## Ported from Libraries/LibGfx/Point.cpp:16 Gfx::Point::constrain for IntPoint.
pub func int_point_constrain(this: IntPoint*, rect: DevicePixelRect):
this.m_x = ak.clamp[i32](int_point_x(this), device_pixel_rect_left(&rect), device_pixel_rect_right(&rect) - 1)
this.m_y = ak.clamp[i32](int_point_y(this), device_pixel_rect_top(&rect), device_pixel_rect_bottom(&rect) - 1)
## Ported from Libraries/LibGfx/Point.h:113 Gfx::Point::constrained for IntPoint.
pub func int_point_constrained(this: const IntPoint*, rect: DevicePixelRect) -> IntPoint:
var point = *this
int_point_constrain(&point, rect)
return point
## Ported from Libraries/LibGfx/Point.h:120 Gfx::Point::moved_left for IntPoint.
pub func int_point_moved_left(this: const IntPoint*, amount: i32) -> IntPoint:
return IntPoint(int_point_x(this) - amount, int_point_y(this))
## Ported from Libraries/LibGfx/Point.h:121 Gfx::Point::moved_right for IntPoint.
pub func int_point_moved_right(this: const IntPoint*, amount: i32) -> IntPoint:
return IntPoint(int_point_x(this) + amount, int_point_y(this))
## Ported from Libraries/LibGfx/Point.h:122 Gfx::Point::moved_up for IntPoint.
pub func int_point_moved_up(this: const IntPoint*, amount: i32) -> IntPoint:
return IntPoint(int_point_x(this), int_point_y(this) - amount)
## Ported from Libraries/LibGfx/Point.h:123 Gfx::Point::moved_down for IntPoint.
pub func int_point_moved_down(this: const IntPoint*, amount: i32) -> IntPoint:
return IntPoint(int_point_x(this), int_point_y(this) + amount)
# mark: Operators ===============================================================================
## Ported from Libraries/LibGfx/Point.h:126 Gfx::Point::operator== for IntPoint (U = int).
pub func int_point_eq(this: const IntPoint*, other: IntPoint) -> bool:
return int_point_x(this) == int_point_x(&other) and int_point_y(this) == int_point_y(&other)
## Ported from Libraries/LibGfx/Point.h:131 Gfx::Point::operator+ for IntPoint.
pub func int_point_add(this: const IntPoint*, other: IntPoint) -> IntPoint:
return IntPoint(this.m_x + other.m_x, this.m_y + other.m_y)
## Ported from Libraries/LibGfx/Point.h:133 Gfx::Point::operator+= for IntPoint.
pub func int_point_add_assign(this: IntPoint*, other: IntPoint) -> IntPoint*:
this.m_x += other.m_x
this.m_y += other.m_y
return this
## Ported from Libraries/LibGfx/Point.h:140 Gfx::Point::operator- (unary) for IntPoint.
pub func int_point_neg(this: const IntPoint*) -> IntPoint:
return IntPoint(-this.m_x, -this.m_y)
## Ported from Libraries/LibGfx/Point.h:142 Gfx::Point::operator- for IntPoint.
pub func int_point_sub(this: const IntPoint*, other: IntPoint) -> IntPoint:
return IntPoint(this.m_x - other.m_x, this.m_y - other.m_y)
## Ported from Libraries/LibGfx/Point.h:144 Gfx::Point::operator-= for IntPoint.
pub func int_point_sub_assign(this: IntPoint*, other: IntPoint) -> IntPoint*:
this.m_x -= other.m_x
this.m_y -= other.m_y
return this
## Ported from Libraries/LibGfx/Point.h:151 Gfx::Point::operator* for IntPoint.
pub func int_point_mul(this: const IntPoint*, factor: i32) -> IntPoint:
return IntPoint(this.m_x * factor, this.m_y * factor)
## Ported from Libraries/LibGfx/Point.h:153 Gfx::Point::operator*= for IntPoint.
pub func int_point_mul_assign(this: IntPoint*, factor: i32) -> IntPoint*:
this.m_x *= factor
this.m_y *= factor
return this
## Ported from Libraries/LibGfx/Point.h:160 Gfx::Point::operator/ for IntPoint.
pub func int_point_div(this: const IntPoint*, factor: i32) -> IntPoint:
return IntPoint(this.m_x // factor, this.m_y // factor)
## Ported from Libraries/LibGfx/Point.h:162 Gfx::Point::operator/= for IntPoint.
pub func int_point_div_assign(this: IntPoint*, factor: i32) -> IntPoint*:
this.m_x = this.m_x // factor
this.m_y = this.m_y // factor
return this
# mark: Orientation and distances ===============================================================
## Ported from Libraries/LibGfx/Point.h:169 Gfx::Point::primary_offset_for_orientation for IntPoint.
pub func int_point_primary_offset_for_orientation(this: const IntPoint*, orientation: Orientation) -> i32:
return int_point_y(this) if orientation == Orientation.vertical else int_point_x(this)
## Ported from Libraries/LibGfx/Point.h:174 Gfx::Point::set_primary_offset_for_orientation for IntPoint.
pub func int_point_set_primary_offset_for_orientation(this: IntPoint*, orientation: Orientation, value: i32):
if orientation == Orientation.vertical:
int_point_set_y(this, value)
else:
int_point_set_x(this, value)
## Ported from Libraries/LibGfx/Point.h:183 Gfx::Point::secondary_offset_for_orientation for IntPoint.
pub func int_point_secondary_offset_for_orientation(this: const IntPoint*, orientation: Orientation) -> i32:
return int_point_x(this) if orientation == Orientation.vertical else int_point_y(this)
## Ported from Libraries/LibGfx/Point.h:188 Gfx::Point::set_secondary_offset_for_orientation for IntPoint.
pub func int_point_set_secondary_offset_for_orientation(this: IntPoint*, orientation: Orientation, value: i32):
if orientation == Orientation.vertical:
int_point_set_x(this, value)
else:
int_point_set_y(this, value)
## Ported from Libraries/LibGfx/Point.h:197 Gfx::Point::dx_relative_to for IntPoint.
pub func int_point_dx_relative_to(this: const IntPoint*, other: IntPoint) -> i32:
return int_point_x(this) - int_point_x(&other)
## Ported from Libraries/LibGfx/Point.h:202 Gfx::Point::dy_relative_to for IntPoint.
pub func int_point_dy_relative_to(this: const IntPoint*, other: IntPoint) -> i32:
return int_point_y(this) - int_point_y(&other)
# Returns pixels moved from other in either direction
## Ported from Libraries/LibGfx/Point.h:208 Gfx::Point::pixels_moved for IntPoint.
pub func int_point_pixels_moved(this: const IntPoint*, other: IntPoint) -> i32:
return ak.max[i32](ak.abs_i32(int_point_dx_relative_to(this, other)), ak.abs_i32(int_point_dy_relative_to(this, other)))
## Ported from Libraries/LibGfx/Point.h:213 Gfx::Point::distance_from for IntPoint.
pub func int_point_distance_from(this: const IntPoint*, other: IntPoint) -> f32:
if int_point_eq(this, other):
return 0.0
return ak.trigonometry_hypot_f32((f32)(this.m_x - other.m_x), (f32)(this.m_y - other.m_y))
## Ported from Libraries/LibGfx/Point.h:220 Gfx::Point::absolute_relative_distance_to for IntPoint.
pub func int_point_absolute_relative_distance_to(this: const IntPoint*, other: IntPoint) -> IntPoint:
return IntPoint(ak.abs_i32(int_point_dx_relative_to(this, other)), ak.abs_i32(int_point_dy_relative_to(this, other)))
## Ported from Libraries/LibGfx/Point.cpp:23 Gfx::Point::end_point_for_aspect_ratio for IntPoint.
pub func int_point_end_point_for_aspect_ratio(this: const IntPoint*, previous_end_point: IntPoint, aspect_ratio: f32) -> IntPoint:
assert(aspect_ratio > 0.0)
let x_sign: i32 = 1 if int_point_x(&previous_end_point) >= int_point_x(this) else -1
let y_sign: i32 = 1 if int_point_y(&previous_end_point) >= int_point_y(this) else -1
var dx = ak.abs_i32(int_point_x(&previous_end_point) - int_point_x(this))
var dy = ak.abs_i32(int_point_y(&previous_end_point) - int_point_y(this))
if dx > dy:
dy = (i32)((f32)dx / aspect_ratio)
else:
dx = (i32)((f32)dy * aspect_ratio)
return IntPoint(int_point_x(this) + x_sign * dx, int_point_y(this) + y_sign * dy)
# mark: Conversions =============================================================================
## Ported from Libraries/LibGfx/Point.h:229 Gfx::Point::to_type<float> for IntPoint (and the
## converting constructor Point<float>(IntPoint), Point.h:38).
pub func int_point_to_type_f32(this: const IntPoint*) -> FloatPoint:
return FloatPoint((f32)int_point_x(this), (f32)int_point_y(this))
## Ported from Libraries/LibGfx/Point.h:229 Gfx::Point::to_type<CSSPixels> for IntPoint (and the
## converting constructor Point<CSSPixels>(IntPoint), Point.h:38).
pub func int_point_to_type_css_pixels(this: const IntPoint*) -> CssPixelPoint:
return CssPixelPoint(css_pixels_from_int(int_point_x(this)), css_pixels_from_int(int_point_y(this)))
## Ported from Libraries/LibGfx/Point.cpp:40 Gfx::Point::to_byte_string for IntPoint.
pub func int_point_to_byte_string(this: const IntPoint*) -> ak.ByteString:
let arguments = [ak.arg_i64(int_point_x(this)), ak.arg_i64(int_point_y(this))]
var params = ak.type_erased_format_params_create(arguments)
return ak.byte_string_vformatted(ak.sv("[{},{}]"), ¶ms)
## Ported from Libraries/LibGfx/Point.h:312 AK::Traits<Gfx::Point<T>>::hash for IntPoint.
pub func int_point_hash(point: const IntPoint*) -> u32:
return ak.pair_int_hash(ak.u32_hash((u32)int_point_x(point)), ak.u32_hash((u32)int_point_y(point)))