comparing coords rounding long numbers

Is there a way to set the rounding accuracy at top of script?

My comparison of vert coords failed because of long numbers. Am I going to have to enclose everything in the rnd() function? ie.,

rnd(vert[i].co.x) == rnd(vert[i+1].co.x)

here is some output:
topI: [0]
me.verts[maxYidx].co.y: 0.999999940395
me.verts[i].co.y: 0.999999940395
topI: [0, 1]
me.verts[maxYidx].co.y: 0.999999940395
me.verts[i].co.y: -1.0
topI: [0, 1, 2]
me.verts[maxYidx].co.y: 0.999999940395
me.verts[i].co.y: -0.999999821186
topI: [0, 1, 2, 3]
me.verts[maxYidx].co.y: 0.999999940395
me.verts[i].co.y: 1.00000035763
update maxYidx: 3
maxYidx: 3
verts[maxYidx].co: -1.000000, 1.000000, 0.000000
topI: [3, 0, 1, 2]
verts: [MVert (1.000000 1.000000 0.000000) (0.000000 0.000000 1.000000) 0]
verts: [MVert (1.000000 -1.000000 0.000000) (0.000000 0.000000 1.000000) 1]
verts: [MVert (-1.000000 -1.000000 0.000000) (0.000000 0.000000 1.000000) 2]
verts: [MVert (-1.000000 1.000000 0.000000) (0.000000 0.000000 1.000000) 3]

As many other users, you have discovered something about BLENDER by your own experience, I guess… Unfortunately, it is the well-known imprecision of BLENDER!!! Frankly, if you put numbers or arithmetic expression in RND() function you wont get a better picture…

Solution - at least to me - is to compare values against a threshold… Soooo you can define a small value (your threshold) - something like 0.000001 - then compare the deviations of your numbers from a target value by using the threshold.

Normally, you have 3D coordinates, so for these the following work well:

threshold = 0.00001

def Dist_3D(a,b):
    return math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z))

if (d <= threshold):  # i.e. if TRUE you may judge your points are at the same 3D-location
  blah-blah-blah (1).......
else:  # i.e. points differ a lot = points differ more than your selected threshold
   blah-blah-blah (2).......

You may wish to implement the Dist_3D() function in a form of lists of 3 elements…

If you have 2 vectors, you may use the length of their difference to compare against the threshold value.

In case of comparing just 1 value, you can use a direct substraction of your target_value (not raising to squares, etc) but dont forget to take the absolute value of the difference or compare with (-threshold) and (+threshold).

Hope this helps you! :cool:


would this work when you want to play with very small dimensions like micrometer

if you change the scale in blender to get that precision
but on the other end you still are limited to 7 digits even in 2.5 i think


Ohhh boy…
I knew the rounding issues was out there… ahhh!!!
Thanks for the func. I’ll use it.