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

    Same Colors not equal?

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 5 Posters 318 Views 5 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      There seems to be no [working] method for '==' for comparing Colors: but c1.to_s==c2.to_s does return true if they have the same rgb values...

      TIG

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        A color is a Sketchup::Color object. So what you've done there is just compare the two objects, which are different, regardless of what their actual color is. It would be nice if Google fixed that. πŸ‘

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

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

          As well as comparing the Color turned into strings c1.to_s==c2.to_s to get true/false, you could also compare the rgb values
          c1.red==c2.red c1.green==c2.green c1.blue==c2.blue
          will all return true if the three color values are all equal...

          As Chris says the Colors are two different objects so they aren't equal so == returns false unless c1 and c2 refer to the same Color object !

          TIG

          1 Reply Last reply Reply Quote 0
          • C Offline
            cjthompson
            last edited by

            @tig said:

            There seems to be no [working] method for '==' for comparing Colors: but c1.to_s==c2.to_s does return true if they have the same rgb values...

            c1.to_a == c2.to_a works too.

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

              So there are lots of ways of checking if two Colors are equal, BUT NOT the obvious c1==c2 !

              TIG

              1 Reply Last reply Reply Quote 0
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                Does converting to an array work faster than to string I wonder? As an array, are the RGB values still left as integers? That seems like it would be a faster comparison.

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

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

                  Also c1.to_i==c2.to_i works, as the color is converted to a single integer format - that might be even quicker ?
                  πŸ˜•

                  TIG

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

                    @chris fullmer said:

                    A color is a Sketchup::Color object. So what you've done there is just compare the two objects, which are different, regardless of what their actual color is. It would be nice if Google fixed that. πŸ‘

                    Ah, of course.

                    The "Ruby way" would be to define the <=> operator for the Color class, and then mix in Comparable.

                    Hi

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

                      Then again, what does it mean for a Color to be greater than another? Nevermind...

                      Equality is all that's needed. I think the .to_i comparison makes the most sense for clarity.

                      Hi

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

                        Yea, always avoid comparing strings.
                        Such a shame that they've not added a proper comparison method for all objects.

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

                        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