Commit: 0079460dc79a6c4798ec41e86550d8f0882ed313
Author: Chris Blackbourn
Date:   Fri Dec 16 17:22:41 2022 +1300
Branches: master
https://developer.blender.org/rB0079460dc79a6c4798ec41e86550d8f0882ed313

Fix T102923: replace zero check with epsilons with uv constrain to bounds

Small roundoff errors during UV editing can sometimes occur, most likely
due to so-called "catastrophic cancellation".

Here we set a tolerance around zero when using Constrain-To-Bounds and UV 
Scaling.

The tolerance is set at one quarter of a texel, on a 65536 x 65536 texture.

TODO: If this fix holds, we should formalize the tolerance into the UV editing
subsystem, perhaps as a helper function, and investigate where else it needs
to be applied.

Differential Revision: https://developer.blender.org/D16702

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

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

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

diff --git a/source/blender/editors/transform/transform_mode_resize.c 
b/source/blender/editors/transform/transform_mode_resize.c
index 70599c3577c..4e671768721 100644
--- a/source/blender/editors/transform/transform_mode_resize.c
+++ b/source/blender/editors/transform/transform_mode_resize.c
@@ -95,9 +95,14 @@ static void constrain_scale_to_boundary(const float 
numerator,
                                         const float denominator,
                                         float *scale)
 {
-  if (denominator == 0.0f) {
-    /* The origin of the scale is on the edge of the boundary. */
-    if (numerator < 0.0f) {
+  /* It's possible the numerator or denominator can be very close to zero due 
to so-called
+   * "catastrophic cancellation". See T102923 for an example. We use epsilon 
tests here to
+   * distinguish between genuine negative coordinates versus coordinates that 
should be rounded off
+   * to zero. */
+  const float epsilon = 0.25f / 65536.0f; /* i.e. Quarter of a texel on a 
65536 x 65536 texture. */
+  if (fabsf(denominator) < epsilon) {
+    /* The origin of the scale is very near the edge of the boundary. */
+    if (numerator < -epsilon) {
       /* Negative scale will wrap around and put us outside the boundary. */
       *scale = 0.0f; /* Hold at the boundary instead. */
     }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to