image-js icon indicating copy to clipboard operation
image-js copied to clipboard

Enhance `filled` option in `drawPolygon`

Open opatiny opened this issue 3 years ago • 1 comments

Enhance the performance of the fill in drawPolygon by running robustPointInPolygon only when it's strictly necessary.

We might first draw the contour of the polygon on a mask, and at every pixel, verify if the previous value and the current value are equal. If it is the case, the value of robustPointInPolygon should be the same as for the previous pixel.

opatiny avatar Jun 29 '22 08:06 opatiny

A better way of enhancing performance would be:

  • Draw the contour first
  • Find one point inside of the polygon
  • Make a floodFill using the previous point as a starting point

opatiny avatar Jun 30 '22 06:06 opatiny