Cleanup: Deduplicate node link intersection test
This commit is contained in:
parent
56193eccf6
commit
b60850d395
|
@ -104,7 +104,7 @@ bNode *add_static_node(const bContext &C, int type, const float2 &location)
|
|||
/** \name Add Reroute Operator
|
||||
* \{ */
|
||||
|
||||
static std::optional<float2> path_link_intersection(const bNodeLink &link, const Span<float2> path)
|
||||
std::optional<float2> link_path_intersection(const bNodeLink &link, const Span<float2> path)
|
||||
{
|
||||
std::array<float2, NODE_LINK_RESOL + 1> coords;
|
||||
node_link_bezier_points_evaluated(link, coords);
|
||||
|
@ -166,7 +166,7 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
|
|||
if (node_link_is_hidden_or_dimmed(region.v2d, *link)) {
|
||||
continue;
|
||||
}
|
||||
const std::optional<float2> intersection = path_link_intersection(*link, path);
|
||||
const std::optional<float2> intersection = link_path_intersection(*link, path);
|
||||
if (!intersection) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -236,6 +236,8 @@ void node_draw_link_bezier(const bContext &C,
|
|||
void node_link_bezier_points_evaluated(const bNodeLink &link,
|
||||
std::array<float2, NODE_LINK_RESOL + 1> &coords);
|
||||
|
||||
std::optional<float2> link_path_intersection(const bNodeLink &link, Span<float2> path);
|
||||
|
||||
void draw_nodespace_back_pix(const bContext &C,
|
||||
ARegion ®ion,
|
||||
SpaceNode &snode,
|
||||
|
|
|
@ -1291,28 +1291,6 @@ void NODE_OT_link_make(wmOperatorType *ot)
|
|||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Node Link Intersect
|
||||
* \{ */
|
||||
|
||||
static bool node_links_intersect(bNodeLink &link, const float mcoords[][2], int tot)
|
||||
{
|
||||
std::array<float2, NODE_LINK_RESOL + 1> coords;
|
||||
node_link_bezier_points_evaluated(link, coords);
|
||||
|
||||
for (int i = 0; i < tot - 1; i++) {
|
||||
for (int b = 0; b < NODE_LINK_RESOL; b++) {
|
||||
if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coords[b], coords[b + 1]) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Cut Link Operator
|
||||
* \{ */
|
||||
|
@ -1321,24 +1299,22 @@ static int cut_links_exec(bContext *C, wmOperator *op)
|
|||
{
|
||||
Main &bmain = *CTX_data_main(C);
|
||||
SpaceNode &snode = *CTX_wm_space_node(C);
|
||||
ARegion ®ion = *CTX_wm_region(C);
|
||||
const ARegion ®ion = *CTX_wm_region(C);
|
||||
|
||||
int i = 0;
|
||||
float mcoords[256][2];
|
||||
Vector<float2> path;
|
||||
RNA_BEGIN (op->ptr, itemptr, "path") {
|
||||
float loc[2];
|
||||
|
||||
RNA_float_get_array(&itemptr, "loc", loc);
|
||||
UI_view2d_region_to_view(
|
||||
®ion.v2d, (int)loc[0], (int)loc[1], &mcoords[i][0], &mcoords[i][1]);
|
||||
i++;
|
||||
if (i >= 256) {
|
||||
float2 loc_region;
|
||||
RNA_float_get_array(&itemptr, "loc", loc_region);
|
||||
float2 loc_view;
|
||||
UI_view2d_region_to_view(®ion.v2d, loc_region.x, loc_region.y, &loc_view.x, &loc_view.y);
|
||||
path.append(loc_view);
|
||||
if (path.size() >= 256) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
RNA_END;
|
||||
|
||||
if (i == 0) {
|
||||
if (path.is_empty()) {
|
||||
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
||||
}
|
||||
|
||||
|
@ -1355,7 +1331,7 @@ static int cut_links_exec(bContext *C, wmOperator *op)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (node_links_intersect(*link, mcoords, i)) {
|
||||
if (link_path_intersection(*link, path)) {
|
||||
|
||||
if (!found) {
|
||||
/* TODO(sergey): Why did we kill jobs twice? */
|
||||
|
@ -1418,24 +1394,22 @@ static int mute_links_exec(bContext *C, wmOperator *op)
|
|||
{
|
||||
Main &bmain = *CTX_data_main(C);
|
||||
SpaceNode &snode = *CTX_wm_space_node(C);
|
||||
ARegion ®ion = *CTX_wm_region(C);
|
||||
const ARegion ®ion = *CTX_wm_region(C);
|
||||
|
||||
int i = 0;
|
||||
float mcoords[256][2];
|
||||
Vector<float2> path;
|
||||
RNA_BEGIN (op->ptr, itemptr, "path") {
|
||||
float loc[2];
|
||||
|
||||
RNA_float_get_array(&itemptr, "loc", loc);
|
||||
UI_view2d_region_to_view(
|
||||
®ion.v2d, (int)loc[0], (int)loc[1], &mcoords[i][0], &mcoords[i][1]);
|
||||
i++;
|
||||
if (i >= 256) {
|
||||
float2 loc_region;
|
||||
RNA_float_get_array(&itemptr, "loc", loc_region);
|
||||
float2 loc_view;
|
||||
UI_view2d_region_to_view(®ion.v2d, loc_region.x, loc_region.y, &loc_view.x, &loc_view.y);
|
||||
path.append(loc_view);
|
||||
if (path.size() >= 256) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
RNA_END;
|
||||
|
||||
if (i <= 1) {
|
||||
if (path.is_empty()) {
|
||||
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
||||
}
|
||||
|
||||
|
@ -1448,7 +1422,7 @@ static int mute_links_exec(bContext *C, wmOperator *op)
|
|||
continue;
|
||||
}
|
||||
link->flag &= ~NODE_LINK_TEST;
|
||||
if (node_links_intersect(*link, mcoords, i)) {
|
||||
if (link_path_intersection(*link, path)) {
|
||||
tot++;
|
||||
}
|
||||
}
|
||||
|
@ -1462,7 +1436,7 @@ static int mute_links_exec(bContext *C, wmOperator *op)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (node_links_intersect(*link, mcoords, i)) {
|
||||
if (link_path_intersection(*link, path)) {
|
||||
nodeMuteLinkToggle(snode.edittree, link);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue