[Bf-blender-cvs] [3f39719b5df] master: Fix [T51595]: Snap to edge does not work with high zoom level

mano-wii noreply at git.blender.org
Tue Jul 11 22:03:58 CEST 2017


Commit: 3f39719b5df592caa6bd1cd68da38377855b89cc
Author: mano-wii
Date:   Tue Jul 11 17:03:49 2017 -0300
Branches: master
https://developer.blender.org/rB3f39719b5df592caa6bd1cd68da38377855b89cc

Fix [T51595]: Snap to edge does not work with high zoom level

That problem occurs because of the imprecision of `short int` (16 bits).
The 3d coordinates are converted to 2d, and when they are off the screen, their values can exceed 32767! (max short int value)

One quick solution is to use float instead of short

The snap code is actually a little tricky. I want to make some arithmetic simplifications in it

===================================================================

M	source/blender/editors/transform/transform_snap_object.c

===================================================================

diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c
index 15839de32db..8f10098c4c2 100644
--- a/source/blender/editors/transform/transform_snap_object.c
+++ b/source/blender/editors/transform/transform_snap_object.c
@@ -1170,15 +1170,12 @@ static float dist_squared_to_projected_aabb(
 	vb2d[0] *= data->win_half[0];
 	vb2d[1] *= data->win_half[1];
 
-	//float dvec[2], edge[2], rdist;
-	//sub_v2_v2v2(dvec, data->mval, va2d);
-	//sub_v2_v2v2(edge, vb2d, va2d);
-	float rdist;
-	short dvec[2] = {data->mval[0] - va2d[0], data->mval[1] - va2d[1]};
-	short edge[2] = {vb2d[0] - va2d[0], vb2d[1] - va2d[1]};
-	float lambda = dvec[0] * edge[0] + dvec[1] * edge[1];
+	float dvec[2], edge[2], lambda, rdist;
+	sub_v2_v2v2(dvec, data->mval, va2d);
+	sub_v2_v2v2(edge, vb2d, va2d);
+	lambda = dot_v2v2(dvec, edge);
 	if (lambda != 0.0f) {
-		lambda /= edge[0] * edge[0] + edge[1] * edge[1];
+		lambda /= len_squared_v2(edge);
 		if (lambda <= 0.0f) {
 			rdist = len_squared_v2v2(data->mval, va2d);
 			r_axis_closest[main_axis] = true;




More information about the Bf-blender-cvs mailing list