treeform/pixie

paths.nim polygon draws an unecessary lineTo

kwhitefoot opened this issue · 2 comments

In proc polygon the code executes path.moveTo(x + size * cos(0.0), y + size * sin(0.0)) to move to the start of the polygon.

The for side in loop enumerates side from 0 to sides. Surely this should be 1 to sides because when side == 0 it will draw a line to the starting point.

Or have I missed something that should be obvious?

proc polygon*(
  path: Path, x, y, size: float32, sides: int
) {.raises: [PixieError].} =
  ## Adds an n-sided regular polygon at (x, y) with the parameter size.
  if sides <= 0:
    raise newException(PixieError, "Invalid polygon sides value")
  path.moveTo(x + size * cos(0.0), y + size * sin(0.0))
  for side in 0 .. sides: <-- Should be: for ide in 1 .. sides:
    path.lineTo(
      x + size * cos(side.float32 * 2.0 * PI / sides.float32),
      y + size * sin(side.float32 * 2.0 * PI / sides.float32)
    )

I have merged in a fix for this. I also rotated the polygons by 90 to be more inline how it works in Figma.

Thank you for the issue. If some thing is still unclear feel free to re-open.