[Bf-blender-cvs] [a12614d1668] geometry-nodes-simulation: Fix T102923: replace zero check with epsilons with uv constrain to bounds
Chris Blackbourn
noreply at git.blender.org
Mon Dec 19 19:05:23 CET 2022
Commit: a12614d16682b25771e45595a9067386f7d37172
Author: Chris Blackbourn
Date: Fri Dec 16 17:22:41 2022 +1300
Branches: geometry-nodes-simulation
https://developer.blender.org/rBa12614d16682b25771e45595a9067386f7d37172
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. */
}
More information about the Bf-blender-cvs
mailing list