From 7e53fe106aa8912f31cc8f01b93231ef09558d4d Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Thu, 18 Jan 2024 11:17:00 -0300 Subject: [PATCH] Fix: Individual projection sometimes snapping to the wrong object The code was comparing real distance to square distance, which is obviously wrong. --- source/blender/editors/transform/transform_snap_object.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/transform/transform_snap_object.cc b/source/blender/editors/transform/transform_snap_object.cc index 1e663807ebd..930a3fa9159 100644 --- a/source/blender/editors/transform/transform_snap_object.cc +++ b/source/blender/editors/transform/transform_snap_object.cc @@ -700,7 +700,7 @@ bool nearest_world_tree(SnapObjectContext *sctx, vec = float3(nearest.co) - curr_co; } - float original_distance = math::length(math::transform_direction(obmat, vec)); + float original_distance = math::length_squared(math::transform_direction(obmat, vec)); if (r_nearest->dist_sq <= original_distance) { return false; } @@ -727,7 +727,7 @@ bool nearest_world_tree(SnapObjectContext *sctx, * When multiple steps are tested, we cannot depend on the distance calculated for * `nearest.dist_sq`, as it reduces with each step. */ vec = co - curr_co; - r_nearest->dist_sq = math::length(math::transform_direction(obmat, vec)); + r_nearest->dist_sq = math::length_squared(math::transform_direction(obmat, vec)); } return true; }