⚠️ Important | Please update Libfredo to v15.1a for bugfixes associated to SketchUp 2025 and below
Download
Odd Math
-
Can anyone explain the results of this snippet?
model = Sketchup.active_model entities = model.entities selection = model.selection camera = model.active_view.camera cdir = camera.direction puts "camera dir; #{ cdir.inspect}" sum = cdir.x.abs + cdir.y.abs + cdir.z.abs puts "sum; #{sum.inspect}" puts "sum == 1? #{sum == 1}"
Results:
camera dir; Vector3d(0, 1, 0) sum; 1 sum == 1? false
-
Yes. .to_s / .inspect print an approximation of the Float value. When it prints (0,1,0), thats just the answer to 4 significant figures. Your Float(1) comparison simply shows that difference.
-
Thanks Adam. I still don't understand why sum (which is a Float)shown as 1 instead of 1.0
Might the .inspect method be over-ridden?
Advertisement