@@ -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
446444end
@@ -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