Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, one obvious problem is that you're parsing the string for every city for every pixel.</p> <p>I would <em>strongly</em> suggest that the first thing you do is convert your <code>placeDataList</code> into a more sensible format - a <code>List&lt;City&gt;</code> where each city has properties of <code>Latitude</code>, <code>Longitude</code> and <code>Population</code>.</p> <p>I wouldn't be surprised to find that the vast bulk of your time is being spent performing parsing. There are some other calculations you're repeating over and over, such as <code>(24.443136 / size_h)</code> but I doubt those are as significant.</p> <p>If you can work out some very crude measure for which areas will be covered for a particular city, you could avoid calculating the <em>exact</em> distance each time. For example, you could work out the minimum and maximum values for latitude and longitude which <em>might</em> be within 150 miles, and do a very quick test for each city before doing any more complicated maths.</p> <p>Some stylistic issues:</p> <ul> <li>Use a foreach loop where you can</li> <li>Follow .NET naming conventions, e.g. <code>GetPixelColor</code> instead of <code>getPixelColor</code></li> <li>Think about your names - the parameters for <code>getPixelColor</code> aren't really a width and height, are they? They're a <em>position</em> (e.g. x and y)</li> <li><p>I would generally encourage you to use braces for <em>every</em> loop and <em>every</em> <code>if</code> block. Not everyone goes along with that, but I find this sort of construct to be error-prone and hard to read:</p> <pre><code>for (int i = 0; i &lt; pixel_h; i++) for (int j = 0; j &lt; pixel_w; j++) { pixelColor = getPixelColor(i, j); bmp.SetPixel(j, i, pixelColor); } </code></pre></li> </ul>
 

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