How is this possible ?
-
SketchUp's internal accuracy is 1000 of an inch. So any lengths you compare that are shorter than that - or when the difference between the lengths is less than 0.001 - will compare as equal.
Length.<
http://code.google.com/apis/sketchup/docs/ourdoc/length.html@unknownuser said:
The < method is used to see if one length is less than another length.
For example, if l1 = 1.0.inch and l2 = 1.000001.inch then l1 == l2 so l1 < l2 should return false. -
hm... am I making stuff up again...
-
Thanks thomthom,
and while we are at it, another weird thing:def test() case Sketchup.active_model.selection[0].class when Sketchup;;Face puts "face" when Sketchup;;ComponentInstance puts "instance" when Sketchup;;Group puts "group" when Sketchup;;Image puts "image" when Sketchup;;Edge puts "edge" else puts "something else" end end
This always outputs "something else" in the Console. Case with 'class' as switch isn't allowed or not effective ?
-
This comparison weirdness doesn't happen for me.
Do you have a script that's loading and resetting==
for 'equality comparisons' in the Float class?
I ran a BareGrep on my ../Plugins folder and found no likely culprits for 'class Float
' matches - although I did find I have a Floatdef =~
in myRoof.rb
tools which takes Floats to within 1/1000 as being equal - as in0.0001==0 >>> false
BUT0.0001=~0 >>> true
- but I don't suspect that...
This is what I gety=9.09494701772928e-013 9.09494701772928e-013 y==0 false y<0 false y>0 true y==0.001 false y>0.001 false y<0.001 true (y*1000000).to_i/1000000.0 0.0 (y*10000000000000).to_i/10000000000000.0 9.0e-013
So you can see how to test for nearness to zero with the differing accuracies as the last two examples...
BUT all == return correct results otherwise -
@didier bur said:
Thanks thomthom,
and while we are at it, another weird thing:def test() > case Sketchup.active_model.selection[0].class > when Sketchup;;Face > puts "face" > when Sketchup;;ComponentInstance > puts "instance" > when Sketchup;;Group > puts "group" > when Sketchup;;Image > puts "image" > when Sketchup;;Edge > puts "edge" > else > puts "something else" > end > end
This always outputs "something else" in the Console. Case with 'class' as switch isn't allowed or not effective ?
I found this out when writing my SKMtools class
case v.class.to_s when 'Fixnum'
was my fix... it returns the class name as a string and compares it with another string in the 'when'... so your method WILL work thus
def test() case Sketchup.active_model.selection[0].class.to_s when 'Sketchup;;Face' puts "face" when 'Sketchup;;ComponentInstance' puts "instance" when 'Sketchup;;Group' puts "group" when 'Sketchup;;Image' puts "image" when 'Sketchup;;Edge' puts "edge" else puts "something else" end end
-
@tig said:
This comparison weirdness doesn't happen for me.
Do you have a script that's loading and resetting==
for 'equality comparisons' in the Float class?The object type you get from
Boundingbox
isLength
- notFloat
. This is why you see this difference. Length has that tolerance built in. Something one need to be aware of when you compare data in Ruby SU. Always check if you have aFloat
orLength
.@tig said:
was my fix... it returns the class name as a string and compares it with another string in the 'when'... so your method WILL work thus
But will be very slow - same performance issue like using
.typename
.I don't know why one can't use class for switch cases - but instead you should use
if,elsif
along with.class
or.is_?
in order to maintain performance. As string operations while iterating entities is just all too big of an performance hit. -
Thanks tt & tig for yur answers;
I'm aware of the "strings comparison time killer" that's why i want to use the class for the switch.
i'll use "elseif" instead -
I really don't understand why switch own't work - since
face1.class == face2.class
work fine... -
Ah - so then we can just do this:
def test() case Sketchup.active_model.selection[0] when Sketchup;;Face puts "face" when Sketchup;;ComponentInstance puts "instance" when Sketchup;;Group puts "group" when Sketchup;;Image puts "image" when Sketchup;;Edge puts "edge" else puts "something else" end end
Right?
-
Partial answer here: http://www.postal-code.com/mrhappy/blog/2007/02/01/ruby-comparing-an-objects-class-in-a-case-statement/
and here http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/3d83faf049160e58This works:
case Sketchup.active_model.selection[0] when 'Sketchup;;Face' puts "face" ...
The simplest the best !
-
@didier bur said:
Partial answer here: http://www.postal-code.com/mrhappy/blog/2007/02/01/ruby-comparing-an-objects-class-in-a-case-statement/
and here http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/3d83faf049160e58This works:
case Sketchup.active_model.selection[0] > when 'Sketchup;;Face' > puts "face" > ...
The simplest the best !
So in your case
def test() case Sketchup.active_model.selection[0] when Sketchup;;Face puts "face" when Sketchup;;ComponentInstance puts "instance" when Sketchup;;Group puts "group" when Sketchup;;Image puts "image" when Sketchup;;Edge puts "edge" else puts "something else" end end
should work ??? Avoiding the .to_s step
Advertisement