From 67308d73a4f9ec34ef42ad22d48dad5840a8a5fd Mon Sep 17 00:00:00 2001 From: Leon Schittek Date: Fri, 23 Sep 2022 17:54:27 +0200 Subject: Node Editor: Adjust node link curving Clamp node link curving when the link is close to horizontal to prevent overshooting at the ends. Reviewed By: Pablo Vazquez, Hans Goudey Differential Revision: http://developer.blender.org/D16041 --- source/blender/editors/space_node/drawnode.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'source/blender/editors/space_node/drawnode.cc') diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc index fbbdd40e92e..b2510df9105 100644 --- a/source/blender/editors/space_node/drawnode.cc +++ b/source/blender/editors/space_node/drawnode.cc @@ -1604,12 +1604,19 @@ static void calculate_inner_link_bezier_points(std::array &points) points[2] = math::interpolate(points[0], points[3], 2.0f / 3.0f); } else { - const float dist = curving * 0.1f * math::distance(points[0].x, points[3].x); + const float dist_x = math::distance(points[0].x, points[3].x); + const float dist_y = math::distance(points[0].y, points[3].y); - points[1].x = points[0].x + dist; + /* Reduce the handle offset when the link endpoints are close to horizontal. */ + const float slope = safe_divide(dist_y, dist_x); + const float clamp_factor = math::min(1.0f, slope * (4.5f - 0.25f * float(curving))); + + const float handle_offset = curving * 0.1f * dist_x * clamp_factor; + + points[1].x = points[0].x + handle_offset; points[1].y = points[0].y; - points[2].x = points[3].x - dist; + points[2].x = points[3].x - handle_offset; points[2].y = points[3].y; } } -- cgit v1.2.3