Cleanup: Split node link draw culling to separate function

This was only really used in one place, so better to just do it there
rather than requiring another argument for the handle calculation.
This commit is contained in:
Hans Goudey 2022-09-02 14:47:23 -05:00
parent ab6702a40f
commit 8d1e5334ec
4 changed files with 32 additions and 32 deletions

View File

@ -1585,8 +1585,7 @@ void draw_nodespace_back_pix(const bContext &C,
GPU_matrix_pop();
}
bool node_link_bezier_handles(const View2D *v2d,
const SpaceNode *snode,
bool node_link_bezier_handles(const SpaceNode *snode,
const bNodeLink &link,
std::array<float2, 4> &points)
{
@ -1637,35 +1636,38 @@ bool node_link_bezier_handles(const View2D *v2d,
/* Straight line: align all points. */
points[1] = math::interpolate(points[0], points[3], 1.0f / 3.0f);
points[2] = math::interpolate(points[0], points[3], 2.0f / 3.0f);
return true;
}
else {
const float dist = curving * 0.1f * math::distance(points[0].x, points[3].x);
const float dist = curving * 0.10f * fabsf(points[0].x - points[3].x);
points[1].x = points[0].x + dist;
points[1].y = points[0].y;
points[1].x = points[0].x + dist;
points[1].y = points[0].y;
points[2].x = points[3].x - dist;
points[2].y = points[3].y;
if (v2d && min_ffff(points[0].x, points[1].x, points[2].x, points[3].x) > v2d->cur.xmax) {
return false; /* clipped */
}
if (v2d && max_ffff(points[0].x, points[1].x, points[2].x, points[3].x) < v2d->cur.xmin) {
return false; /* clipped */
points[2].x = points[3].x - dist;
points[2].y = points[3].y;
}
return true;
}
bool node_link_bezier_points(const View2D *v2d,
const SpaceNode *snode,
static bool node_link_draw_is_visible(const View2D &v2d, const std::array<float2, 4> &points)
{
if (min_ffff(points[0].x, points[1].x, points[2].x, points[3].x) > v2d.cur.xmax) {
return false;
}
if (max_ffff(points[0].x, points[1].x, points[2].x, points[3].x) < v2d.cur.xmin) {
return false;
}
return true;
}
bool node_link_bezier_points(const SpaceNode *snode,
const bNodeLink &link,
float coord_array[][2],
const int resol)
{
std::array<float2, 4> points;
if (!node_link_bezier_handles(v2d, snode, link, points)) {
if (!node_link_bezier_handles(snode, link, points)) {
return false;
}
@ -2181,7 +2183,10 @@ void node_draw_link_bezier(const bContext &C,
const bool selected)
{
std::array<float2, 4> points;
if (!node_link_bezier_handles(&v2d, &snode, link, points)) {
if (!node_link_bezier_handles(&snode, link, points)) {
return;
}
if (!node_link_draw_is_visible(v2d, points)) {
return;
}
const NodeLinkDrawConfig draw_config = nodelink_get_draw_config(
@ -2246,7 +2251,7 @@ void node_draw_link_dragged(const bContext &C,
}
std::array<float2, 4> points;
if (!node_link_bezier_handles(&v2d, &snode, link, points)) {
if (!node_link_bezier_handles(&snode, link, points)) {
return;
}

View File

@ -108,7 +108,7 @@ static bool add_reroute_intersect_check(const bNodeLink &link,
{
float coord_array[NODE_LINK_RESOL + 1][2];
if (node_link_bezier_points(nullptr, nullptr, link, coord_array, NODE_LINK_RESOL)) {
if (node_link_bezier_points(nullptr, link, coord_array, NODE_LINK_RESOL)) {
for (int i = 0; i < tot - 1; i++) {
for (int b = 0; b < NODE_LINK_RESOL; b++) {
if (isect_seg_seg_v2_point(

View File

@ -229,17 +229,14 @@ void node_draw_link_bezier(const bContext &C,
int th_col2,
int th_col3,
bool selected);
/** If v2d not nullptr, it clips and returns 0 if not visible. */
bool node_link_bezier_points(const View2D *v2d,
const SpaceNode *snode,
bool node_link_bezier_points(const SpaceNode *snode,
const bNodeLink &link,
float coord_array[][2],
int resol);
/**
* Return quadratic beziers points for a given nodelink and clip if v2d is not nullptr.
* Return quadratic beziers points for a given nodelink.
*/
bool node_link_bezier_handles(const View2D *v2d,
const SpaceNode *snode,
bool node_link_bezier_handles(const SpaceNode *snode,
const bNodeLink &ink,
std::array<float2, 4> &points);
void draw_nodespace_back_pix(const bContext &C,

View File

@ -120,8 +120,6 @@ static void pick_input_link_by_link_intersect(const bContext &C,
const float2 &cursor)
{
SpaceNode *snode = CTX_wm_space_node(&C);
const ARegion *region = CTX_wm_region(&C);
const View2D *v2d = &region->v2d;
float2 drag_start;
RNA_float_get_array(op.ptr, "drag_start", drag_start);
@ -140,7 +138,7 @@ static void pick_input_link_by_link_intersect(const bContext &C,
if (link->tosock == socket) {
/* Test if the cursor is near a link. */
std::array<float2, 4> points;
node_link_bezier_handles(v2d, snode, *link, points);
node_link_bezier_handles(snode, *link, points);
std::array<float2, NODE_LINK_RESOL + 1> data;
BKE_curve_forward_diff_bezier(points[0].x,
@ -1327,7 +1325,7 @@ static bool node_links_intersect(bNodeLink &link, const float mcoords[][2], int
{
float coord_array[NODE_LINK_RESOL + 1][2];
if (node_link_bezier_points(nullptr, nullptr, link, coord_array, NODE_LINK_RESOL)) {
if (node_link_bezier_points(nullptr, link, coord_array, NODE_LINK_RESOL)) {
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], coord_array[b], coord_array[b + 1]) > 0) {
@ -1967,7 +1965,7 @@ void ED_node_link_intersect_test(ScrArea *area, int test)
continue;
}
if (node_link_bezier_points(nullptr, nullptr, *link, coord_array, NODE_LINK_RESOL)) {
if (node_link_bezier_points(nullptr, *link, coord_array, NODE_LINK_RESOL)) {
float dist = FLT_MAX;
/* loop over link coords to find shortest dist to