Blender  V2.93
util_rect.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __UTIL_RECT_H__
18 #define __UTIL_RECT_H__
19 
20 #include "util/util_types.h"
21 
23 
24 /* Rectangles are represented as a int4 containing the coordinates of the lower-left and
25  * upper-right corners in the order (x0, y0, x1, y1). */
26 
27 ccl_device_inline int4 rect_from_shape(int x0, int y0, int w, int h)
28 {
29  return make_int4(x0, y0, x0 + w, y0 + h);
30 }
31 
33 {
34  return make_int4(rect.x - d, rect.y - d, rect.z + d, rect.w + d);
35 }
36 
37 /* Returns the intersection of two rects. */
39 {
40  return make_int4(max(a.x, b.x), max(a.y, b.y), min(a.z, b.z), min(a.w, b.w));
41 }
42 
44 {
45  return (rect.z > rect.x) && (rect.w > rect.y);
46 }
47 
48 /* Returns the local row-major index of the pixel inside the rect. */
50 {
51  int w = rect.z - rect.x;
52  return (y - rect.y) * w + (x - rect.x);
53 }
54 
55 /* Finds the coordinates of a pixel given by its row-major index in the rect,
56  * and returns whether the pixel is inside it. */
57 ccl_device_inline bool local_index_to_coord(int4 rect, int idx, int *x, int *y)
58 {
59  int w = rect.z - rect.x;
60  *x = (idx % w) + rect.x;
61  *y = (idx / w) + rect.y;
62  return (*y < rect.w);
63 }
64 
66 {
67  return (rect.z - rect.x) * (rect.w - rect.y);
68 }
69 
71 
72 #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_device_inline
#define CCL_NAMESPACE_END
#define make_int4(x, y, z, w)
static unsigned a[3]
Definition: RandGen.cpp:92
#define min(a, b)
Definition: sort.c:51
float max
ccl_device_inline bool rect_is_valid(int4 rect)
Definition: util_rect.h:43
CCL_NAMESPACE_BEGIN ccl_device_inline int4 rect_from_shape(int x0, int y0, int w, int h)
Definition: util_rect.h:27
ccl_device_inline int4 rect_clip(int4 a, int4 b)
Definition: util_rect.h:38
ccl_device_inline int coord_to_local_index(int4 rect, int x, int y)
Definition: util_rect.h:49
ccl_device_inline int4 rect_expand(int4 rect, int d)
Definition: util_rect.h:32
ccl_device_inline bool local_index_to_coord(int4 rect, int idx, int *x, int *y)
Definition: util_rect.h:57
ccl_device_inline int rect_size(int4 rect)
Definition: util_rect.h:65