Skip to content

How the convexFillCells algorithm works

Griswald Brooks edited this page Sep 24, 2020 · 9 revisions

This algorithm is confusing, so I looked at the code and tried to figure it out. This is how it does it:

Assumptions:

  • The size_x input parameter is a big number so don't worry about it.
  • The polygon input parameter are the vertices of the polygon to fill.
    • The produced outline is a convex hull

Steps:

  1. If the polygon parameter has less than 3 elements, return an empty vector.
  2. Create the outline from the input polygon vertices using the polygonOutlineCells function.
  1. Sort the outline vector by the x coordinate value, from least to greatest.
  1. Start from the beginning of the outline vector, for every x value, find the Cell with biggest and smallest y value
  1. For each x value, push back a Cell into the output vector from the smallest y value to the biggest y value

At the end the output vector should have every cell that was inside the outline, because it went column by column to find the extrema of the y value for that column.

Clone this wiki locally