68 static_assert(
sizeof(T) <= 4);
69 if(val < (std::numeric_limits<T>::min)())
70 val = (std::numeric_limits<T>::min)();
71 else if(val > (std::numeric_limits<T>::max)())
72 val = (std::numeric_limits<T>::max)();
79 return clip<T>(lhs + rhs);
85 return clip<T>((int64_t)lhs + rhs);
91 return clip<T>((int64_t)lhs - rhs);
97 return clip<T>(lhs - rhs);
176 GRK_INFO(
"[%u,%u,%u,%u,%u,%u]",
origin_x0,
origin_y0,
x0,
y0,
x1,
y1);
180 std::ostringstream os;
199 return x >=
x0 && y >=
y0 && x <
x1 && y <
y1;
208 if(rhs && (
this != rhs))
244 x1 * scalex,
y1 * scaley);
249 (T)(
y0 / deny), (T)ceildiv<uint64_t>(
x1, denx),
250 (T)ceildiv<uint64_t>(
y1, deny));
255 (T)(
y0 >> powy), (T)ceildivpow2<uint64_t>(
x1, powx),
256 (T)ceildivpow2<uint64_t>(
y1, powy));
265 ceildiv<uint64_t>(
x0, denx), ceildiv<uint64_t>(
y0, deny),
266 ceildiv<uint64_t>(
x1, denx), ceildiv<uint64_t>(
y1, deny));
277 ceildivpow2<uint64_t>(
origin_y0, powy), ceildivpow2<uint64_t>(
x0, powx),
278 ceildivpow2<uint64_t>(
y0, powy), ceildivpow2<uint64_t>(
x1, powx),
279 ceildivpow2<uint64_t>(
y1, powy));
295 std::min<T>(
x1, rhs->
x1), std::min<T>(
y1, rhs->
y1));
305 std::min<T>(
x1, rhs.
x1), std::min<T>(
y1, rhs.
y1));
313 std::min<T>(
x1, rhs->
x1), std::min<T>(
y1, rhs->
y1));
318 return std::max<T>(
x0, rhs->
x0) < std::min<T>(
x1, rhs->
x1) &&
319 std::max<T>(
y0, rhs->
y0) < std::min<T>(
y1, rhs->
y1);
325 std::max<T>(
x1, rhs->
x1), std::max<T>(
y1, rhs->
y1));
333 return (uint64_t)(
x1 -
x0) * (
y1 -
y0);
356 return rc.pan_IN_PLACE(x, y);
360 x0 = satAdd<T>((int64_t)
x0, (int64_t)x);
361 y0 = satAdd<T>((int64_t)
y0, (int64_t)y);
362 x1 = satAdd<T>((int64_t)
x1, (int64_t)x);
363 y1 = satAdd<T>((int64_t)
y1, (int64_t)y);
370 return grow_IN_PLACE(boundary, boundary, (std::numeric_limits<T>::max)(),
371 (std::numeric_limits<T>::max)());
375 return grow_IN_PLACE(boundaryx, boundaryy, (std::numeric_limits<T>::max)(),
376 (std::numeric_limits<T>::max)());
392 x0 = std::max<T>(satSub<T>(
x0, boundaryx), bounds.
x0);
393 y0 = std::max<T>(satSub<T>(
y0, boundaryy), bounds.
y0);
394 x1 = std::min<T>(satAdd<T>(
x1, boundaryx), bounds.
x1);
395 y1 = std::min<T>(satAdd<T>(
y1, boundaryy), bounds.
y1);
Copyright (C) 2016-2022 Grok Image Compression Inc.
Definition: ICacheable.h:20
grk_rect< uint16_t > grk_rect16
Definition: geometry.h:62
T satAdd(int64_t lhs, int64_t rhs)
Definition: geometry.h:77
T clip(int64_t val)
Definition: geometry.h:66
void GRK_INFO(const char *fmt,...)
Definition: logger.cpp:40
uint32_t ceildiv(T a, T b)
Divide an integer by another integer and round upwards.
Definition: grk_intmath.h:33
T satSub(T lhs, T rhs)
Definition: geometry.h:89
grk_rect< uint32_t > grk_rect32
Definition: geometry.h:61
T ceildivpow2(T a, uint32_t b)
Definition: grk_intmath.h:40
Definition: geometry.h:45
T x0
Definition: geometry.h:48
grk_line(T _x0, T _x1)
Definition: geometry.h:47
grk_line()
Definition: geometry.h:46
T x1
Definition: geometry.h:49
T length() const
Definition: geometry.h:51
Definition: geometry.h:34
T x
Definition: geometry.h:37
T y
Definition: geometry.h:38
grk_pt(T _x, T _y)
Definition: geometry.h:36
grk_pt()
Definition: geometry.h:35
Definition: geometry.h:102
uint64_t area(void) const
Definition: geometry.h:331
grk_rect< T > & grow_IN_PLACE(T boundaryx, T boundaryy)
Definition: geometry.h:373
T width() const
Definition: geometry.h:335
grk_rect< T > rectUnion(const grk_rect< T > &rhs) const
Definition: geometry.h:327
grk_rect< T > & setOrigin(grk_rect< T > &rhs, bool absolute)
Definition: geometry.h:138
bool absoluteCoordinates
Definition: geometry.h:122
void setRect(grk_rect< T > rhs)
Definition: geometry.h:232
T y1
Definition: geometry.h:124
grk_rect< T > scaleDownCeilPow2(uint32_t powx, uint32_t powy) const
Definition: geometry.h:274
grk_rect< T > & grow_IN_PLACE(T boundary)
Definition: geometry.h:368
T x0
Definition: geometry.h:124
bool operator==(const grk_rect< T > &rhs) const
Definition: geometry.h:220
T x1
Definition: geometry.h:124
grk_rect< T > scaleDownPow2(uint32_t powx, uint32_t powy) const
Definition: geometry.h:252
grk_rect< T > & clip_IN_PLACE(const grk_rect< T > &rhs)
Definition: geometry.h:301
grk_rect< T > & operator=(const grk_rect< T > &rhs)
Definition: geometry.h:201
grk_rect< T > & toRelative(void)
Definition: geometry.h:156
T origin_y0
Definition: geometry.h:123
T height() const
Definition: geometry.h:339
bool valid(void) const
Definition: geometry.h:185
T parityY(void) const
Definition: geometry.h:403
grk_rect< T > clip(const grk_rect< T > *rhs) const
Definition: geometry.h:291
grk_rect< T > scaleDownCeilPow2(uint32_t power) const
Definition: geometry.h:268
grk_rect< T > & pan_IN_PLACE(int64_t x, int64_t y)
Definition: geometry.h:358
grk_rect< T > scaleDown(uint64_t denx, uint64_t deny) const
Definition: geometry.h:246
grk_rect< T > & grow_IN_PLACE(T boundary, T maxX, T maxY)
Definition: geometry.h:378
grk_rect< T > pan(int64_t x, int64_t y) const
Definition: geometry.h:352
grk_rect< T > & grow_IN_PLACE(T boundaryx, T boundaryy, T maxX, T maxY)
Definition: geometry.h:382
grk_rect< T > scale(uint32_t scalex, uint32_t scaley) const
Definition: geometry.h:241
bool nonEmptyIntersection(const grk_rect< T > *rhs) const
Definition: geometry.h:315
grk_rect< T > clip(const grk_rect< T > &rhs) const
Definition: geometry.h:297
T parityX(void) const
Definition: geometry.h:399
grk_rect< T > scaleDownPow2(grk_pt< T > pow) const
Definition: geometry.h:258
virtual ~grk_rect()=default
grk_rect< T > & setOrigin(T origx, T origy, bool absolute)
Definition: geometry.h:126
grk_rect< T > scaleDownCeil(uint64_t denx, uint64_t deny) const
Definition: geometry.h:262
grk_rect< T > scaleDownCeil(uint32_t den) const
Definition: geometry.h:236
grk_rect< T > rectUnion(const grk_rect< T > *rhs) const
Definition: geometry.h:321
grk_rect< T > intersection(const grk_rect< T > rhs) const
Definition: geometry.h:281
bool contains(grk_pt< T > pt)
Definition: geometry.h:193
bool empty(void) const
Definition: geometry.h:189
grk_rect< T > & grow_IN_PLACE(T boundaryx, T boundaryy, grk_rect< T > bounds)
Definition: geometry.h:390
grk_rect< T > intersection(const grk_rect< T > *rhs) const
Definition: geometry.h:309
grk_rect(T x0, T y0, T x1, T y1)
Definition: geometry.h:107
grk_rect(const grk_rect *rhs)
Definition: geometry.h:109
T origin_x0
Definition: geometry.h:123
grk_line< T > dimY() const
Definition: geometry.h:347
virtual void print(void) const
Definition: geometry.h:174
grk_line< T > dimX() const
Definition: geometry.h:343
void setRect(grk_rect< T > *rhs)
Definition: geometry.h:228
grk_rect(void)
Definition: geometry.h:119
bool contains(T x, T y)
Definition: geometry.h:197
grk_rect< T > & setOrigin(grk_rect< T > *rhs, bool absolute)
Definition: geometry.h:142
bool isContainedIn(const grk_rect< T > rhs) const
Definition: geometry.h:287
grk_rect(const grk_rect &rhs)
Definition: geometry.h:108
grk_rect< T > & grow_IN_PLACE(T boundary, grk_rect< T > bounds)
Definition: geometry.h:386
grk_rect< T > & toAbsolute(void)
Definition: geometry.h:166
grk_rect(T origin_x0, T origin_y0, T x0, T y0, T x1, T y1)
Definition: geometry.h:103
std::string boundsString() const
Definition: geometry.h:178
grk_rect< T > & operator=(const grk_rect< T > *rhs)
Definition: geometry.h:205
T y0
Definition: geometry.h:124