Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Right now I can see small solutions that might speed up your algorithm to limit as much as possible iterating over all of your elements,</p> <p>The first thing you can do is have a default colour. When you see that colour, you know you don't need to iterate all over your array of elements. It will accelerate large poorly populated areas. It's very easy to implement, just adding a if.</p> <p>For more dense areas you can implement some kind of colour caching. That means you store an array of colour you encountered. When you check a pixel, you first check the cache and then go over the entire list of elements, and if you find the element, add it to the cache. It should accelerate cases with few big elements but will be bad if you have lots of small elements, which is very unlikely if you have picking... You can accelerate your cache buy sorting your cached elements by last hit or/and by number of hits, it's very likely to find the same element in a continuous raw of pixels. It's more work but stays relatively easy and short to implement.</p> <p>Last optimisation would be to implement a space partitioning algorithm to filter the elements you want to check. That would be more work but will pay better of on the long run.</p> <p>edit : I'm not a dart guy but this is how it would look like to implement in a basic way the first two optimisations:</p> <pre><code>var cache = new Map&lt;UInt32, PickerInstance&gt;(); for (int i = 0; i &lt; size; i += 4) { UInt32 colour = _color[i] &lt;&lt; 24 | _color[i+1] &lt;&lt; 16 | _color[i+2] &lt;&lt; 8 | 0; // I guess we can just skip transparency. if (_selection.length &gt;= picker.numberOfInstances) { // selected all available objects, no need to keep searching break; } // black is a good default colour. if(colour == 0) { // if the pixel is black we didn't hit any element :( continue; } // check the cache if(cache[colour] != null) { _selection.add(cache[colour]); continue; } // valid colour and cache miss, we can't avoid iterating the list. PickerInstance pi = picker.findInstanceByColor(_color[i], _color[i+1], _color[i+2]); if (pi == null) { continue; } _selection.add(pi); // update cache cache[colour] = pi; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload