Merge pull request #398 from treeform/dev

Fix for #393 and other polygon improvements.
This commit is contained in:
treeform 2022-03-18 14:07:03 -07:00 committed by GitHub
commit a7e4aac165
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 15 additions and 5 deletions

View file

@ -632,13 +632,14 @@ 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:
## Polygons "face" north.
if sides <= 2:
raise newException(PixieError, "Invalid polygon sides value")
path.moveTo(x + size * cos(0.0), y + size * sin(0.0))
for side in 0 .. sides:
path.moveTo(x + size * sin(0.0), y - size * cos(0.0))
for side 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)
x + size * sin(side.float32 * 2.0 * PI / sides.float32),
y - size * cos(side.float32 * 2.0 * PI / sides.float32)
)
proc polygon*(

BIN
tests/paths/polygon3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B

BIN
tests/paths/polygon4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

BIN
tests/paths/polygon5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 902 B

BIN
tests/paths/polygon6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 737 B

BIN
tests/paths/polygon7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 972 B

BIN
tests/paths/polygon8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,012 B

View file

@ -690,3 +690,12 @@ block:
mask = newMask(100, 100)
pathStr = "M0 0 L0 1 L0 0 Z"
mask.fillPath(pathStr)
block:
# Test different polygons.
for i in 3 .. 8:
let path = newPath()
path.polygon(vec2(50, 50), 30, i)
let mask = newMask(100, 100)
mask.fillPath(path)
mask.writeFile(&"tests/paths/polygon{i}.png")