35 grk_pt() :
x(0),
y(0) {}
36 grk_pt(T _x, T _y) :
x(_x),
y(_y) {}
46 grk_line() :
x0(0),
x1(0) {}
47 grk_line(T _x0, T _x1) :
x0(_x0),
x1(_x1) {}
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)();
85 return clip<T>((int64_t)lhs + rhs);
91 return clip<T>((int64_t)lhs - rhs);
108 grk_rect(
const grk_rect& rhs) : grk_rect(&rhs) {}
109 grk_rect(
const grk_rect* rhs)
119 grk_rect(
void) : grk_rect(0, 0, 0, 0) {}
120 virtual ~grk_rect() =
default;
126 grk_rect<T>& setOrigin(T origx, T origy,
bool absolute)
138 grk_rect<T>& setOrigin(grk_rect<T>& rhs,
bool absolute)
140 return setOrigin(&rhs, absolute);
142 grk_rect<T>& setOrigin(grk_rect<T>* rhs,
bool absolute)
148 assert(
x0 >= rhs->origin_x0);
149 assert(
y0 >= rhs->origin_y0);
156 grk_rect<T>& toRelative(
void)
166 grk_rect<T>& toAbsolute(
void)
174 virtual void print(
void)
const
176 GRK_INFO(
"[%u,%u,%u,%u,%u,%u]",
origin_x0,
origin_y0,
x0,
y0,
x1,
y1);
178 std::string boundsString()
const
180 std::ostringstream os;
185 bool valid(
void)
const
189 bool empty(
void)
const
193 bool contains(grk_pt<T> pt)
195 return contains(pt.x, pt.y);
197 bool contains(T
x, T
y)
201 grk_rect<T>& operator=(
const grk_rect<T>& rhs)
203 return operator=(&rhs);
205 grk_rect<T>& operator=(
const grk_rect<T>* rhs)
208 if(rhs && (
this != rhs))
225 origin_y0 == rhs.origin_y0 &&
x0 == rhs.x0 &&
y0 == rhs.y0 &&
x1 == rhs.x1 &&
228 void setRect(grk_rect<T>* rhs)
232 void setRect(grk_rect<T> rhs)
236 grk_rect<T> scaleDownCeil(uint32_t den)
const
241 grk_rect<T>
scale(uint32_t scalex, uint32_t scaley)
const
244 x1 * scalex,
y1 * scaley);
246 grk_rect<T> scaleDown(uint64_t denx, uint64_t deny)
const
249 (T)(
y0 / deny), (T)ceildiv<uint64_t>(
x1, denx),
250 (T)ceildiv<uint64_t>(
y1, deny));
252 grk_rect<T> scaleDownPow2(uint32_t powx, uint32_t powy)
const
255 (T)(
y0 >> powy), (T)ceildivpow2<uint64_t>(
x1, powx),
256 (T)ceildivpow2<uint64_t>(
y1, powy));
258 grk_rect<T> scaleDownPow2(grk_pt<T> pow)
const
260 return scaleDownPow2(pow.x, pow.y);
262 grk_rect<T> scaleDownCeil(uint64_t denx, uint64_t deny)
const
264 return grk_rect<T>(ceildiv<uint64_t>(
origin_x0, denx), ceildiv<uint64_t>(
origin_y0, deny),
265 ceildiv<uint64_t>(
x0, denx), ceildiv<uint64_t>(
y0, deny),
266 ceildiv<uint64_t>(
x1, denx), ceildiv<uint64_t>(
y1, deny));
268 grk_rect<T> scaleDownCeilPow2(uint32_t power)
const
274 grk_rect<T> scaleDownCeilPow2(uint32_t powx, uint32_t powy)
const
276 return grk_rect<T>(ceildivpow2<uint64_t>(
origin_x0, powx),
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));
281 grk_rect<T> intersection(
const grk_rect<T> rhs)
const
285 return intersection(&rhs);
287 bool isContainedIn(
const grk_rect<T> rhs)
const
289 return (intersection(&rhs) == *
this);
291 grk_rect<T>
clip(
const grk_rect<T>* rhs)
const
294 return grk_rect<T>(std::max<T>(
x0, rhs->x0), std::max<T>(
y0, rhs->y0),
295 std::min<T>(
x1, rhs->x1), std::min<T>(
y1, rhs->y1));
297 grk_rect<T>
clip(
const grk_rect<T>& rhs)
const
301 grk_rect<T>& clip_IN_PLACE(
const grk_rect<T>& rhs)
304 *
this = grk_rect<T>(std::max<T>(
x0, rhs.x0), std::max<T>(
y0, rhs.y0),
305 std::min<T>(
x1, rhs.x1), std::min<T>(
y1, rhs.y1));
309 grk_rect<T> intersection(
const grk_rect<T>* rhs)
const
312 return grk_rect<T>(std::max<T>(
x0, rhs->x0), std::max<T>(
y0, rhs->y0),
313 std::min<T>(
x1, rhs->x1), std::min<T>(
y1, rhs->y1));
315 bool nonEmptyIntersection(
const grk_rect<T>* rhs)
const
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);
321 grk_rect<T> rectUnion(
const grk_rect<T>* rhs)
const
324 return grk_rect<T>(std::min<T>(
x0, rhs->x0), std::min<T>(
y0, rhs->y0),
325 std::max<T>(
x1, rhs->x1), std::max<T>(
y1, rhs->y1));
327 grk_rect<T> rectUnion(
const grk_rect<T>& rhs)
const
329 return rectUnion(&rhs);
331 uint64_t area(
void)
const
333 return (uint64_t)(
x1 -
x0) * (
y1 -
y0);
343 grk_line<T> dimX()
const
345 return grk_line<T>(
x0,
x1);
347 grk_line<T> dimY()
const
349 return grk_line<T>(
y0,
y1);
352 grk_rect<T> pan(int64_t
x, int64_t
y)
const
356 return rc.pan_IN_PLACE(
x,
y);
358 grk_rect<T>& pan_IN_PLACE(int64_t
x, int64_t
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);
368 grk_rect<T>& grow_IN_PLACE(T boundary)
370 return grow_IN_PLACE(boundary, boundary, (std::numeric_limits<T>::max)(),
371 (std::numeric_limits<T>::max)());
373 grk_rect<T>& grow_IN_PLACE(T boundaryx, T boundaryy)
375 return grow_IN_PLACE(boundaryx, boundaryy, (std::numeric_limits<T>::max)(),
376 (std::numeric_limits<T>::max)());
378 grk_rect<T>& grow_IN_PLACE(T boundary, T maxX, T maxY)
380 return grow_IN_PLACE(boundary, boundary, maxX, maxY);
382 grk_rect<T>& grow_IN_PLACE(T boundaryx, T boundaryy, T maxX, T maxY)
384 return grow_IN_PLACE(boundaryx, boundaryy, grk_rect<T>((T)0, (T)0, maxX, maxY));
386 grk_rect<T>& grow_IN_PLACE(T boundary, grk_rect<T>
bounds)
388 return grow_IN_PLACE(boundary, boundary,
bounds);
390 grk_rect<T>& grow_IN_PLACE(T boundaryx, T boundaryy, grk_rect<T>
bounds)
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);
399 T parityX(
void)
const
403 T parityY(
void)
const
uint32_t y
Definition BlockExec.h:39
uint32_t x
Definition BlockExec.h:38
bool valid
Definition PacketIter.h:172
grk_rect32 bounds
Definition SparseCanvas.h:275
T val[N]
Definition WaveletCommon.h:65
bool absoluteCoordinates
Definition geometry.h:122
T origin_y0
Definition geometry.h:123
T origin_x0
Definition geometry.h:123
T clip(int64_t val)
Definition TileCache.h:66
uint32_t ceildiv(T a, T b)
Divide an integer by another integer and round upwards.
Definition TileCache.h:34
T ceildivpow2(T a, uint32_t b)
Definition TileCache.h:41
void GRK_INFO(const char *fmt,...)
Copyright (C) 2016-2023 Grok Image Compression Inc.
Definition ICacheable.h:20
T satAdd(int64_t lhs, int64_t rhs)
Definition geometry.h:77
T clip(int64_t val)
Definition geometry.h:66
grk_rect< float > grk_rect_single
Definition geometry.h:63
grk_line< uint32_t > grk_line32
Definition geometry.h:57
grk_pt< uint16_t > grk_pt16
Definition geometry.h:41
T satSub(T lhs, T rhs)
Definition geometry.h:89
grk_rect< uint32_t > grk_rect32
Definition geometry.h:61
const double scale
Definition RateControl.cpp:163
grk_pt< uint32_t > grk_pt32
Definition geometry.h:40
grk_rect< uint16_t > grk_rect16
Definition geometry.h:62
HWY_API Mask128< T, N > operator==(const Vec128< T, N > a, const Vec128< T, N > b)
Definition emu128-inl.h:1139
uint32_t y0
Definition t1_common.h:75
uint32_t x1
Definition t1_common.h:75
uint32_t x0
Definition t1_common.h:75
uint32_t y1
Definition t1_common.h:75