( [ 0,0,0 ].vector_to( [ 0,0,0 ] ) ).length.mm < 0.01.mm
-
is this "true" or "false"?:
( [ 0,0,0 ].vector_to( [ 0,0,0 ] ) ).length.mm < 0.01.mm
on my computer it is "false" - and I dont know why?
-
SketchUp's Length class uses some default tolerance in its comparisons - the tolerance is not documented as far as I know.
@unknownuser said:
The equality comparison on Length values uses the default tolerance that SketchUp uses for comparing lengths
In SketchUp-land:
> 0.01.mm == 0 #==> true
Search the following page for "tolerance"
http://www.sketchup.com/intl/en/developer/docs/ourdoc/length
-
nullvec = Geom;;Vector3d.new(0,0,0) l1 = nullvec.length.mm # obviously 0 mm or 0 inch l2 = 0.01.mm # 0.000393700787401575 inch l1 == l2 → true
but
0 < 0.000393700787401575 → true
This is because #mm or #to_mm etc. are methods that return an object of the Length class, not a Float. A Length is a Float that considers SketchUp's tolerance, which is currently set to 0.001 inch (we should never use this tolerance value directly since SketchUp might have the freedom to change it).
-
so to find the length of I should use length.to_f ?
-
@davidfi1 said:
so to find the length of I should use length.to_f ?
To treat it as a float you must use
to_f
, yes. The numeric value of the objects are the same. The only difference of theLength
which is a sub-class ofFloat
is the comparison operators.( [ 0,0,0 ].vector_to( [ 0,0,0 ] ) ).length.to_f < 0.01.mm
That works because you're now dealing with the standard floating point comparisons. Not knowing what your experience with floating points are, but just in case; here's a very informative site on the topic: http://floating-point-gui.de/ -
Very informative site in did.
Thank you.
I am a hardware engineer by training - so I know this problem from the other side
and still it is a little strange
Advertisement