Skip to content

Reduced diameter of star as thickness increases to fit within bounding box #1445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/gui/design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Expand Down
28 changes: 14 additions & 14 deletions internal/design/shapes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -492,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
Expand All @@ -509,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
Expand Down Expand Up @@ -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 }
Expand All @@ -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
Expand Down
Loading