Blender V4.3
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#ifndef __UTIL_RECT_H__
6#define __UTIL_RECT_H__
7
8#include "util/types.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(int x0, int y0, int w, int h)
16{
17 return make_int4(x0, y0, x0 + w, y0 + h);
18}
19
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. */
38{
39 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 int idx,
47 ccl_private int *x,
48 ccl_private int *y)
49{
50 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
62
63#endif /* __UTIL_RECT_H__ */
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
local_group_size(16, 16) .push_constant(Type b
#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 rect_is_valid(int4 rect)
Definition rect.h:31
ccl_device_inline bool local_index_to_coord(int4 rect, int idx, ccl_private int *x, ccl_private int *y)
Definition rect.h:45
CCL_NAMESPACE_BEGIN ccl_device_inline int4 rect_from_shape(int x0, int y0, int w, int h)
Definition rect.h:15
ccl_device_inline int4 rect_clip(int4 a, int4 b)
Definition rect.h:26
ccl_device_inline int coord_to_local_index(int4 rect, int x, int y)
Definition rect.h:37
ccl_device_inline int4 rect_expand(int4 rect, int d)
Definition rect.h:20
ccl_device_inline int rect_size(int4 rect)
Definition rect.h:56
#define min(a, b)
Definition sort.c:32
float max