From 7e6c000698ef7f9e068c14cd92d844d2f2bba4e7 Mon Sep 17 00:00:00 2001 From: 83N170 <83N170@mail.com> Date: Mon, 28 Apr 2025 22:24:59 +0100 Subject: [PATCH 1/3] Reduced diameter of star as thickness increases to remain within bounding box --- changelog.txt | 8 +++++++- internal/design/shapes.lua | 24 ++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/changelog.txt b/changelog.txt index 7a74140c5..17e016f76 100644 --- a/changelog.txt +++ b/changelog.txt @@ -16,10 +16,16 @@ Template for new versions: ## New Features -- `gui/design`: add option to draw N-point stars, hollow or filled or inverted, and change the main axis to orient in any direction +- `gui/design`: add new option to draw N-point stars. + - The default has 5 points, use 'B'/'b' to increase/decrease points. + - They can be hollow or filled, and inverted. + - 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. + - The orientation can be changed by adding a main axis point using 'v' and moving this to point in the desired direction. ## Fixes +- `gui/design`: reduced diameter of star as thickness increases to remain within bounding box + ## Misc Improvements ## Removed diff --git a/internal/design/shapes.lua b/internal/design/shapes.lua index 34e8796c4..f3209fc19 100644 --- a/internal/design/shapes.lua +++ b/internal/design/shapes.lua @@ -411,12 +411,11 @@ function LineDrawer:plot_bresenham(x0, y0, x1, y1, thickness) local sy = y0 < y1 and 1 or -1 local e2, x, y - for i = 0, thickness - 1 do + for i = -math.floor(thickness / 2), math.ceil(thickness / 2) - 1 do x = x0 y = y0 + i local err = dx - dy - local p = math.max(dx, dy) - while p >= 0 do + while true do for j = -math.floor(thickness / 2), math.ceil(thickness / 2) - 1 do if not self.arr[x + j] then self.arr[x + j] = {} end if not self.arr[x + j][y] then @@ -440,7 +439,6 @@ function LineDrawer:plot_bresenham(x0, y0, x1, y1, thickness) err = err + dx y = y + sy end - p = p - 1 end end end @@ -770,11 +768,17 @@ function Star:update(points, extra_points) self.arr = {} if #points < self.min_points then return end self.threshold = self.options.total_points.value - 2 * self.options.next_point_offset.value + + local thickness = 1 + if self.options.hollow.value then + thickness = self.options.thickness.value + end + local top_left, bot_right = self:get_point_dims() - self.height = bot_right.y - top_left.y - self.width = bot_right.x - top_left.x - if self.height == 1 or self.width == 1 then return end - self.center = { x = self.width * 0.5, y = self.height * 0.5 } + self.height = bot_right.y - top_left.y - thickness + 1 + self.width = bot_right.x - top_left.x - thickness + 1 + if self.height < 2 or self.width < 2 then return end + 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 } local axes = {} 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) 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 } end - local thickness = 1 - if self.options.hollow.value then - thickness = self.options.thickness.value - end self.lines = {} for l = 1, self.options.total_points.value do From cb1b108eaa2cf51006e3d65aae08ed50dd0fa898 Mon Sep 17 00:00:00 2001 From: 83N170 <83N170@mail.com> Date: Tue, 29 Apr 2025 21:41:31 +0100 Subject: [PATCH 2/3] Move details from changelog to docs --- changelog.txt | 8 +------- docs/gui/design.rst | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/changelog.txt b/changelog.txt index 17e016f76..7a74140c5 100644 --- a/changelog.txt +++ b/changelog.txt @@ -16,16 +16,10 @@ Template for new versions: ## New Features -- `gui/design`: add new option to draw N-point stars. - - The default has 5 points, use 'B'/'b' to increase/decrease points. - - They can be hollow or filled, and inverted. - - 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. - - The orientation can be changed by adding a main axis point using 'v' and moving this to point in the desired direction. +- `gui/design`: add option to draw N-point stars, hollow or filled or inverted, and change the main axis to orient in any direction ## Fixes -- `gui/design`: reduced diameter of star as thickness increases to remain within bounding box - ## Misc Improvements ## Removed diff --git a/docs/gui/design.rst b/docs/gui/design.rst index 2c80170da..2106c085e 100644 --- a/docs/gui/design.rst +++ b/docs/gui/design.rst @@ -17,6 +17,45 @@ Usage gui/design +Shapes +------ + +- Rectangle + - They can be hollow or filled using 'h'. + - When hollow line thickness can be increased/decreased using 'T'/'t'. + - They can be inverted using 'i'. +- Ellipse + - They can be hollow or filled using 'h'. + - When hollow line thickness can be increased/decreased using 'T'/'t'. + - They can be inverted using 'i'. +- Star + - The default has 5 points, use 'B'/'b' to increase/decrease points. + - They can be hollow or filled using 'h'. + - When hollow line thickness can be increased/decreased using 'T'/'t'. + - They can be inverted using 'i'. + - 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. + - The orientation can be changed by adding a main axis point using 'v' and + moving this to point in the desired direction. +- Rows + - Vertical rows can be toggled using 'v'. + - Horizontal rows can be toggled using 'h'. + - Spacing can be increased/decreased using 'T'/'t'. + - They can be inverted using 'i'. +- Diagonal + - Direction can be reversed using 'r'. + - Spacing can be increased/decreased using 'T'/'t'. + - They can be inverted using 'i'. +- Line + - Line thickness can be increased/decreased using 'T'/'t'. + - Can be curved by adding one or more control points using 'v'. +- FreeForm + - Can be toggled open multi-line sequence or closed polygon using 'y' + - Line thickness can be increased/decreased using 'T'/'t'. + + Overlay ------- From cf488e38979085a1caa067b3b81c066d74295bd0 Mon Sep 17 00:00:00 2001 From: 83N170 <83N170@mail.com> Date: Tue, 29 Apr 2025 21:57:30 +0100 Subject: [PATCH 3/3] Make horizontal and vertical line thickness consistent --- internal/design/shapes.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/design/shapes.lua b/internal/design/shapes.lua index f3209fc19..c6d3c9deb 100644 --- a/internal/design/shapes.lua +++ b/internal/design/shapes.lua @@ -490,7 +490,7 @@ function Line:cubic_bezier(x0, y0, x1, y1, bezier_point1, bezier_point2, thickne 0.5) local y = math.floor(((1 - t) ^ 3 * y0 + 3 * (1 - t) ^ 2 * t * y2 + 3 * (1 - t) * t ^ 2 * y3 + t ^ 3 * y1) + 0.5) - for i = 0, thickness - 1 do + for i = -math.floor(thickness / 2), math.ceil(thickness / 2) - 1 do for j = -math.floor(thickness / 2), math.ceil(thickness / 2) - 1 do if not self.arr[x + j] then self.arr[x + j] = {} end if not self.arr[x + j][y + i] then @@ -507,7 +507,7 @@ function Line:cubic_bezier(x0, y0, x1, y1, bezier_point1, bezier_point2, thickne 0.5) local y_end = math.floor(((1 - 1) ^ 3 * y0 + 3 * (1 - 1) ^ 2 * 1 * y2 + 3 * (1 - 1) * 1 ^ 2 * y3 + 1 ^ 3 * y1) + 0.5) - for i = 0, thickness - 1 do + for i = -math.floor(thickness / 2), math.ceil(thickness / 2) - 1 do for j = -math.floor(thickness / 2), math.ceil(thickness / 2) - 1 do if not self.arr[x_end + j] then self.arr[x_end + j] = {} end if not self.arr[x_end + j][y_end + i] then