title: How to get all points contained within an SVG path string without checking every point on canvas?
body: <p>Is there an efficient way to find the <code>[x, y]</code> coordinates of every point in a inside a path without manually checking every point on the entire canvas using <code>context.isPointInPath()</code>? </p>
  
  <p>Sample path from a geojson</p>
  
  <pre><code>&lt;path d="
    M 588, 173,
    L 588, 176,  L 585, 216,  L 585, 216,  L 584, 223,
    L 580, 274,  L 565, 273,  L 565, 273,  L 549, 271,
    L 539, 270,  L 535, 269,  L 513, 267,  L 503, 266,
    L 486, 264,  L 477, 262,  L 468, 261,  L 464, 260,
    L 455, 259,  L 449, 258,  L 451, 249,  L 452, 244,
    L 453, 233,  L 456, 218,  L 456, 215,  L 460, 192,
    L 460, 191,  L 462, 180,  L 463, 174,  L 463, 171,
    L 464, 167,  L 464, 161,  L 465, 158,  L 470, 159,
    L 471, 159,  L 477, 160,  L 477, 160,  L 480, 161,
    L 482, 161,  L 487, 161,  L 499, 163,  L 500, 163,
    L 514, 165,  L 534, 168,  L 535, 168,  L 544, 169,
    L 555, 170,  L 557, 170,  L 565, 171,  L 581, 173,
    Z"  
  fill="transparent" stroke-width="1" stroke="black"&gt;&lt;/path&gt;
  </code></pre>
  
  <p>For example, this is what I'm doing now with a geojson file:</p>
  
  <pre><code>  const points = [];
    const pointWidth = 2;
  
    for (let x = 0; x &lt; canvasWidth; x += pointWidth) {
      for (let y = 0; y &lt; canvasHeight; y += pointWidth) {
  
        for (const feature of countyGeoJson.features) {
          const d = pathGenerator(feature);
          const countyShape = new Path2D(d);
  
          if (context.isPointInPath(countyShape, x, y)) {
            points.push({ coords: [x, y], data: feature.properties });
            break;
          }
        }
      }
    }
  </code></pre>
  
  <p>Basically, I'm looping through every point in the canvas grid (there are over one million), and nesting another loop that looks through every feature to determine if the point is in the feature's projected path string. That is terribly inefficient and my browser cannot handle it.</p>
  
  <p>Is there a way to use the path string itself to generate the points?</p>