Skip to content

Commit 7e6c000

Browse files
83N17083N170
authored andcommitted
Reduced diameter of star as thickness increases to remain within bounding box
1 parent fdd597e commit 7e6c000

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

changelog.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ Template for new versions:
1616

1717
## New Features
1818

19-
- `gui/design`: add option to draw N-point stars, hollow or filled or inverted, and change the main axis to orient in any direction
19+
- `gui/design`: add new option to draw N-point stars.
20+
- The default has 5 points, use 'B'/'b' to increase/decrease points.
21+
- They can be hollow or filled, and inverted.
22+
- The next-point offset can be increased/decreased using 'N'/'n' which particularly affects 7 point stars and above to make them spikier or smoother, but can also be used to decrease to 1 to make symmetrical polygons or increase to N which only paints the vertexes.
23+
- The orientation can be changed by adding a main axis point using 'v' and moving this to point in the desired direction.
2024

2125
## Fixes
2226

27+
- `gui/design`: reduced diameter of star as thickness increases to remain within bounding box
28+
2329
## Misc Improvements
2430

2531
## Removed

internal/design/shapes.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,11 @@ function LineDrawer:plot_bresenham(x0, y0, x1, y1, thickness)
411411
local sy = y0 < y1 and 1 or -1
412412
local e2, x, y
413413

414-
for i = 0, thickness - 1 do
414+
for i = -math.floor(thickness / 2), math.ceil(thickness / 2) - 1 do
415415
x = x0
416416
y = y0 + i
417417
local err = dx - dy
418-
local p = math.max(dx, dy)
419-
while p >= 0 do
418+
while true do
420419
for j = -math.floor(thickness / 2), math.ceil(thickness / 2) - 1 do
421420
if not self.arr[x + j] then self.arr[x + j] = {} end
422421
if not self.arr[x + j][y] then
@@ -440,7 +439,6 @@ function LineDrawer:plot_bresenham(x0, y0, x1, y1, thickness)
440439
err = err + dx
441440
y = y + sy
442441
end
443-
p = p - 1
444442
end
445443
end
446444
end
@@ -770,11 +768,17 @@ function Star:update(points, extra_points)
770768
self.arr = {}
771769
if #points < self.min_points then return end
772770
self.threshold = self.options.total_points.value - 2 * self.options.next_point_offset.value
771+
772+
local thickness = 1
773+
if self.options.hollow.value then
774+
thickness = self.options.thickness.value
775+
end
776+
773777
local top_left, bot_right = self:get_point_dims()
774-
self.height = bot_right.y - top_left.y
775-
self.width = bot_right.x - top_left.x
776-
if self.height == 1 or self.width == 1 then return end
777-
self.center = { x = self.width * 0.5, y = self.height * 0.5 }
778+
self.height = bot_right.y - top_left.y - thickness + 1
779+
self.width = bot_right.x - top_left.x - thickness + 1
780+
if self.height < 2 or self.width < 2 then return end
781+
self.center = { x = (bot_right.x - top_left.x + ((thickness - 1) % 2)) * 0.5, y = (bot_right.y - top_left.y + ((thickness - 1) % 2)) * 0.5 }
778782
local axes = {}
779783

780784
axes[1] = (#extra_points > 0) and { x = extra_points[1].x - self.center.x - top_left.x, y = extra_points[1].y - self.center.y - top_left.y } or { x = 0, y = -self.center.y }
@@ -786,10 +790,6 @@ function Star:update(points, extra_points)
786790
axes[a] = { x = math.cos(angle) * axes[1].x - math.sin(angle) * axes[1].y, y = math.sin(angle) * axes[1].x + math.cos(angle) * axes[1].y }
787791
end
788792

789-
local thickness = 1
790-
if self.options.hollow.value then
791-
thickness = self.options.thickness.value
792-
end
793793

794794
self.lines = {}
795795
for l = 1, self.options.total_points.value do

0 commit comments

Comments
 (0)