Blender V5.0
rect.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2017-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "util/math_base.h"
8#include "util/types_int4.h"
9
11
12/* Rectangles are represented as a int4 containing the coordinates of the lower-left and
13 * upper-right corners in the order (x0, y0, x1, y1). */
14
15ccl_device_inline int4 rect_from_shape(const int x0, const int y0, const int w, int h)
16{
17 return make_int4(x0, y0, x0 + w, y0 + h);
18}
19
20ccl_device_inline int4 rect_expand(const int4 rect, const int d)
21{
22 return make_int4(rect.x - d, rect.y - d, rect.z + d, rect.w + d);
23}
24
25/* Returns the intersection of two rects. */
27{
28 return make_int4(max(a.x, b.x), max(a.y, b.y), min(a.z, b.z), min(a.w, b.w));
29}
30
32{
33 return (rect.z > rect.x) && (rect.w > rect.y);
34}
35
36/* Returns the local row-major index of the pixel inside the rect. */
37ccl_device_inline int coord_to_local_index(const int4 rect, const int x, int y)
38{
39 const int w = rect.z - rect.x;
40 return (y - rect.y) * w + (x - rect.x);
41}
42
43/* Finds the coordinates of a pixel given by its row-major index in the rect,
44 * and returns whether the pixel is inside it. */
46 const int idx,
47 ccl_private int *x,
48 ccl_private int *y)
49{
50 const int w = rect.z - rect.x;
51 *x = (idx % w) + rect.x;
52 *y = (idx / w) + rect.y;
53 return (*y < rect.w);
54}
55
57{
58 return (rect.z - rect.x) * (rect.w - rect.y);
59}
60
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
#define ccl_private
#define ccl_device_inline
#define CCL_NAMESPACE_END
ccl_device_forceinline int4 make_int4(const int x, const int y, const int z, const int w)
ccl_device_inline bool local_index_to_coord(const int4 rect, const int idx, ccl_private int *x, ccl_private int *y)
Definition rect.h:45
ccl_device_inline int coord_to_local_index(const int4 rect, const int x, int y)
Definition rect.h:37
ccl_device_inline int rect_size(const int4 rect)
Definition rect.h:56
CCL_NAMESPACE_BEGIN ccl_device_inline int4 rect_from_shape(const int x0, const int y0, const int w, int h)
Definition rect.h:15
ccl_device_inline int4 rect_clip(const int4 a, const int4 b)
Definition rect.h:26
ccl_device_inline int4 rect_expand(const int4 rect, const int d)
Definition rect.h:20
ccl_device_inline bool rect_is_valid(const int4 rect)
Definition rect.h:31
#define min(a, b)
Definition sort.cc:36
max
Definition text_draw.cc:251