nearest_vertex_co was not reset when a new triangle was intersected by
the ray, so it was always returning the closest vertex to the real
cursor position in any triangle, which was not always the triangle under
the cursor.
Details
Details
Diff Detail
Diff Detail
- Repository
- rB Blender
Event Timeline
Comment Actions
I don't think this is correct. Treating coordinate (0, 0, 0) as something special is wrong.
I can think of two possible ways to make it right:
- Use boolean flag which denotes whether there is a known nearest coordinate or not. And then the check becomes if (!have_closest_co || len(..) < len(...)).
- Initialize nearest vertex to FLT_MAX coordinates. From quick thinking seems this will give correct behavior as well.
Comment Actions
Had a quick discussion with Brecht in blender-coders.
Thing is: historically in Blender some find-extremum code is not numerically robust. However, in the new code is better to not rely on floating point comparison.
So here suggestion would be to actually use explicit check for whether value is initialized to something meaningful or not. Here you can easily do it by checking whether this is the first loop iteration.
Comment Actions
For the readability you can do:
if (j == 0 || len_squared_v3v3(location, co[j]) < len_squared_v3v3(location, nearest_vertex_co)) {