Blender  V3.3
rect.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2017-2022 Blender Foundation */
3 
4 #ifndef __UTIL_RECT_H__
5 #define __UTIL_RECT_H__
6 
7 #include "util/types.h"
8 
10 
11 /* Rectangles are represented as a int4 containing the coordinates of the lower-left and
12  * upper-right corners in the order (x0, y0, x1, y1). */
13 
14 ccl_device_inline int4 rect_from_shape(int x0, int y0, int w, int h)
15 {
16  return make_int4(x0, y0, x0 + w, y0 + h);
17 }
18 
20 {
21  return make_int4(rect.x - d, rect.y - d, rect.z + d, rect.w + d);
22 }
23 
24 /* Returns the intersection of two rects. */
26 {
27  return make_int4(max(a.x, b.x), max(a.y, b.y), min(a.z, b.z), min(a.w, b.w));
28 }
29 
31 {
32  return (rect.z > rect.x) && (rect.w > rect.y);
33 }
34 
35 /* Returns the local row-major index of the pixel inside the rect. */
37 {
38  int w = rect.z - rect.x;
39  return (y - rect.y) * w + (x - rect.x);
40 }
41 
42 /* Finds the coordinates of a pixel given by its row-major index in the rect,
43  * and returns whether the pixel is inside it. */
45  int idx,
46  ccl_private int *x,
47  ccl_private int *y)
48 {
49  int w = rect.z - rect.x;
50  *x = (idx % w) + rect.x;
51  *y = (idx / w) + rect.y;
52  return (*y < rect.w);
53 }
54 
56 {
57  return (rect.z - rect.x) * (rect.w - rect.y);
58 }
59 
61 
62 #endif /* __UTIL_RECT_H__ */
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
int x
Definition: btConvexHull.h:149
int w
Definition: btConvexHull.h:149
int y
Definition: btConvexHull.h:149
int z
Definition: btConvexHull.h:149
#define ccl_private
Definition: cuda/compat.h:48
#define ccl_device_inline
Definition: cuda/compat.h:34
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
#define make_int4(x, y, z, w)
Definition: metal/compat.h:208
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
ccl_device_inline bool rect_is_valid(int4 rect)
Definition: rect.h:30
ccl_device_inline bool local_index_to_coord(int4 rect, int idx, ccl_private int *x, ccl_private int *y)
Definition: rect.h:44
CCL_NAMESPACE_BEGIN ccl_device_inline int4 rect_from_shape(int x0, int y0, int w, int h)
Definition: rect.h:14
ccl_device_inline int4 rect_clip(int4 a, int4 b)
Definition: rect.h:25
ccl_device_inline int coord_to_local_index(int4 rect, int x, int y)
Definition: rect.h:36
ccl_device_inline int4 rect_expand(int4 rect, int d)
Definition: rect.h:19
ccl_device_inline int rect_size(int4 rect)
Definition: rect.h:55
#define min(a, b)
Definition: sort.c:35
float max