Blender V5.3
rct.cc
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
10
11#include <algorithm>
12#include <cfloat>
13#include <climits>
14#include <cmath>
15#include <cstdio>
16#include <cstdlib>
17
18#include "BLI_math_base_c.hh"
19#include "BLI_math_geom_c.hh"
20#include "BLI_math_matrix_c.hh"
21#include "BLI_math_vector.hh"
22#include "BLI_rect.hh"
23#include "BLI_utildefines.hh"
24
25#include "DNA_vec_types.h"
26
27namespace blender {
28
29bool BLI_rcti_is_empty(const rcti *rect)
30{
31 return ((rect->xmax <= rect->xmin) || (rect->ymax <= rect->ymin));
32}
33
34bool BLI_rctf_is_empty(const rctf *rect)
35{
36 return ((rect->xmax <= rect->xmin) || (rect->ymax <= rect->ymin));
37}
38
39bool BLI_rcti_isect_x(const rcti *rect, const int x)
40{
41 if (x < rect->xmin) {
42 return false;
43 }
44 if (x > rect->xmax) {
45 return false;
46 }
47 return true;
48}
49
50bool BLI_rcti_isect_y(const rcti *rect, const int y)
51{
52 if (y < rect->ymin) {
53 return false;
54 }
55 if (y > rect->ymax) {
56 return false;
57 }
58 return true;
59}
60
61bool BLI_rcti_isect_pt(const rcti *rect, const int x, const int y)
62{
63 if (x < rect->xmin) {
64 return false;
65 }
66 if (x > rect->xmax) {
67 return false;
68 }
69 if (y < rect->ymin) {
70 return false;
71 }
72 if (y > rect->ymax) {
73 return false;
74 }
75 return true;
76}
77
78bool BLI_rcti_isect_pt_v(const rcti *rect, const int xy[2])
79{
80 if (xy[0] < rect->xmin) {
81 return false;
82 }
83 if (xy[0] > rect->xmax) {
84 return false;
85 }
86 if (xy[1] < rect->ymin) {
87 return false;
88 }
89 if (xy[1] > rect->ymax) {
90 return false;
91 }
92 return true;
93}
94
95bool BLI_rctf_isect_x(const rctf *rect, const float x)
96{
97 if (x < rect->xmin) {
98 return false;
99 }
100 if (x > rect->xmax) {
101 return false;
102 }
103 return true;
104}
105
106bool BLI_rctf_isect_y(const rctf *rect, const float y)
107{
108 if (y < rect->ymin) {
109 return false;
110 }
111 if (y > rect->ymax) {
112 return false;
113 }
114 return true;
115}
116
117bool BLI_rctf_isect_pt(const rctf *rect, const float x, const float y)
118{
119 if (x < rect->xmin) {
120 return false;
121 }
122 if (x > rect->xmax) {
123 return false;
124 }
125 if (y < rect->ymin) {
126 return false;
127 }
128 if (y > rect->ymax) {
129 return false;
130 }
131 return true;
132}
133
134bool BLI_rctf_isect_pt_v(const rctf *rect, const float xy[2])
135{
136 if (xy[0] < rect->xmin) {
137 return false;
138 }
139 if (xy[0] > rect->xmax) {
140 return false;
141 }
142 if (xy[1] < rect->ymin) {
143 return false;
144 }
145 if (xy[1] > rect->ymax) {
146 return false;
147 }
148 return true;
149}
150
151int BLI_rcti_length_x(const rcti *rect, const int x)
152{
153 if (x < rect->xmin) {
154 return rect->xmin - x;
155 }
156 if (x > rect->xmax) {
157 return x - rect->xmax;
158 }
159 return 0;
160}
161
162int BLI_rcti_length_y(const rcti *rect, const int y)
163{
164 if (y < rect->ymin) {
165 return rect->ymin - y;
166 }
167 if (y > rect->ymax) {
168 return y - rect->ymax;
169 }
170 return 0;
171}
172
173float BLI_rctf_length_x(const rctf *rect, const float x)
174{
175 if (x < rect->xmin) {
176 return rect->xmin - x;
177 }
178 if (x > rect->xmax) {
179 return x - rect->xmax;
180 }
181 return 0.0f;
182}
183
184float BLI_rctf_length_y(const rctf *rect, const float y)
185{
186 if (y < rect->ymin) {
187 return rect->ymin - y;
188 }
189 if (y > rect->ymax) {
190 return y - rect->ymax;
191 }
192 return 0.0f;
193}
194
195bool BLI_rctf_inside_rctf(const rctf *rct_a, const rctf *rct_b)
196{
197 return ((rct_a->xmin <= rct_b->xmin) && (rct_a->xmax >= rct_b->xmax) &&
198 (rct_a->ymin <= rct_b->ymin) && (rct_a->ymax >= rct_b->ymax));
199}
200bool BLI_rcti_inside_rcti(const rcti *rct_a, const rcti *rct_b)
201{
202 return ((rct_a->xmin <= rct_b->xmin) && (rct_a->xmax >= rct_b->xmax) &&
203 (rct_a->ymin <= rct_b->ymin) && (rct_a->ymax >= rct_b->ymax));
204}
205
206/* based closely on 'isect_seg_seg_v2_int',
207 * but in modified so corner cases are treated as intersections */
208static int isect_segments_i(const int v1[2], const int v2[2], const int v3[2], const int v4[2])
209{
210 const double div = double((v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]));
211 if (div == 0.0) {
212 return 1; /* co-linear */
213 }
214
215 const double lambda = double((v1[1] - v3[1]) * (v4[0] - v3[0]) -
216 (v1[0] - v3[0]) * (v4[1] - v3[1])) /
217 div;
218 const double mu = double((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) /
219 div;
220 return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0);
221}
222static int isect_segments_fl(const float v1[2],
223 const float v2[2],
224 const float v3[2],
225 const float v4[2])
226{
227 const double div = double((v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]));
228 if (div == 0.0) {
229 return 1; /* co-linear */
230 }
231
232 const double lambda = double((v1[1] - v3[1]) * (v4[0] - v3[0]) -
233 (v1[0] - v3[0]) * (v4[1] - v3[1])) /
234 div;
235 const double mu = double((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) /
236 div;
237 return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0);
238}
239
240bool BLI_rcti_isect_segment(const rcti *rect, const int s1[2], const int s2[2])
241{
242 /* first do outside-bounds check for both points of the segment */
243 if (s1[0] < rect->xmin && s2[0] < rect->xmin) {
244 return false;
245 }
246 if (s1[0] > rect->xmax && s2[0] > rect->xmax) {
247 return false;
248 }
249 if (s1[1] < rect->ymin && s2[1] < rect->ymin) {
250 return false;
251 }
252 if (s1[1] > rect->ymax && s2[1] > rect->ymax) {
253 return false;
254 }
255
256 /* if either points intersect then we definitely intersect */
257 if (BLI_rcti_isect_pt_v(rect, s1) || BLI_rcti_isect_pt_v(rect, s2)) {
258 return true;
259 }
260
261 /* both points are outside but may intersect the rect */
262 int tvec1[2];
263 int tvec2[2];
264 /* diagonal: [/] */
265 tvec1[0] = rect->xmin;
266 tvec1[1] = rect->ymin;
267 tvec2[0] = rect->xmax;
268 tvec2[1] = rect->ymax;
269 if (isect_segments_i(s1, s2, tvec1, tvec2)) {
270 return true;
271 }
272
273 /* diagonal: [\‍] */
274 tvec1[0] = rect->xmin;
275 tvec1[1] = rect->ymax;
276 tvec2[0] = rect->xmax;
277 tvec2[1] = rect->ymin;
278 if (isect_segments_i(s1, s2, tvec1, tvec2)) {
279 return true;
280 }
281
282 /* no intersection */
283 return false;
284}
285
286bool BLI_rctf_isect_segment(const rctf *rect, const float s1[2], const float s2[2])
287{
288 /* first do outside-bounds check for both points of the segment */
289 if (s1[0] < rect->xmin && s2[0] < rect->xmin) {
290 return false;
291 }
292 if (s1[0] > rect->xmax && s2[0] > rect->xmax) {
293 return false;
294 }
295 if (s1[1] < rect->ymin && s2[1] < rect->ymin) {
296 return false;
297 }
298 if (s1[1] > rect->ymax && s2[1] > rect->ymax) {
299 return false;
300 }
301
302 /* if either points intersect then we definitely intersect */
303 if (BLI_rctf_isect_pt_v(rect, s1) || BLI_rctf_isect_pt_v(rect, s2)) {
304 return true;
305 }
306
307 /* both points are outside but may intersect the rect */
308 float tvec1[2];
309 float tvec2[2];
310 /* diagonal: `[/]` */
311 tvec1[0] = rect->xmin;
312 tvec1[1] = rect->ymin;
313 tvec2[0] = rect->xmax;
314 tvec2[1] = rect->ymax;
315 if (isect_segments_fl(s1, s2, tvec1, tvec2)) {
316 return true;
317 }
318
319 /* diagonal: `[\‍]` */
320 tvec1[0] = rect->xmin;
321 tvec1[1] = rect->ymax;
322 tvec2[0] = rect->xmax;
323 tvec2[1] = rect->ymin;
324 if (isect_segments_fl(s1, s2, tvec1, tvec2)) {
325 return true;
326 }
327
328 /* no intersection */
329 return false;
330}
331
332bool BLI_rcti_isect_circle(const rcti *rect, const float xy[2], const float radius)
333{
334 float dx, dy;
335
336 if (xy[0] >= rect->xmin && xy[0] <= rect->xmax) {
337 dx = 0;
338 }
339 else {
340 dx = (xy[0] < rect->xmin) ? (rect->xmin - xy[0]) : (xy[0] - rect->xmax);
341 }
342
343 if (xy[1] >= rect->ymin && xy[1] <= rect->ymax) {
344 dy = 0;
345 }
346 else {
347 dy = (xy[1] < rect->ymin) ? (rect->ymin - xy[1]) : (xy[1] - rect->ymax);
348 }
349
350 return dx * dx + dy * dy <= radius * radius;
351}
352
353bool BLI_rctf_isect_circle(const rctf *rect, const float xy[2], const float radius)
354{
355 float dx, dy;
356
357 if (xy[0] >= rect->xmin && xy[0] <= rect->xmax) {
358 dx = 0;
359 }
360 else {
361 dx = (xy[0] < rect->xmin) ? (rect->xmin - xy[0]) : (xy[0] - rect->xmax);
362 }
363
364 if (xy[1] >= rect->ymin && xy[1] <= rect->ymax) {
365 dy = 0;
366 }
367 else {
368 dy = (xy[1] < rect->ymin) ? (rect->ymin - xy[1]) : (xy[1] - rect->ymax);
369 }
370
371 return dx * dx + dy * dy <= radius * radius;
372}
373
374void BLI_rctf_union(rctf *rct_a, const rctf *rct_b)
375{
376 if (rct_a->xmin > rct_b->xmin) {
377 rct_a->xmin = rct_b->xmin;
378 }
379 if (rct_a->xmax < rct_b->xmax) {
380 rct_a->xmax = rct_b->xmax;
381 }
382 if (rct_a->ymin > rct_b->ymin) {
383 rct_a->ymin = rct_b->ymin;
384 }
385 if (rct_a->ymax < rct_b->ymax) {
386 rct_a->ymax = rct_b->ymax;
387 }
388}
389
390void BLI_rctf_union_x(rctf *rct, const float x)
391{
392 rct->xmin = min_ff(rct->xmin, x);
393 rct->xmax = max_ff(rct->xmax, x);
394}
395
396void BLI_rctf_union_y(rctf *rct, const float y)
397{
398 rct->ymin = min_ff(rct->ymin, y);
399 rct->ymax = max_ff(rct->ymax, y);
400}
401
402void BLI_rcti_union(rcti *rct_a, const rcti *rct_b)
403{
404 if (rct_a->xmin > rct_b->xmin) {
405 rct_a->xmin = rct_b->xmin;
406 }
407 if (rct_a->xmax < rct_b->xmax) {
408 rct_a->xmax = rct_b->xmax;
409 }
410 if (rct_a->ymin > rct_b->ymin) {
411 rct_a->ymin = rct_b->ymin;
412 }
413 if (rct_a->ymax < rct_b->ymax) {
414 rct_a->ymax = rct_b->ymax;
415 }
416}
417
418void BLI_rctf_init(rctf *rect, float xmin, float xmax, float ymin, float ymax)
419{
420 rect->xmin = xmin;
421 rect->xmax = xmax;
422 rect->ymin = ymin;
423 rect->ymax = ymax;
424
425 BLI_rctf_sanitize(rect);
426}
427
428void BLI_rcti_init(rcti *rect, int xmin, int xmax, int ymin, int ymax)
429{
430 rect->xmin = xmin;
431 rect->xmax = xmax;
432 rect->ymin = ymin;
433 rect->ymax = ymax;
434
435 BLI_rcti_sanitize(rect);
436}
437
438bool BLI_rctf_is_valid(const rctf *rect)
439{
440 return (rect->xmin <= rect->xmax) && (rect->ymin <= rect->ymax);
441}
442
443bool BLI_rcti_is_valid(const rcti *rect)
444{
445 return (rect->xmin <= rect->xmax) && (rect->ymin <= rect->ymax);
446}
447
449{
450 if (rect->xmin > rect->xmax) {
451 SWAP(float, rect->xmin, rect->xmax);
452 }
453 if (rect->ymin > rect->ymax) {
454 SWAP(float, rect->ymin, rect->ymax);
455 }
456
458}
459
461{
462 if (rect->xmin > rect->xmax) {
463 SWAP(int, rect->xmin, rect->xmax);
464 }
465 if (rect->ymin > rect->ymax) {
466 SWAP(int, rect->ymin, rect->ymax);
467 }
468
470}
471
472void BLI_rctf_init_pt_radius(rctf *rect, const float xy[2], float size)
473{
474 rect->xmin = xy[0] - size;
475 rect->xmax = xy[0] + size;
476 rect->ymin = xy[1] - size;
477 rect->ymax = xy[1] + size;
478}
479
480void BLI_rcti_init_pt_radius(rcti *rect, const int xy[2], int size)
481{
482 rect->xmin = xy[0] - size;
483 rect->xmax = xy[0] + size;
484 rect->ymin = xy[1] - size;
485 rect->ymax = xy[1] + size;
486}
487
489{
490 rect->xmin = rect->ymin = INT_MAX;
491 rect->xmax = rect->ymax = INT_MIN;
492}
493
495{
496 rect->xmin = rect->ymin = FLT_MAX;
497 rect->xmax = rect->ymax = -FLT_MAX;
498}
499
500void BLI_rcti_do_minmax_v(rcti *rect, const int xy[2])
501{
502 if (xy[0] < rect->xmin) {
503 rect->xmin = xy[0];
504 }
505 if (xy[0] > rect->xmax) {
506 rect->xmax = xy[0];
507 }
508 if (xy[1] < rect->ymin) {
509 rect->ymin = xy[1];
510 }
511 if (xy[1] > rect->ymax) {
512 rect->ymax = xy[1];
513 }
514}
515
516void BLI_rcti_do_minmax_rcti(rcti *rect, const rcti *other)
517{
518 rect->xmin = min_ii(rect->xmin, other->xmin);
519 rect->xmax = max_ii(rect->xmax, other->xmax);
520 rect->ymin = min_ii(rect->ymin, other->ymin);
521 rect->ymax = max_ii(rect->ymax, other->ymax);
522}
523
524void BLI_rctf_do_minmax_v(rctf *rect, const float xy[2])
525{
526 if (xy[0] < rect->xmin) {
527 rect->xmin = xy[0];
528 }
529 if (xy[0] > rect->xmax) {
530 rect->xmax = xy[0];
531 }
532 if (xy[1] < rect->ymin) {
533 rect->ymin = xy[1];
534 }
535 if (xy[1] > rect->ymax) {
536 rect->ymax = xy[1];
537 }
538}
539
541 const rctf *src,
542 float xy_dst[2],
543 const float xy_src[2])
544{
545 xy_dst[0] = ((xy_src[0] - src->xmin) / (src->xmax - src->xmin));
546 xy_dst[0] = dst->xmin + ((dst->xmax - dst->xmin) * xy_dst[0]);
547
548 xy_dst[1] = ((xy_src[1] - src->ymin) / (src->ymax - src->ymin));
549 xy_dst[1] = dst->ymin + ((dst->ymax - dst->ymin) * xy_dst[1]);
550}
551
553 const rctf *dst, const rctf *src, float matrix[4][4], uint x, uint y)
554{
555 BLI_assert(x < 3 && y < 3);
556
557 unit_m4(matrix);
558
559 matrix[x][x] = BLI_rctf_size_x(src) / BLI_rctf_size_x(dst);
560 matrix[y][y] = BLI_rctf_size_y(src) / BLI_rctf_size_y(dst);
561 matrix[3][x] = (src->xmin - dst->xmin) * matrix[x][x];
562 matrix[3][y] = (src->ymin - dst->ymin) * matrix[y][y];
563}
564
565void BLI_rctf_transform_calc_m4_pivot_min(const rctf *dst, const rctf *src, float matrix[4][4])
566{
567 BLI_rctf_transform_calc_m4_pivot_min_ex(dst, src, matrix, 0, 1);
568}
569
570void BLI_rctf_transform_calc_m3_pivot_min(const rctf *dst, const rctf *src, float matrix[3][3])
571{
572 unit_m3(matrix);
573
574 matrix[0][0] = BLI_rctf_size_x(src) / BLI_rctf_size_x(dst);
575 matrix[1][1] = BLI_rctf_size_y(src) / BLI_rctf_size_y(dst);
576 matrix[2][0] = (src->xmin - dst->xmin) * matrix[0][0];
577 matrix[2][1] = (src->ymin - dst->ymin) * matrix[1][1];
578}
579
580void BLI_rcti_translate(rcti *rect, int x, int y)
581{
582 rect->xmin += x;
583 rect->ymin += y;
584 rect->xmax += x;
585 rect->ymax += y;
586}
587void BLI_rctf_translate(rctf *rect, float x, float y)
588{
589 rect->xmin += x;
590 rect->ymin += y;
591 rect->xmax += x;
592 rect->ymax += y;
593}
594
595void BLI_rcti_mul(rcti *rect, const int factor)
596{
597 rect->xmin *= factor;
598 rect->ymin *= factor;
599 rect->xmax *= factor;
600 rect->ymax *= factor;
601}
602void BLI_rctf_mul(rctf *rect, const float factor)
603{
604 rect->xmin *= factor;
605 rect->ymin *= factor;
606 rect->xmax *= factor;
607 rect->ymax *= factor;
608}
609
610void BLI_rcti_recenter(rcti *rect, int x, int y)
611{
612 const int dx = x - BLI_rcti_cent_x(rect);
613 const int dy = y - BLI_rcti_cent_y(rect);
614 BLI_rcti_translate(rect, dx, dy);
615}
616void BLI_rctf_recenter(rctf *rect, float x, float y)
617{
618 const float dx = x - BLI_rctf_cent_x(rect);
619 const float dy = y - BLI_rctf_cent_y(rect);
620 BLI_rctf_translate(rect, dx, dy);
621}
622
623void BLI_rcti_resize_x(rcti *rect, int x)
624{
625 rect->xmin = BLI_rcti_cent_x(rect) - (x / 2);
626 rect->xmax = rect->xmin + x;
627}
628
629void BLI_rcti_resize_y(rcti *rect, int y)
630{
631 rect->ymin = BLI_rcti_cent_y(rect) - (y / 2);
632 rect->ymax = rect->ymin + y;
633}
634
635void BLI_rcti_resize(rcti *rect, int x, int y)
636{
637 rect->xmin = BLI_rcti_cent_x(rect) - (x / 2);
638 rect->ymin = BLI_rcti_cent_y(rect) - (y / 2);
639 rect->xmax = rect->xmin + x;
640 rect->ymax = rect->ymin + y;
641}
642
643void BLI_rcti_pad(rcti *rect, int pad_x, int pad_y)
644{
645 rect->xmin -= pad_x;
646 rect->ymin -= pad_y;
647 rect->xmax += pad_x;
648 rect->ymax += pad_y;
649}
650
651void BLI_rctf_pad(rctf *rect, float pad_x, float pad_y)
652{
653 rect->xmin -= pad_x;
654 rect->ymin -= pad_y;
655 rect->xmax += pad_x;
656 rect->ymax += pad_y;
657}
658
659void BLI_rctf_resize_x(rctf *rect, float x)
660{
661 rect->xmin = BLI_rctf_cent_x(rect) - (x * 0.5f);
662 rect->xmax = rect->xmin + x;
663}
664
665void BLI_rctf_resize_y(rctf *rect, float y)
666{
667 rect->ymin = BLI_rctf_cent_y(rect) - (y * 0.5f);
668 rect->ymax = rect->ymin + y;
669}
670
671void BLI_rctf_resize(rctf *rect, float x, float y)
672{
673 rect->xmin = BLI_rctf_cent_x(rect) - (x * 0.5f);
674 rect->ymin = BLI_rctf_cent_y(rect) - (y * 0.5f);
675 rect->xmax = rect->xmin + x;
676 rect->ymax = rect->ymin + y;
677}
678
679void BLI_rcti_scale(rcti *rect, const float scale)
680{
681 const int cent_x = BLI_rcti_cent_x(rect);
682 const int cent_y = BLI_rcti_cent_y(rect);
683 const int size_x_half = BLI_rcti_size_x(rect) * (scale * 0.5f);
684 const int size_y_half = BLI_rcti_size_y(rect) * (scale * 0.5f);
685 rect->xmin = cent_x - size_x_half;
686 rect->ymin = cent_y - size_y_half;
687 rect->xmax = cent_x + size_x_half;
688 rect->ymax = cent_y + size_y_half;
689}
690
691void BLI_rctf_scale(rctf *rect, const float scale)
692{
693 const float cent_x = BLI_rctf_cent_x(rect);
694 const float cent_y = BLI_rctf_cent_y(rect);
695 const float size_x_half = BLI_rctf_size_x(rect) * (scale * 0.5f);
696 const float size_y_half = BLI_rctf_size_y(rect) * (scale * 0.5f);
697 rect->xmin = cent_x - size_x_half;
698 rect->ymin = cent_y - size_y_half;
699 rect->xmax = cent_x + size_x_half;
700 rect->ymax = cent_y + size_y_half;
701}
702
704 const float boundary_size,
705 const float pad_min,
706 const float pad_max)
707{
708 BLI_assert(pad_max >= 0.0f);
709 BLI_assert(pad_min >= 0.0f);
710 BLI_assert(boundary_size > 0.0f);
711
712 float total_pad = pad_max + pad_min;
713 if (total_pad == 0.0f) {
714 return;
715 }
716
717 /* To get the padding to work as intended, we have to calculate the
718 * new 'rect' y size that has the same ratio between its padding and size
719 * as our screen space ratio (total_pad / boundary_size).
720 *
721 * Here is how the equation was derived:
722 *
723 * ratio = local_pad / new_local_view_size = total_pad / boundary_size
724 * Where, new_local_view_size = local_view_size + local_pad
725 *
726 * ratio = local_pad / (local_view_size + local_pad) ->
727 * ratio * local_view_size + ratio * local_pad = local_pad ->
728 * ratio * local_view_size = local_pad * (1 - ratio) ->
729 * ratio * local_view_size / (1 - ratio) = local_pad ->
730 * total_pad * local_view_size / (boundary_size - total_pad) = local_pad
731 *
732 * We can then remove the first "total_pad" in the equation as we need to
733 * divide pad_(max/min) by "total_pad" when we are calculating the final ymax/ymin.
734 */
735
736 float local_view_size = BLI_rctf_size_y(rect);
737 float local_pad = local_view_size / (boundary_size - total_pad);
738
739 rect->ymax += local_pad * pad_max;
740 rect->ymin -= local_pad * pad_min;
741}
742
743void BLI_rctf_interp(rctf *rect, const rctf *rect_a, const rctf *rect_b, const float fac)
744{
745 const float ifac = 1.0f - fac;
746 rect->xmin = (rect_a->xmin * ifac) + (rect_b->xmin * fac);
747 rect->xmax = (rect_a->xmax * ifac) + (rect_b->xmax * fac);
748 rect->ymin = (rect_a->ymin * ifac) + (rect_b->ymin * fac);
749 rect->ymax = (rect_a->ymax * ifac) + (rect_b->ymax * fac);
750}
751
752/* BLI_rcti_interp() not needed yet */
753
754bool BLI_rctf_clamp_pt_v(const rctf *rect, float xy[2])
755{
756 bool changed = false;
757 if (xy[0] < rect->xmin) {
758 xy[0] = rect->xmin;
759 changed = true;
760 }
761 if (xy[0] > rect->xmax) {
762 xy[0] = rect->xmax;
763 changed = true;
764 }
765 if (xy[1] < rect->ymin) {
766 xy[1] = rect->ymin;
767 changed = true;
768 }
769 if (xy[1] > rect->ymax) {
770 xy[1] = rect->ymax;
771 changed = true;
772 }
773 return changed;
774}
775
776bool BLI_rcti_clamp_pt_v(const rcti *rect, int xy[2])
777{
778 bool changed = false;
779 if (xy[0] < rect->xmin) {
780 xy[0] = rect->xmin;
781 changed = true;
782 }
783 if (xy[0] > rect->xmax) {
784 xy[0] = rect->xmax;
785 changed = true;
786 }
787 if (xy[1] < rect->ymin) {
788 xy[1] = rect->ymin;
789 changed = true;
790 }
791 if (xy[1] > rect->ymax) {
792 xy[1] = rect->ymax;
793 changed = true;
794 }
795 return changed;
796}
797
798bool BLI_rctf_clamp(rctf *rect, const rctf *rect_bounds, float r_xy[2])
799{
800 bool changed = false;
801
802 r_xy[0] = 0.0f;
803 r_xy[1] = 0.0f;
804
805 if (rect->xmax > rect_bounds->xmax) {
806 float ofs = rect_bounds->xmax - rect->xmax;
807 rect->xmin += ofs;
808 rect->xmax += ofs;
809 r_xy[0] += ofs;
810 changed = true;
811 }
812
813 if (rect->xmin < rect_bounds->xmin) {
814 float ofs = rect_bounds->xmin - rect->xmin;
815 rect->xmin += ofs;
816 rect->xmax += ofs;
817 r_xy[0] += ofs;
818 changed = true;
819 }
820
821 if (rect->ymin < rect_bounds->ymin) {
822 float ofs = rect_bounds->ymin - rect->ymin;
823 rect->ymin += ofs;
824 rect->ymax += ofs;
825 r_xy[1] += ofs;
826 changed = true;
827 }
828
829 if (rect->ymax > rect_bounds->ymax) {
830 float ofs = rect_bounds->ymax - rect->ymax;
831 rect->ymin += ofs;
832 rect->ymax += ofs;
833 r_xy[1] += ofs;
834 changed = true;
835 }
836
837 return changed;
838}
839
840bool BLI_rcti_clamp(rcti *rect, const rcti *rect_bounds, int r_xy[2])
841{
842 bool changed = false;
843
844 r_xy[0] = 0;
845 r_xy[1] = 0;
846
847 if (rect->xmax > rect_bounds->xmax) {
848 int ofs = rect_bounds->xmax - rect->xmax;
849 rect->xmin += ofs;
850 rect->xmax += ofs;
851 r_xy[0] += ofs;
852 changed = true;
853 }
854
855 if (rect->xmin < rect_bounds->xmin) {
856 int ofs = rect_bounds->xmin - rect->xmin;
857 rect->xmin += ofs;
858 rect->xmax += ofs;
859 r_xy[0] += ofs;
860 changed = true;
861 }
862
863 if (rect->ymin < rect_bounds->ymin) {
864 int ofs = rect_bounds->ymin - rect->ymin;
865 rect->ymin += ofs;
866 rect->ymax += ofs;
867 r_xy[1] += ofs;
868 changed = true;
869 }
870
871 if (rect->ymax > rect_bounds->ymax) {
872 int ofs = rect_bounds->ymax - rect->ymax;
873 rect->ymin += ofs;
874 rect->ymax += ofs;
875 r_xy[1] += ofs;
876 changed = true;
877 }
878
879 return changed;
880}
881
882bool BLI_rctf_compare(const rctf *rect_a, const rctf *rect_b, const float limit)
883{
884 if (fabsf(rect_a->xmin - rect_b->xmin) <= limit) {
885 if (fabsf(rect_a->xmax - rect_b->xmax) <= limit) {
886 if (fabsf(rect_a->ymin - rect_b->ymin) <= limit) {
887 if (fabsf(rect_a->ymax - rect_b->ymax) <= limit) {
888 return true;
889 }
890 }
891 }
892 }
893
894 return false;
895}
896
897bool BLI_rcti_compare(const rcti *rect_a, const rcti *rect_b)
898{
899 if (rect_a->xmin == rect_b->xmin) {
900 if (rect_a->xmax == rect_b->xmax) {
901 if (rect_a->ymin == rect_b->ymin) {
902 if (rect_a->ymax == rect_b->ymax) {
903 return true;
904 }
905 }
906 }
907 }
908
909 return false;
910}
911
912bool BLI_rctf_isect(const rctf *src1, const rctf *src2, rctf *dest)
913{
914 float xmin, xmax;
915 float ymin, ymax;
916
917 xmin = (src1->xmin) > (src2->xmin) ? (src1->xmin) : (src2->xmin);
918 xmax = (src1->xmax) < (src2->xmax) ? (src1->xmax) : (src2->xmax);
919 ymin = (src1->ymin) > (src2->ymin) ? (src1->ymin) : (src2->ymin);
920 ymax = (src1->ymax) < (src2->ymax) ? (src1->ymax) : (src2->ymax);
921
922 if (xmax >= xmin && ymax >= ymin) {
923 if (dest) {
924 dest->xmin = xmin;
925 dest->xmax = xmax;
926 dest->ymin = ymin;
927 dest->ymax = ymax;
928 }
929 return true;
930 }
931
932 if (dest) {
933 dest->xmin = 0;
934 dest->xmax = 0;
935 dest->ymin = 0;
936 dest->ymax = 0;
937 }
938 return false;
939}
940
941bool BLI_rcti_isect(const rcti *src1, const rcti *src2, rcti *dest)
942{
943 int xmin, xmax;
944 int ymin, ymax;
945
946 xmin = (src1->xmin) > (src2->xmin) ? (src1->xmin) : (src2->xmin);
947 xmax = (src1->xmax) < (src2->xmax) ? (src1->xmax) : (src2->xmax);
948 ymin = (src1->ymin) > (src2->ymin) ? (src1->ymin) : (src2->ymin);
949 ymax = (src1->ymax) < (src2->ymax) ? (src1->ymax) : (src2->ymax);
950
951 if (xmax >= xmin && ymax >= ymin) {
952 if (dest) {
953 dest->xmin = xmin;
954 dest->xmax = xmax;
955 dest->ymin = ymin;
956 dest->ymax = ymax;
957 }
958 return true;
959 }
960
961 if (dest) {
962 dest->xmin = 0;
963 dest->xmax = 0;
964 dest->ymin = 0;
965 dest->ymax = 0;
966 }
967 return false;
968}
969
970bool BLI_rctf_isect_rect_x(const rctf *src1, const rctf *src2, float range_x[2])
971{
972 const float xmin = (src1->xmin) > (src2->xmin) ? (src1->xmin) : (src2->xmin);
973 const float xmax = (src1->xmax) < (src2->xmax) ? (src1->xmax) : (src2->xmax);
974
975 if (xmax >= xmin) {
976 if (range_x) {
977 range_x[0] = xmin;
978 range_x[1] = xmax;
979 }
980 return true;
981 }
982
983 if (range_x) {
984 range_x[0] = 0;
985 range_x[1] = 0;
986 }
987 return false;
988}
989
990bool BLI_rctf_isect_rect_y(const rctf *src1, const rctf *src2, float range_y[2])
991{
992 const float ymin = (src1->ymin) > (src2->ymin) ? (src1->ymin) : (src2->ymin);
993 const float ymax = (src1->ymax) < (src2->ymax) ? (src1->ymax) : (src2->ymax);
994
995 if (ymax >= ymin) {
996 if (range_y) {
997 range_y[0] = ymin;
998 range_y[1] = ymax;
999 }
1000 return true;
1001 }
1002
1003 if (range_y) {
1004 range_y[0] = 0;
1005 range_y[1] = 0;
1006 }
1007 return false;
1008}
1009
1010bool BLI_rcti_isect_rect_x(const rcti *src1, const rcti *src2, int range_x[2])
1011{
1012 const int xmin = (src1->xmin) > (src2->xmin) ? (src1->xmin) : (src2->xmin);
1013 const int xmax = (src1->xmax) < (src2->xmax) ? (src1->xmax) : (src2->xmax);
1014
1015 if (xmax >= xmin) {
1016 if (range_x) {
1017 range_x[0] = xmin;
1018 range_x[1] = xmax;
1019 }
1020 return true;
1021 }
1022
1023 if (range_x) {
1024 range_x[0] = 0;
1025 range_x[1] = 0;
1026 }
1027 return false;
1028}
1029
1030bool BLI_rcti_isect_rect_y(const rcti *src1, const rcti *src2, int range_y[2])
1031{
1032 const int ymin = (src1->ymin) > (src2->ymin) ? (src1->ymin) : (src2->ymin);
1033 const int ymax = (src1->ymax) < (src2->ymax) ? (src1->ymax) : (src2->ymax);
1034
1035 if (ymax >= ymin) {
1036 if (range_y) {
1037 range_y[0] = ymin;
1038 range_y[1] = ymax;
1039 }
1040 return true;
1041 }
1042
1043 if (range_y) {
1044 range_y[0] = 0;
1045 range_y[1] = 0;
1046 }
1047 return false;
1048}
1049
1050void BLI_rcti_rctf_copy(rcti *dst, const rctf *src)
1051{
1052 dst->xmin = floorf(src->xmin + 0.5f);
1053 dst->xmax = dst->xmin + floorf(BLI_rctf_size_x(src) + 0.5f);
1054 dst->ymin = floorf(src->ymin + 0.5f);
1055 dst->ymax = dst->ymin + floorf(BLI_rctf_size_y(src) + 0.5f);
1056}
1057
1058void BLI_rcti_rctf_copy_floor(rcti *dst, const rctf *src)
1059{
1060 dst->xmin = floorf(src->xmin);
1061 dst->xmax = floorf(src->xmax);
1062 dst->ymin = floorf(src->ymin);
1063 dst->ymax = floorf(src->ymax);
1064}
1065
1066void BLI_rcti_rctf_copy_round(rcti *dst, const rctf *src)
1067{
1068 dst->xmin = floorf(src->xmin + 0.5f);
1069 dst->xmax = floorf(src->xmax + 0.5f);
1070 dst->ymin = floorf(src->ymin + 0.5f);
1071 dst->ymax = floorf(src->ymax + 0.5f);
1072}
1073
1074void BLI_rctf_rcti_copy(rctf *dst, const rcti *src)
1075{
1076 dst->xmin = src->xmin;
1077 dst->xmax = src->xmax;
1078 dst->ymin = src->ymin;
1079 dst->ymax = src->ymax;
1080}
1081
1082void print_rctf(const char *str, const rctf *rect)
1083{
1084 printf("%s: xmin %.8f, xmax %.8f, ymin %.8f, ymax %.8f (%.12fx%.12f)\n",
1085 str,
1086 rect->xmin,
1087 rect->xmax,
1088 rect->ymin,
1089 rect->ymax,
1090 BLI_rctf_size_x(rect),
1091 BLI_rctf_size_y(rect));
1092}
1093
1094void print_rcti(const char *str, const rcti *rect)
1095{
1096 printf("%s: xmin %d, xmax %d, ymin %d, ymax %d (%dx%d)\n",
1097 str,
1098 rect->xmin,
1099 rect->xmax,
1100 rect->ymin,
1101 rect->ymax,
1102 BLI_rcti_size_x(rect),
1103 BLI_rcti_size_y(rect));
1104}
1105
1106/* Comprehensive math (float only) */
1107
1108/* -------------------------------------------------------------------- */
1111
1112#define ROTATE_SINCOS(r_vec, mat2, vec) \
1113 { \
1114 (r_vec)[0] = (mat2)[1] * (vec)[0] + (+(mat2)[0]) * (vec)[1]; \
1115 (r_vec)[1] = (mat2)[0] * (vec)[0] + (-(mat2)[1]) * (vec)[1]; \
1116 } \
1117 ((void)0)
1118
1119void BLI_rctf_rotate_expand(rctf *dst, const rctf *src, const float angle)
1120{
1121 const float mat2[2] = {sinf(angle), cosf(angle)};
1122 const float cent[2] = {BLI_rctf_cent_x(src), BLI_rctf_cent_y(src)};
1123 float corner[2], corner_rot[2], corder_max[2];
1124
1125 /* x is same for both corners */
1126 corner[0] = src->xmax - cent[0];
1127 corner[1] = src->ymax - cent[1];
1128 ROTATE_SINCOS(corner_rot, mat2, corner);
1129 corder_max[0] = fabsf(corner_rot[0]);
1130 corder_max[1] = fabsf(corner_rot[1]);
1131
1132 corner[1] *= -1;
1133 ROTATE_SINCOS(corner_rot, mat2, corner);
1134 corder_max[0] = std::max(corder_max[0], fabsf(corner_rot[0]));
1135 corder_max[1] = std::max(corder_max[1], fabsf(corner_rot[1]));
1136
1137 dst->xmin = cent[0] - corder_max[0];
1138 dst->xmax = cent[0] + corder_max[0];
1139 dst->ymin = cent[1] - corder_max[1];
1140 dst->ymax = cent[1] + corder_max[1];
1141}
1142
1143#undef ROTATE_SINCOS
1144
1146 const rctf *src,
1147 const float pivot[2],
1148 const float angle)
1149{
1150 const float cent[2] = {BLI_rctf_cent_x(src) - pivot[0], BLI_rctf_cent_y(src) - pivot[1]};
1151 const float sin_a = sinf(angle);
1152 const float cos_a = cosf(angle);
1153 const float cent_rot[2] = {cent[0] * cos_a - cent[1] * sin_a, cent[0] * sin_a + cent[1] * cos_a};
1154
1155 BLI_rctf_rotate_expand(dst, src, angle);
1156 BLI_rctf_translate(dst, cent_rot[0] - cent[0], cent_rot[1] - cent[1]);
1157}
1158
1159bool BLI_rctf_clamp_segment(const rctf *rect, float s1[2], float s2[2])
1160{
1161 const bool p1_inside = BLI_rctf_isect_pt_v(rect, s1);
1162 const bool p2_inside = BLI_rctf_isect_pt_v(rect, s2);
1163 if (p1_inside && p2_inside) {
1164 return true;
1165 }
1166
1167 const std::array<float2, 2> top_line = {float2{rect->xmin, rect->ymax},
1168 float2{rect->xmax, rect->ymax}};
1169 const std::array<float2, 2> bottom_line = {float2{rect->xmin, rect->ymin},
1170 float2{rect->xmax, rect->ymin}};
1171 const std::array<float2, 2> left_line = {float2{rect->xmin, rect->ymin},
1172 float2{rect->xmin, rect->ymax}};
1173 const std::array<float2, 2> right_line = {float2{rect->xmax, rect->ymin},
1174 float2{rect->xmax, rect->ymax}};
1175 const std::array<std::array<float2, 2>, 4> lines = {
1176 top_line, bottom_line, left_line, right_line};
1177
1178 if (p1_inside && !p2_inside) {
1179 for (const std::array<float2, 2> &line : lines) {
1180 float2 intersection;
1181 if (isect_seg_seg_v2_point(s1, s2, line[0], line[1], intersection) == 1) {
1182 copy_v2_v2(s2, intersection);
1183 }
1184 }
1185 return true;
1186 }
1187 if (!p1_inside && p2_inside) {
1188 for (const std::array<float2, 2> &line : lines) {
1189 float2 intersection;
1190 if (isect_seg_seg_v2_point(s1, s2, line[0], line[1], intersection) == 1) {
1191 copy_v2_v2(s1, intersection);
1192 }
1193 }
1194 return true;
1195 }
1196
1197 for (const std::array<float2, 2> &line : lines) {
1198 float2 intersection;
1199 if (isect_seg_seg_v2_point(s1, s2, line[0], line[1], intersection) == 1) {
1200 copy_v2_v2(s1, intersection);
1201 }
1202 else {
1203 return false;
1204 }
1205 }
1206 for (const std::array<float2, 2> &line : lines) {
1207 float2 intersection;
1208 if (isect_seg_seg_v2_point(s2, s1, line[0], line[1], intersection) == 1) {
1209 copy_v2_v2(s2, intersection);
1210 }
1211 else {
1212 return false;
1213 }
1214 }
1215
1216 return true;
1217}
1218
1220
1221} // namespace blender
#define SWAP(type, a, b)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
#define str(s)
#define FLT_MAX
#define INT_MAX
float3x3 scale(float3x3 mat, float2 scale)
BMesh Iterators.
MINLINE float min_ff(float a, float b)
bool BLI_rcti_is_valid(const struct rcti *rect)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
float BLI_rctf_length_y(const rctf *rect, float y)
Definition rct.cc:184
bool BLI_rctf_clamp_segment(const struct rctf *rect, float s1[2], float s2[2])
void BLI_rcti_resize_y(struct rcti *rect, int y)
Definition rct.cc:629
bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2])
bool BLI_rcti_isect_x(const rcti *rect, int x)
Definition rct.cc:39
unsigned int uint
Definition BKE_text.h:55
void BLI_rctf_recenter(struct rctf *rect, float x, float y)
Definition rct.cc:616
void BLI_rctf_rotate_expand_around(rctf *dst, const rctf *src, const float pivot[2], float angle)
Definition rct.cc:1145
int BLI_rcti_length_x(const rcti *rect, int x)
Definition rct.cc:151
bool BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest)
bool BLI_rcti_isect_rect_y(const struct rcti *src1, const struct rcti *src2, int range_y[2])
MINLINE void copy_v2_v2(float r[2], const float a[2])
bool BLI_rcti_compare(const struct rcti *rect_a, const struct rcti *rect_b)
void BLI_rcti_rctf_copy(struct rcti *dst, const struct rctf *src)
bool BLI_rcti_isect_circle(const struct rcti *rect, const float xy[2], float radius)
void BLI_rctf_resize(struct rctf *rect, float x, float y)
Definition rct.cc:671
void BLI_rcti_init_minmax(struct rcti *rect)
Definition rct.cc:488
void BLI_rctf_do_minmax_v(struct rctf *rect, const float xy[2])
Definition rct.cc:524
int isect_seg_seg_v2_point(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float r_vi[2])
void BLI_rcti_resize_x(struct rcti *rect, int x)
Definition rct.cc:623
bool BLI_rctf_isect_circle(const struct rctf *rect, const float xy[2], float radius)
static int isect_segments_fl(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
Definition rct.cc:222
MINLINE int max_ii(int a, int b)
void BLI_rctf_sanitize(struct rctf *rect)
Definition rct.cc:448
void BLI_rcti_rctf_copy_round(struct rcti *dst, const struct rctf *src)
void BLI_rctf_scale(rctf *rect, float scale)
Definition rct.cc:691
bool BLI_rcti_clamp(struct rcti *rect, const struct rcti *rect_bounds, int r_xy[2])
void BLI_rcti_do_minmax_v(struct rcti *rect, const int xy[2])
Definition rct.cc:500
void BLI_rcti_sanitize(struct rcti *rect)
Definition rct.cc:460
void BLI_rctf_rcti_copy(struct rctf *dst, const struct rcti *src)
void BLI_rctf_rotate_expand(rctf *dst, const rctf *src, float angle)
Definition rct.cc:1119
bool BLI_rctf_isect_x(const rctf *rect, float x)
Definition rct.cc:95
bool BLI_rctf_isect_rect_x(const struct rctf *src1, const struct rctf *src2, float range_x[2])
void BLI_rctf_resize_x(struct rctf *rect, float x)
Definition rct.cc:659
bool BLI_rctf_is_valid(const struct rctf *rect)
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.cc:552
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
void BLI_rctf_init_pt_radius(struct rctf *rect, const float xy[2], float size)
Definition rct.cc:472
bool BLI_rctf_is_empty(const struct rctf *rect)
void BLI_rctf_mul(struct rctf *rect, float factor)
Definition rct.cc:602
int BLI_rcti_length_y(const rcti *rect, int y)
Definition rct.cc:162
static int isect_segments_i(const int v1[2], const int v2[2], const int v3[2], const int v4[2])
Definition rct.cc:208
VecBase< float, 2 > float2
BLI_INLINE int BLI_rcti_cent_y(const struct rcti *rct)
Definition BLI_rect.hh:190
bool BLI_rctf_compare(const struct rctf *rect_a, const struct rctf *rect_b, float limit)
void BLI_rctf_resize_y(struct rctf *rect, float y)
Definition rct.cc:665
void BLI_rcti_scale(rcti *rect, float scale)
Definition rct.cc:679
void BLI_rctf_pad_y(struct rctf *rect, float boundary_size, float pad_min, float pad_max)
Definition rct.cc:703
void BLI_rctf_union_y(struct rctf *rct, float y)
Definition rct.cc:396
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
bool BLI_rctf_isect_pt(const struct rctf *rect, float x, float y)
void BLI_rcti_union(struct rcti *rct_a, const struct rcti *rct_b)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.cc:580
bool BLI_rcti_isect_y(const rcti *rect, int y)
Definition rct.cc:50
bool BLI_rctf_clamp(struct rctf *rect, const struct rctf *rect_bounds, float r_xy[2])
void BLI_rctf_transform_calc_m3_pivot_min(const rctf *dst, const rctf *src, float matrix[3][3])
Definition rct.cc:570
void BLI_rctf_init_minmax(struct rctf *rect)
Definition rct.cc:494
bool BLI_rctf_inside_rctf(const rctf *rct_a, const rctf *rct_b)
Definition rct.cc:195
void print_rcti(const char *str, const struct rcti *rect)
void unit_m4(float m[4][4])
void BLI_rctf_union_x(struct rctf *rct, float x)
Definition rct.cc:390
bool BLI_rcti_is_empty(const struct rcti *rect)
void print_rctf(const char *str, const struct rctf *rect)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void BLI_rctf_union(struct rctf *rct_a, const struct rctf *rct_b)
bool BLI_rcti_isect_rect_x(const struct rcti *src1, const struct rcti *src2, int range_x[2])
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:428
float BLI_rctf_length_x(const rctf *rect, float x)
Definition rct.cc:173
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.cc:540
void unit_m3(float m[3][3])
ATTR_WARN_UNUSED_RESULT const BMVert * v2
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
bool BLI_rctf_clamp_pt_v(const struct rctf *rect, float xy[2])
void BLI_rctf_interp(struct rctf *rect, const struct rctf *rect_a, const struct rctf *rect_b, float fac)
void BLI_rcti_mul(struct rcti *rect, int factor)
Definition rct.cc:595
MINLINE float max_ff(float a, float b)
bool BLI_rctf_isect(const struct rctf *src1, const struct rctf *src2, struct rctf *dest)
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition BLI_rect.hh:198
void BLI_rctf_transform_calc_m4_pivot_min(const rctf *dst, const rctf *src, float matrix[4][4])
Definition rct.cc:565
void BLI_rctf_translate(struct rctf *rect, float x, float y)
Definition rct.cc:587
bool BLI_rctf_isect_rect_y(const struct rctf *src1, const struct rctf *src2, float range_y[2])
bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2])
bool BLI_rcti_isect_pt(const struct rcti *rect, int x, int y)
void BLI_rcti_pad(struct rcti *rect, int pad_x, int pad_y)
Definition rct.cc:643
void BLI_rcti_resize(struct rcti *rect, int x, int y)
Definition rct.cc:635
BLI_INLINE int BLI_rcti_cent_x(const struct rcti *rct)
Definition BLI_rect.hh:186
bool BLI_rcti_inside_rcti(const rcti *rct_a, const rcti *rct_b)
Definition rct.cc:200
bool BLI_rctf_isect_y(const rctf *rect, float y)
Definition rct.cc:106
void BLI_rcti_init_pt_radius(struct rcti *rect, const int xy[2], int size)
Definition rct.cc:480
MINLINE int min_ii(int a, int b)
bool BLI_rctf_isect_segment(const struct rctf *rect, const float s1[2], const float s2[2])
BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
Definition BLI_rect.hh:194
bool BLI_rcti_clamp_pt_v(const struct rcti *rect, int xy[2])
void BLI_rctf_pad(struct rctf *rect, float pad_x, float pad_y)
Definition rct.cc:651
void BLI_rcti_do_minmax_rcti(struct rcti *rect, const struct rcti *other)
void BLI_rcti_recenter(struct rcti *rect, int x, int y)
Definition rct.cc:610
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
Definition rct.cc:418
void BLI_rcti_rctf_copy_floor(struct rcti *dst, const struct rctf *src)
#define floorf
#define fabsf
#define sinf
#define cosf
#define ROTATE_SINCOS(r_vec, mat2, vec)
Definition rct.cc:1112