Blender V4.3
BLI_rect.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11#include "BLI_compiler_compat.h"
12#include "BLI_sys_types.h" /* bool */
13#include "DNA_vec_types.h"
14
15struct rctf;
16struct rcti;
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
28bool BLI_rcti_is_empty(const struct rcti *rect);
29bool BLI_rctf_is_empty(const struct rctf *rect);
30void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax);
31void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax);
39bool BLI_rctf_is_valid(const struct rctf *rect);
40bool BLI_rcti_is_valid(const struct rcti *rect);
44void BLI_rctf_sanitize(struct rctf *rect);
45void BLI_rcti_sanitize(struct rcti *rect);
46void BLI_rctf_init_pt_radius(struct rctf *rect, const float xy[2], float size);
47void BLI_rcti_init_pt_radius(struct rcti *rect, const int xy[2], int size);
48void BLI_rcti_init_minmax(struct rcti *rect);
49void BLI_rctf_init_minmax(struct rctf *rect);
50void BLI_rcti_do_minmax_v(struct rcti *rect, const int xy[2]);
51void BLI_rctf_do_minmax_v(struct rctf *rect, const float xy[2]);
52void BLI_rcti_do_minmax_rcti(struct rcti *rect, const struct rcti *other);
53
57void BLI_rctf_transform_pt_v(const rctf *dst,
58 const rctf *src,
59 float xy_dst[2],
60 const float xy_src[2]);
68 const rctf *dst, const rctf *src, float matrix[4][4], uint x, uint y);
69void BLI_rctf_transform_calc_m4_pivot_min(const rctf *dst, const rctf *src, float matrix[4][4]);
70
71void BLI_rctf_translate(struct rctf *rect, float x, float y);
72void BLI_rcti_translate(struct rcti *rect, int x, int y);
73void BLI_rctf_mul(struct rctf *rect, float factor);
74void BLI_rcti_mul(struct rcti *rect, int factor);
75void BLI_rcti_recenter(struct rcti *rect, int x, int y);
76void BLI_rctf_recenter(struct rctf *rect, float x, float y);
77void BLI_rcti_resize(struct rcti *rect, int x, int y);
81void BLI_rcti_resize_x(struct rcti *rect, int x);
85void BLI_rcti_resize_y(struct rcti *rect, int y);
86void BLI_rcti_pad(struct rcti *rect, int pad_x, int pad_y);
87void BLI_rctf_pad(struct rctf *rect, float pad_x, float pad_y);
88void BLI_rctf_resize(struct rctf *rect, float x, float y);
89void BLI_rctf_resize_x(struct rctf *rect, float x);
90void BLI_rctf_resize_y(struct rctf *rect, float y);
91void BLI_rcti_scale(rcti *rect, float scale);
92void BLI_rctf_scale(rctf *rect, float scale);
93void BLI_rctf_pad_y(struct rctf *rect, float boundary_size, float pad_min, float pad_max);
94void BLI_rctf_interp(struct rctf *rect,
95 const struct rctf *rect_a,
96 const struct rctf *rect_b,
97 float fac);
98// void BLI_rcti_interp(struct rctf *rect, struct rctf *rect_a, struct rctf *rect_b, float fac);
99bool BLI_rctf_clamp_pt_v(const struct rctf *rect, float xy[2]);
100bool BLI_rcti_clamp_pt_v(const struct rcti *rect, int xy[2]);
109bool BLI_rctf_clamp(struct rctf *rect, const struct rctf *rect_bounds, float r_xy[2]);
110bool BLI_rcti_clamp(struct rcti *rect, const struct rcti *rect_bounds, int r_xy[2]);
111bool BLI_rctf_compare(const struct rctf *rect_a, const struct rctf *rect_b, float limit);
112bool BLI_rcti_compare(const struct rcti *rect_a, const struct rcti *rect_b);
113bool BLI_rctf_isect(const struct rctf *src1, const struct rctf *src2, struct rctf *dest);
114bool BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest);
115bool BLI_rctf_isect_rect_x(const struct rctf *src1, const struct rctf *src2, float range_x[2]);
116bool BLI_rctf_isect_rect_y(const struct rctf *src1, const struct rctf *src2, float range_y[2]);
117bool BLI_rcti_isect_rect_x(const struct rcti *src1, const struct rcti *src2, int range_x[2]);
118bool BLI_rcti_isect_rect_y(const struct rcti *src1, const struct rcti *src2, int range_y[2]);
119bool BLI_rcti_isect_x(const rcti *rect, int x);
120bool BLI_rcti_isect_y(const rcti *rect, int y);
121bool BLI_rcti_isect_pt(const struct rcti *rect, int x, int y);
122bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2]);
123bool BLI_rctf_isect_x(const rctf *rect, float x);
124bool BLI_rctf_isect_y(const rctf *rect, float y);
125bool BLI_rctf_isect_pt(const struct rctf *rect, float x, float y);
126bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2]);
130int BLI_rcti_length_x(const rcti *rect, int x);
134int BLI_rcti_length_y(const rcti *rect, int y);
135float BLI_rctf_length_x(const rctf *rect, float x);
136float BLI_rctf_length_y(const rctf *rect, float y);
137bool BLI_rcti_isect_segment(const struct rcti *rect, const int s1[2], const int s2[2]);
138bool BLI_rctf_isect_segment(const struct rctf *rect, const float s1[2], const float s2[2]);
139bool BLI_rcti_isect_circle(const struct rcti *rect, const float xy[2], float radius);
140bool BLI_rctf_isect_circle(const struct rctf *rect, const float xy[2], float radius);
141bool BLI_rcti_inside_rcti(const rcti *rct_a, const rcti *rct_b);
145bool BLI_rctf_inside_rctf(const rctf *rct_a, const rctf *rct_b);
146void BLI_rcti_union(struct rcti *rct_a, const struct rcti *rct_b);
147void BLI_rctf_union(struct rctf *rct_a, const struct rctf *rct_b);
148void BLI_rcti_rctf_copy(struct rcti *dst, const struct rctf *src);
149void BLI_rctf_rcti_copy(struct rctf *dst, const struct rcti *src);
150void BLI_rcti_rctf_copy_floor(struct rcti *dst, const struct rctf *src);
151void BLI_rcti_rctf_copy_round(struct rcti *dst, const struct rctf *src);
152
156void BLI_rctf_rotate_expand(rctf *dst, const rctf *src, float angle);
157
158void print_rctf(const char *str, const struct rctf *rect);
159void print_rcti(const char *str, const struct rcti *rect);
160
161#define print_rctf_id(rect) print_rctf(STRINGIFY(rect), rect)
162#define print_rcti_id(rect) print_rcti(STRINGIFY(rect), rect)
163
164BLI_INLINE float BLI_rcti_cent_x_fl(const struct rcti *rct)
165{
166 return (float)(rct->xmin + rct->xmax) / 2.0f;
167}
168BLI_INLINE float BLI_rcti_cent_y_fl(const struct rcti *rct)
169{
170 return (float)(rct->ymin + rct->ymax) / 2.0f;
171}
172BLI_INLINE int BLI_rcti_cent_x(const struct rcti *rct)
173{
174 return (rct->xmin + rct->xmax) / 2;
175}
176BLI_INLINE int BLI_rcti_cent_y(const struct rcti *rct)
177{
178 return (rct->ymin + rct->ymax) / 2;
179}
180BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
181{
182 return (rct->xmin + rct->xmax) / 2.0f;
183}
184BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
185{
186 return (rct->ymin + rct->ymax) / 2.0f;
187}
188
189BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
190{
191 return (rct->xmax - rct->xmin);
192}
193BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
194{
195 return (rct->ymax - rct->ymin);
196}
197BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
198{
199 return (rct->xmax - rct->xmin);
200}
201BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
202{
203 return (rct->ymax - rct->ymin);
204}
205
206#ifdef __cplusplus
207}
208#endif
#define BLI_INLINE
bool BLI_rctf_is_empty(const struct rctf *rect)
void BLI_rcti_union(struct rcti *rct_a, const struct rcti *rct_b)
bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2])
void print_rctf(const char *str, const struct rctf *rect)
void BLI_rctf_translate(struct rctf *rect, float x, float y)
Definition rct.c:567
bool BLI_rcti_isect_rect_y(const struct rcti *src1, const struct rcti *src2, int range_y[2])
bool BLI_rctf_isect_x(const rctf *rect, float x)
Definition rct.c:93
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.h:193
void BLI_rcti_init_minmax(struct rcti *rect)
Definition rct.c:478
bool BLI_rcti_compare(const struct rcti *rect_a, const struct rcti *rect_b)
bool BLI_rctf_clamp_pt_v(const struct rctf *rect, float xy[2])
void BLI_rctf_union(struct rctf *rct_a, const struct rctf *rct_b)
bool BLI_rctf_is_valid(const struct rctf *rect)
BLI_INLINE float BLI_rcti_cent_x_fl(const struct rcti *rct)
Definition BLI_rect.h:164
void BLI_rctf_resize_y(struct rctf *rect, float y)
Definition rct.c:645
int BLI_rcti_length_x(const rcti *rect, int x)
Definition rct.c:149
bool BLI_rcti_isect_y(const rcti *rect, int y)
Definition rct.c:48
bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2])
void BLI_rcti_init_pt_radius(struct rcti *rect, const int xy[2], int size)
Definition rct.c:470
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition BLI_rect.h:184
void BLI_rcti_mul(struct rcti *rect, int factor)
Definition rct.c:575
bool BLI_rcti_isect_segment(const struct rcti *rect, const int s1[2], const int s2[2])
void BLI_rctf_transform_pt_v(const rctf *dst, const rctf *src, float xy_dst[2], const float xy_src[2])
Definition rct.c:530
bool BLI_rctf_isect(const struct rctf *src1, const struct rctf *src2, struct rctf *dest)
BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
Definition BLI_rect.h:180
bool BLI_rctf_isect_y(const rctf *rect, float y)
Definition rct.c:104
bool BLI_rctf_clamp(struct rctf *rect, const struct rctf *rect_bounds, float r_xy[2])
void BLI_rcti_rctf_copy_round(struct rcti *dst, const struct rctf *src)
void BLI_rcti_pad(struct rcti *rect, int pad_x, int pad_y)
Definition rct.c:623
bool BLI_rcti_is_valid(const struct rcti *rect)
void BLI_rcti_rctf_copy_floor(struct rcti *dst, const struct rctf *src)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.c:560
void BLI_rctf_pad_y(struct rctf *rect, float boundary_size, float pad_min, float pad_max)
Definition rct.c:683
int BLI_rcti_length_y(const rcti *rect, int y)
Definition rct.c:160
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.c:418
void BLI_rcti_resize_y(struct rcti *rect, int y)
Definition rct.c:609
void BLI_rcti_recenter(struct rcti *rect, int x, int y)
Definition rct.c:590
void BLI_rctf_resize_x(struct rctf *rect, float x)
Definition rct.c:639
void BLI_rctf_sanitize(struct rctf *rect)
Definition rct.c:438
bool BLI_rcti_isect_pt(const struct rcti *rect, int x, int y)
void BLI_rctf_transform_calc_m4_pivot_min(const rctf *dst, const rctf *src, float matrix[4][4])
Definition rct.c:555
void BLI_rctf_scale(rctf *rect, float scale)
Definition rct.c:671
void BLI_rcti_resize(struct rcti *rect, int x, int y)
Definition rct.c:615
void BLI_rctf_transform_calc_m4_pivot_min_ex(const rctf *dst, const rctf *src, float matrix[4][4], uint x, uint y)
Definition rct.c:542
float BLI_rctf_length_x(const rctf *rect, float x)
Definition rct.c:171
bool BLI_rctf_isect_rect_y(const struct rctf *src1, const struct rctf *src2, float range_y[2])
bool BLI_rctf_isect_segment(const struct rctf *rect, const float s1[2], const float s2[2])
bool BLI_rcti_clamp_pt_v(const struct rcti *rect, int xy[2])
bool BLI_rctf_isect_rect_x(const struct rctf *src1, const struct rctf *src2, float range_x[2])
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
Definition rct.c:408
bool BLI_rctf_isect_circle(const struct rctf *rect, const float xy[2], float radius)
void BLI_rcti_sanitize(struct rcti *rect)
Definition rct.c:450
void BLI_rctf_recenter(struct rctf *rect, float x, float y)
Definition rct.c:596
bool BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest)
bool BLI_rcti_isect_x(const rcti *rect, int x)
Definition rct.c:37
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.h:189
bool BLI_rcti_isect_rect_x(const struct rcti *src1, const struct rcti *src2, int range_x[2])
void BLI_rcti_scale(rcti *rect, float scale)
Definition rct.c:659
void BLI_rctf_pad(struct rctf *rect, float pad_x, float pad_y)
Definition rct.c:631
bool BLI_rctf_isect_pt(const struct rctf *rect, float x, float y)
BLI_INLINE float BLI_rcti_cent_y_fl(const struct rcti *rct)
Definition BLI_rect.h:168
BLI_INLINE int BLI_rcti_cent_y(const struct rcti *rct)
Definition BLI_rect.h:176
void BLI_rctf_rcti_copy(struct rctf *dst, const struct rcti *src)
void BLI_rcti_resize_x(struct rcti *rect, int x)
Definition rct.c:603
bool BLI_rcti_isect_circle(const struct rcti *rect, const float xy[2], float radius)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.h:197
bool BLI_rctf_inside_rctf(const rctf *rct_a, const rctf *rct_b)
Definition rct.c:193
void BLI_rctf_mul(struct rctf *rect, float factor)
Definition rct.c:582
void BLI_rcti_rctf_copy(struct rcti *dst, const struct rctf *src)
void BLI_rctf_do_minmax_v(struct rctf *rect, const float xy[2])
Definition rct.c:514
bool BLI_rcti_is_empty(const struct rcti *rect)
bool BLI_rcti_inside_rcti(const rcti *rct_a, const rcti *rct_b)
Definition rct.c:198
void BLI_rctf_interp(struct rctf *rect, const struct rctf *rect_a, const struct rctf *rect_b, float fac)
void BLI_rctf_resize(struct rctf *rect, float x, float y)
Definition rct.c:651
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.h:201
void print_rcti(const char *str, const struct rcti *rect)
bool BLI_rcti_clamp(struct rcti *rect, const struct rcti *rect_bounds, int r_xy[2])
void BLI_rctf_rotate_expand(rctf *dst, const rctf *src, float angle)
Definition rct.c:1099
void BLI_rctf_init_pt_radius(struct rctf *rect, const float xy[2], float size)
Definition rct.c:462
void BLI_rcti_do_minmax_v(struct rcti *rect, const int xy[2])
Definition rct.c:490
void BLI_rcti_do_minmax_rcti(struct rcti *rect, const struct rcti *other)
bool BLI_rctf_compare(const struct rctf *rect_a, const struct rctf *rect_b, float limit)
float BLI_rctf_length_y(const rctf *rect, float y)
Definition rct.c:182
BLI_INLINE int BLI_rcti_cent_x(const struct rcti *rct)
Definition BLI_rect.h:172
void BLI_rctf_init_minmax(struct rctf *rect)
Definition rct.c:484
unsigned int uint
#define str(s)
float xmax
float xmin
float ymax
float ymin
int ymin
int ymax
int xmin
int xmax
int xy[2]
Definition wm_draw.cc:170