sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    ( [ 0,0,0 ].vector_to( [ 0,0,0 ] ) ).length.mm < 0.01.mm

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 4 Posters 119 Views 4 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.
    • D Offline
      Davidfi1
      last edited by Davidfi1

      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?

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

        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

        Hi

        1 Reply Last reply Reply Quote 0
        • A Offline
          Aerilius
          last edited by

          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).

          1 Reply Last reply Reply Quote 0
          • D Offline
            Davidfi1
            last edited by

            so to find the length of I should use length.to_f ?

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @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 the Length which is a sub-class of Float 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/

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • D Offline
                Davidfi1
                last edited by

                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 😄

                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