sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Odd Math

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 246 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      Jim
      last edited by

      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
      
      

      Hi

      1 Reply Last reply Reply Quote 0
      • AdamBA Offline
        AdamB
        last edited by

        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.

        Developer of LightUp Click for website

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by

          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?

          Hi

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement