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

    Optimize Challenge #1 - Find Curves (connected edges)

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 1 Posters 231 Views 1 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.
    • thomthomT Offline
      thomthom
      last edited by

      I'll be trying out an experiment to see if we can all learn from each other the various tricks and methods we've all learned independently.
      If it turns out to be of value I'll to to make regular challenges like this. (Please suggest new challenges.)

      The goal is to see the various ways a problem can be resolved and how it can be done in the most efficient manner and with easily readable code.

      Challenge #1
      Finding curves
      Given a set of entities, find all sets of connected edges, and return an array of each set sorted from start to end.
      ("Curve" here is a set of edges, not Sketchup::Curve objects. Edges connected to faces should be ignored.)

      FindCurves.png
      Results from this should be:

      <span class="syntaxdefault"><br /></span><span class="syntaxkeyword">[<br /></span><span class="syntaxdefault">  </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">sorted_edges</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># (Curve1)<br /></span><span class="syntaxdefault">  </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">sorted_edges</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># (Curve2)<br /></span><span class="syntaxdefault">  </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">sorted_edges</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># (Curve3)<br /></span><span class="syntaxdefault">  </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">sorted_edges</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># (Curve4)<br /></span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> </span>
      

      Use the attached model to benchmark your solution.
      Find_Curves_Test_Model.png

      Post back:

      • the time it took to find all curves
      • the code

      (Please make your test code colourize the curves afterwards to visually inspect correct results. No not include the colouring in your benchmark time.)


      22099 Edges

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

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

        My current solution:

        TT_Find_Curves.run === Find Curves === Method: TT_Find_Curves Found 4253 curves in 7.191s

        (I must be doing something terribly wrong, as 7 seconds seems all too slow.)

        TT_Find_Curves_Results.png


        Revision 1

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

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

          Faster solution, using hashes for quick lookups:

          ` === Find Curves ===

          Sorting: 0.306s (11%)
          Filter: 0.05s

          Method: TT_Find_Curves
          Found 4253 curves in 2.62s`


          Revision 2

          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