sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Length woes

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 6 Posters 1.3k Views 6 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.
    • G Offline
      g2ktcf
      last edited by

      Al,

      I do remember reading something about "within a tolerance" for many of the SU functions. I do not know what the tolerance is but you may be getting two values the the sytem considers EQUAL within a tolerance. Then the "<" would be false as both numbers are Zero within this established tolerance (i thought it was 0.01")

      just my quick after lunch thoughts...

      Chris

      1 Reply Last reply Reply Quote 0
      • Didier BurD Offline
        Didier Bur
        last edited by

        Yes,
        In fact, I often had to write my own "within tolerance" method, as well as several other coders I think. Safer... 😉

        DB

        1 Reply Last reply Reply Quote 0
        • G Offline
          g2ktcf
          last edited by

          What is the actual "tolerance" value? Anyone?

          1 Reply Last reply Reply Quote 0
          • T Offline
            todd burch
            last edited by

            Try Float::EPSILON.

            Todd

            1 Reply Last reply Reply Quote 0
            • G Offline
              g2ktcf
              last edited by

              Okay...that's a REALLY small number. 😕

              1 Reply Last reply Reply Quote 0
              • G Offline
                g2ktcf
                last edited by

                Okay, I had to play this morning on this.

                I took the same L1 and L2 example and varied the value of l2 by a factor of 10 until the L1==L2 statement returned FALSE. It seems that a value of l2=0.001 is the point at which things change. I tried an l2 = 0.0005 and that returned TRUE. This must be handled in the class methods....Right???

                1 Reply Last reply Reply Quote 0
                • G Offline
                  g2ktcf
                  last edited by

                  It seems the same argument goes for the Zero Vector. Setting either of these with a value less than 0.001" will result in SU "seeing' them as zero even though they print out differently. 😮

                  1 Reply Last reply Reply Quote 0
                  • TIGT Offline
                    TIG Moderator
                    last edited by

                    "float-tolerance.rb" is by RickW [I think - I hope he doesn't mind me repeating it in its entirety here]

                    
                    class Float
                    	def =~(num2,tol=10000)
                    		num1=(self*tol).to_i
                    		num2=(num2*tol).to_i
                    		return true if num1==num2
                    		return nil
                    	end
                    end #class Float
                    
                    

                    Then you test two floats thus:
                    float1 =~ float2
                    It returns false or true
                    You could adjust the float tol part to suit...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • R Offline
                      RickW
                      last edited by

                      I don't mind as long as there's a link 😄
                      (http://www.smustard.com/script/FloatTolerance)

                      RickW
                      [www.smustard.com](http://www.smustard.com)

                      1 Reply Last reply Reply Quote 0
                      • G Offline
                        g2ktcf
                        last edited by

                        I actually found this implied in an example in the length class API. If you use a float, the math comes out like you would expect. The Length class is where this changes (as Al suspected). Notice that the 0.001" value that I got while testing is not mentioned as a limiting factor.

                        @unknownuser said:

                        <
                        The < method is used to see if one length is less than another length.

                        Syntax
                        status = length1 < length2
                        Arguments
                        length1 - a length value

                        length2 - a length value

                        Return Value
                        status - true if length1 is < length2; false if length1 is not < length2

                        Comments
                        For example, if l1 = 1.0.inch and l2 = 1.000001.inch then l1 == l2 so l1 < l2 should return false.

                        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