4#ifndef GREM_CORE_EXTENTS_HPP
5#define GREM_CORE_EXTENTS_HPP
44 return {.x = v.x, .y = v.y, .z = v.z};
120 constexpr operator vec3() const noexcept {
121 return vec3{
static_cast<float>(
x),
static_cast<float>(
y),
static_cast<float>(
z)};
129 constexpr operator dvec3() const noexcept {
130 return dvec3{
static_cast<double>(
x),
static_cast<double>(
y),
static_cast<double>(
z)};
138 constexpr operator ivec3() const noexcept {
139 return ivec3{
static_cast<int>(
x),
static_cast<int>(
y),
static_cast<int>(
z)};
148 return u32vec3{
static_cast<uint32_t
>(
x),
static_cast<uint32_t
>(
y),
static_cast<uint32_t
>(
z)};
171 return {.width = v.x, .height = v.y, .depth = v.z};
216 .width =
static_cast<uint32_t
>(
grem::ceil(v.x)),
218 .depth =
static_cast<uint32_t
>(
grem::ceil(v.z)),
248 constexpr explicit operator Offset<3>() const noexcept {
258 constexpr operator vec3() const noexcept {
268 constexpr operator dvec3() const noexcept {
278 constexpr operator ivec3() const noexcept {
314 const uint32_t originalWidth =
width;
315 const uint32_t originalHeight =
height;
316 const uint32_t originalDepth =
depth;
318 const uint32_t nextWidth = originalWidth * (
scale + 1);
319 const uint32_t nextHeight = originalHeight * (
scale + 1);
320 const uint32_t nextDepth = originalDepth * (
scale + 1);
321 if (nextWidth > targetSize.width || nextHeight > targetSize.height || nextDepth > targetSize.depth) {
343 return {.x = v.x, .y = v.y};
423 constexpr operator vec2() const noexcept {
424 return vec2{
static_cast<float>(
x),
static_cast<float>(
y)};
432 constexpr operator dvec2() const noexcept {
433 return dvec2{
static_cast<double>(
x),
static_cast<double>(
y)};
441 constexpr operator ivec2() const noexcept {
442 return ivec2{
static_cast<int>(
x),
static_cast<int>(
y)};
451 return u32vec2{
static_cast<uint32_t
>(
x),
static_cast<uint32_t
>(
y)};
474 return {.width = v.x, .height = v.y};
517 .width =
static_cast<uint32_t
>(
grem::ceil(v.x)),
546 constexpr explicit operator Offset<2>() const noexcept {
556 constexpr operator vec2() const noexcept {
566 constexpr operator dvec2() const noexcept {
576 constexpr operator ivec2() const noexcept {
614 return static_cast<float>(
width) /
static_cast<float>(
height);
630 const uint32_t originalWidth =
width;
631 const uint32_t originalHeight =
height;
633 const uint32_t nextWidth = originalWidth * (
scale + 1);
634 const uint32_t nextHeight = originalHeight * (
scale + 1);
635 if (nextWidth > targetSize.width || nextHeight > targetSize.height) {
653 a.x +=
static_cast<int32_t
>(b.width);
654 a.y +=
static_cast<int32_t
>(b.height);
659 a.x -=
static_cast<int32_t
>(b.width);
660 a.y -=
static_cast<int32_t
>(b.height);
665 return {.x = -a.x, .y = -a.y};
669 return {.x = a.x + b.x, .y = a.y + b.y};
673 return {.x = a.x +
static_cast<int32_t
>(b.width), .y = a.y +
static_cast<int32_t
>(b.height)};
677 return {.x =
static_cast<int32_t
>(a.width) + b.x, .y =
static_cast<int32_t
>(a.height) + b.y};
681 return {.x = a.x - b.x, .y = a.y - b.y};
685 return {.x = a.x -
static_cast<int32_t
>(b.width), .y = a.y -
static_cast<int32_t
>(b.height)};
689 return {.x =
static_cast<int32_t
>(a.width) - b.x, .y =
static_cast<int32_t
>(a.height) - b.y};
693 return {.x = a.x * b, .y = a.y * b};
697 return {.x = a * b.x, .y = a * b.y};
701 return {.x = a.x / b, .y = a.y / b};
705 return {.x = a / b.x, .y = a / b.y};
709 return a *
static_cast<int32_t
>(b);
713 return static_cast<int32_t
>(a) * b;
717 return a /
static_cast<int32_t
>(b);
721 return static_cast<int32_t
>(a) / b;
726 a.height += b.height;
732 a.height -= b.height;
749 return {.width = a.width + b.width, .height = a.height + b.height};
753 return {.width = a.width - b.width, .height = a.height - b.height};
757 return {.width = a.width * b, .height = a.height * b};
761 return {.width = a * b.width, .height = a * b.height};
765 return {.width = a.width / b, .height = a.height / b};
769 return {.width = a / b.width, .height = a / b.height};
799 return point.x >=
offset.x && point.y >=
offset.y &&
static_cast<uint32_t
>(point.x -
offset.x) <
size.width &&
static_cast<uint32_t
>(point.y -
offset.y) <
size.height;
814 const uint32_t
scale =
size.fitIntegerScaled(targetRegion.
size);
vec< 3, uint32_t > u32vec3
Definition math.hpp:419
constexpr Offset2D & operator+=(Offset2D &a, Offset2D b) noexcept
Definition extents.hpp:646
vec< 2, float > vec2
Definition math.hpp:438
GREM_ALWAYS_INLINE constexpr vec< N, T > GREM_VECTORCALL floor(vec< N, T > a)
Definition math.hpp:1421
constexpr Offset2D operator-(Offset2D a) noexcept
Definition extents.hpp:664
constexpr Offset2D operator/(Offset2D a, int32_t b) noexcept
Definition extents.hpp:700
vec< 3, int32_t > i32vec3
Definition math.hpp:415
Region< 3 > Region3D
Rectangular region of 3D data.
Definition extents.hpp:820
vec< 3, float > vec3
Definition math.hpp:439
Extent< 2 > Extent2D
Size of a 2D data region.
Definition extents.hpp:31
constexpr Offset2D operator*(Offset2D a, int32_t b) noexcept
Definition extents.hpp:692
Region< 2 > Region2D
Rectangular region of 2D data.
Definition extents.hpp:819
Offset< 2 > Offset2D
Offset in a 2D data region.
Definition extents.hpp:21
constexpr Offset2D & operator-=(Offset2D &a, Extent2D b) noexcept
Definition extents.hpp:658
GREM_ALWAYS_INLINE constexpr vec< N, T > GREM_VECTORCALL ceil(vec< N, T > a)
Definition math.hpp:1422
GREM_ALWAYS_INLINE constexpr vec< N, T > GREM_VECTORCALL trunc(vec< N, T > a)
Definition math.hpp:1420
vec< 3, double > dvec3
Definition math.hpp:443
vec< 2, int32_t > i32vec2
Definition math.hpp:414
Offset< 3 > Offset3D
Offset in a 3D data region.
Definition extents.hpp:22
GREM_ALWAYS_INLINE constexpr vec< N, T > GREM_VECTORCALL round(vec< N, T > a)
Definition math.hpp:1418
Extent< 3 > Extent3D
Size of a 3D data region.
Definition extents.hpp:32
vec< 3, int > ivec3
Definition math.hpp:391
GREM_ALWAYS_INLINE constexpr mat< 3, 3, T > GREM_VECTORCALL scale(vec< 2, T > scale)
Create a scale matrix describing a 2D scale.
Definition math.hpp:2665
constexpr auto operator+(const ConstantString< CharT, LengthA > &a, const ConstantString< CharT, LengthB > &b)
Definition ConstantString.hpp:656
vec< 2, uint32_t > u32vec2
Definition math.hpp:418
vec< 2, double > dvec2
Definition math.hpp:442
constexpr Extent2D & operator*=(Extent2D &a, uint32_t b) noexcept
Definition extents.hpp:736
constexpr Extent2D & operator/=(Extent2D &a, uint32_t b) noexcept
Definition extents.hpp:742
vec< 2, int > ivec2
Definition math.hpp:390
static Extent< 2 > trunc(vec2 v)
Create an extent from a vector of floating-point numbers, rounded to their truncated integer values b...
Definition extents.hpp:530
static Extent< 2 > floor(vec2 v)
Create an extent from a vector of floating-point numbers, rounded down to their floor integer values ...
Definition extents.hpp:500
float getAspectRatio() const
Get the aspect ratio of the extent (width / height).
Definition extents.hpp:613
uint32_t fitIntegerScaled(Extent targetSize)
Fit the extents into a target size at the largest positive integer scale of its original size that st...
Definition extents.hpp:628
static Extent< 2 > ceil(vec2 v)
Create an extent from a vector of floating-point numbers, rounded up to their ceiling integer values ...
Definition extents.hpp:515
constexpr bool operator==(const Extent2D &other) const =default
Compare this extent to another for equality.
static constexpr Extent< 2 > from(u32vec2 v) noexcept
Create an extent from a vector of integers.
Definition extents.hpp:473
static Extent< 2 > round(vec2 v)
Create an extent from a vector of floating-point numbers, rounded to their nearest integer values bef...
Definition extents.hpp:485
uint32_t width
Horizontal extent of the region.
Definition extents.hpp:537
uint32_t height
Vertical extent of the region.
Definition extents.hpp:538
static Extent< 3 > trunc(vec3 v)
Create an extent from a vector of floating-point numbers, rounded to their truncated integer values b...
Definition extents.hpp:230
static Extent< 3 > ceil(vec3 v)
Create an extent from a vector of floating-point numbers, rounded up to their ceiling integer values ...
Definition extents.hpp:214
static Extent< 3 > floor(vec3 v)
Create an extent from a vector of floating-point numbers, rounded down to their floor integer values ...
Definition extents.hpp:198
static constexpr Extent< 3 > from(u32vec3 v) noexcept
Create an extent from a vector of integers.
Definition extents.hpp:170
uint32_t height
Vertical extent.
Definition extents.hpp:239
constexpr bool operator==(const Extent< 3 > &other) const =default
Compare this extent to another for equality.
uint32_t fitIntegerScaled(Extent targetSize)
Fit the extents into a target size at the largest positive integer scale of its original size that st...
Definition extents.hpp:312
uint32_t width
Horizontal extent.
Definition extents.hpp:238
static Extent< 3 > round(vec3 v)
Create an extent from a vector of floating-point numbers, rounded to their nearest integer values bef...
Definition extents.hpp:182
uint32_t depth
Number of layers.
Definition extents.hpp:240
Size of a data region.
Definition extents.hpp:30
int32_t x
Horizontal offset.
Definition extents.hpp:406
constexpr bool operator==(const Offset< 2 > &other) const =default
Compare this offset to another for equality.
static constexpr Offset< 2 > from(i32vec2 v) noexcept
Create an offset from a vector of integers.
Definition extents.hpp:342
static Offset< 2 > trunc(vec2 v)
Create an offset from a vector of floating-point numbers, rounded to their truncated integer values b...
Definition extents.hpp:399
static Offset< 2 > floor(vec2 v)
Create an offset from a vector of floating-point numbers, rounded down to their floor integer values ...
Definition extents.hpp:369
int32_t y
Vertical offset.
Definition extents.hpp:407
static Offset< 2 > ceil(vec2 v)
Create an offset from a vector of floating-point numbers, rounded up to their ceiling integer values ...
Definition extents.hpp:384
static Offset< 2 > round(vec2 v)
Create an offset from a vector of floating-point numbers, rounded to their nearest integer values bef...
Definition extents.hpp:354
int32_t x
Horizontal offset.
Definition extents.hpp:111
static constexpr Offset< 3 > from(i32vec3 v) noexcept
Create an offset from a vector of integers.
Definition extents.hpp:43
int32_t z
Depth offset.
Definition extents.hpp:113
static Offset< 3 > ceil(vec3 v)
Create an offset from a vector of floating-point numbers, rounded up to their ceiling integer values ...
Definition extents.hpp:87
static Offset< 3 > trunc(vec3 v)
Create an offset from a vector of floating-point numbers, rounded to their truncated integer values b...
Definition extents.hpp:103
static Offset< 3 > floor(vec3 v)
Create an offset from a vector of floating-point numbers, rounded down to their floor integer values ...
Definition extents.hpp:71
constexpr bool operator==(const Offset< 3 > &other) const =default
Compare this offset to another for equality.
static Offset< 3 > round(vec3 v)
Create an offset from a vector of floating-point numbers, rounded to their nearest integer values bef...
Definition extents.hpp:55
int32_t y
Vertical offset.
Definition extents.hpp:112
Offset in a data region.
Definition extents.hpp:20
Rectangular region of data.
Definition extents.hpp:778
constexpr bool operator==(const Region< N > &other) const =default
Compare this region's offset and extents to another for equality.
uint32_t fitCenteredIntegerScaled(Region targetRegion)
Fit the region into the middle of a target region at the largest positive integer scale of its origin...
Definition extents.hpp:813
constexpr bool contains(Offset< N > point) const noexcept
Check if a given point is contained within the extents of this region.
Definition extents.hpp:798
Extent< N > size
Definition extents.hpp:780
Offset< N > offset
Definition extents.hpp:779