Blender V4.3
lasso_2d.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
9#include "DNA_vec_types.h"
10
11#include "BLI_math_base.h"
12#include "BLI_math_geom.h"
13
14#include "BLI_lasso_2d.hh" /* own include */
15
16#include "BLI_strict_flags.h" /* Keep last. */
17
18using blender::int2;
19using blender::Span;
20
21void BLI_lasso_boundbox(rcti *rect, const Span<int2> mcoords)
22{
23 rect->xmin = rect->xmax = mcoords[0][0];
24 rect->ymin = rect->ymax = mcoords[0][1];
25
26 for (const int64_t a : mcoords.index_range().drop_front(1)) {
27 if (mcoords[a][0] < rect->xmin) {
28 rect->xmin = mcoords[a][0];
29 }
30 else if (mcoords[a][0] > rect->xmax) {
31 rect->xmax = mcoords[a][0];
32 }
33 if (mcoords[a][1] < rect->ymin) {
34 rect->ymin = mcoords[a][1];
35 }
36 else if (mcoords[a][1] > rect->ymax) {
37 rect->ymax = mcoords[a][1];
38 }
39 }
40}
41
43 const int sx,
44 const int sy,
45 const int error_value)
46{
47 if (sx == error_value || mcoords.is_empty()) {
48 return false;
49 }
50
51 const int pt[2] = {sx, sy};
53 pt, reinterpret_cast<const int(*)[2]>(mcoords.data()), uint(mcoords.size()));
54}
55
57 const Span<int2> mcoords, int x0, int y0, int x1, int y1, const int error_value)
58{
59
60 if (x0 == error_value || x1 == error_value || mcoords.is_empty()) {
61 return false;
62 }
63
64 const int v1[2] = {x0, y0}, v2[2] = {x1, y1};
65
66 /* check points in lasso */
67 if (BLI_lasso_is_point_inside(mcoords, v1[0], v1[1], error_value)) {
68 return true;
69 }
70 if (BLI_lasso_is_point_inside(mcoords, v2[0], v2[1], error_value)) {
71 return true;
72 }
73
74 /* no points in lasso, so we have to intersect with lasso edge */
75
76 if (isect_seg_seg_v2_int(mcoords[0], mcoords.last(), v1, v2) > 0) {
77 return true;
78 }
79 for (const int64_t i : mcoords.index_range().drop_back(1)) {
80 if (isect_seg_seg_v2_int(mcoords[i], mcoords[i + 1], v1, v2) > 0) {
81 return true;
82 }
83 }
84
85 return false;
86}
bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], unsigned int nr)
int isect_seg_seg_v2_int(const int v1[2], const int v2[2], const int v3[2], const int v4[2])
unsigned int uint
ATTR_WARN_UNUSED_RESULT const BMVert * v2
constexpr IndexRange drop_back(int64_t n) const
constexpr IndexRange drop_front(int64_t n) const
constexpr const T * data() const
Definition BLI_span.hh:216
constexpr int64_t size() const
Definition BLI_span.hh:253
constexpr const T & last(const int64_t n=0) const
Definition BLI_span.hh:326
constexpr IndexRange index_range() const
Definition BLI_span.hh:402
constexpr bool is_empty() const
Definition BLI_span.hh:261
void BLI_lasso_boundbox(rcti *rect, const Span< int2 > mcoords)
Definition lasso_2d.cc:21
bool BLI_lasso_is_point_inside(const Span< int2 > mcoords, const int sx, const int sy, const int error_value)
Definition lasso_2d.cc:42
bool BLI_lasso_is_edge_inside(const Span< int2 > mcoords, int x0, int y0, int x1, int y1, const int error_value)
Definition lasso_2d.cc:56
__int64 int64_t
Definition stdint.h:89
int ymin
int ymax
int xmin
int xmax