Skip to content

Commit def13b7

Browse files
authored
Merge pull request #1445 from ryanbennitt/feature/design_star_thickness
Reduced diameter of star as thickness increases to fit within bounding box
2 parents ef77444 + 89ce186 commit def13b7

2 files changed

Lines changed: 52 additions & 14 deletions

File tree

docs/gui/design.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,44 @@ Usage
1717

1818
gui/design
1919

20+
Shapes
21+
------
22+
23+
- Rectangle
24+
- They can be hollow or filled using 'h'.
25+
- When hollow line thickness can be increased/decreased using 'T'/'t'.
26+
- They can be inverted using 'i'.
27+
- Ellipse
28+
- They can be hollow or filled using 'h'.
29+
- When hollow line thickness can be increased/decreased using 'T'/'t'.
30+
- They can be inverted using 'i'.
31+
- Star
32+
- The default has 5 points, use 'B'/'b' to increase/decrease points.
33+
- They can be hollow or filled using 'h'.
34+
- When hollow line thickness can be increased/decreased using 'T'/'t'.
35+
- They can be inverted using 'i'.
36+
- The next-point offset can be increased/decreased using 'N'/'n' which
37+
particularly affects 7 point stars and above to make them spikier or
38+
smoother, but can also be used to decrease to 1 to make symmetrical
39+
polygons or increase to N which only paints the vertexes.
40+
- The orientation can be changed by adding a main axis point using 'v' and
41+
moving this to point in the desired direction.
42+
- Rows
43+
- Vertical rows can be toggled using 'v'.
44+
- Horizontal rows can be toggled using 'h'.
45+
- Spacing can be increased/decreased using 'T'/'t'.
46+
- They can be inverted using 'i'.
47+
- Diagonal
48+
- Direction can be reversed using 'r'.
49+
- Spacing can be increased/decreased using 'T'/'t'.
50+
- They can be inverted using 'i'.
51+
- Line
52+
- Line thickness can be increased/decreased using 'T'/'t'.
53+
- Can be curved by adding one or more control points using 'v'.
54+
- FreeForm
55+
- Can be toggled open multi-line sequence or closed polygon using 'y'
56+
- Line thickness can be increased/decreased using 'T'/'t'.
57+
2058
Overlay
2159
-------
2260

internal/design/shapes.lua

Lines changed: 14 additions & 14 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
@@ -492,7 +490,7 @@ function Line:cubic_bezier(x0, y0, x1, y1, bezier_point1, bezier_point2, thickne
492490
0.5)
493491
local y = math.floor(((1 - t) ^ 3 * y0 + 3 * (1 - t) ^ 2 * t * y2 + 3 * (1 - t) * t ^ 2 * y3 + t ^ 3 * y1) +
494492
0.5)
495-
for i = 0, thickness - 1 do
493+
for i = -math.floor(thickness / 2), math.ceil(thickness / 2) - 1 do
496494
for j = -math.floor(thickness / 2), math.ceil(thickness / 2) - 1 do
497495
if not self.arr[x + j] then self.arr[x + j] = {} end
498496
if not self.arr[x + j][y + i] then
@@ -509,7 +507,7 @@ function Line:cubic_bezier(x0, y0, x1, y1, bezier_point1, bezier_point2, thickne
509507
0.5)
510508
local y_end = math.floor(((1 - 1) ^ 3 * y0 + 3 * (1 - 1) ^ 2 * 1 * y2 + 3 * (1 - 1) * 1 ^ 2 * y3 + 1 ^ 3 * y1) +
511509
0.5)
512-
for i = 0, thickness - 1 do
510+
for i = -math.floor(thickness / 2), math.ceil(thickness / 2) - 1 do
513511
for j = -math.floor(thickness / 2), math.ceil(thickness / 2) - 1 do
514512
if not self.arr[x_end + j] then self.arr[x_end + j] = {} end
515513
if not self.arr[x_end + j][y_end + i] then
@@ -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)