script-8.github.io icon indicating copy to clipboard operation
script-8.github.io copied to clipboard

Inconsistent behavior with polyStroke()

Open thykka opened this issue 5 years ago • 2 comments

I noticed that polyStroke() has a quirk, where given 2 or 5 arguments, it draws unclosed polygons, i.e.:

polyStroke([
  // empty array as last point
  [0,0], [64, 0], [64, 64], []
], 5)
image

When given 3 arguments however, it doesn't draw anything. I'm guessing this behavior appears because this:

Math.min.apply(
  Math,
  [[0,0], [1,1], []].map(p => p[0])
)

...would return NaN

Since drawing unclosed polylines has plenty of use-cases, perhaps this behaviour should be parametrized, and unified across the different drawing implementations?

thykka avatar Jan 18 '20 13:01 thykka

Oh interesting. Very interesting. Would you be able to provide image examples for each quirk?

gabrielflorit avatar Jan 22 '20 16:01 gabrielflorit

The 3 argument version simply draws nothing, whereas the 5 argument version behaves like 2.

Test case cassette

thykka avatar Jan 23 '20 16:01 thykka