Fix segment small offset with thickness
This commit is contained in:
@@ -140,8 +140,9 @@ class Polyline:
|
||||
|
||||
# Get segments between arcs
|
||||
for i in range(2, self.length_polyline - 1):
|
||||
self.segments[i] = Segment2D(Point2D(self.acrs_intersections[i][0].x, self.acrs_intersections[i][0].y), Point2D(
|
||||
self.acrs_intersections[i-1][-1].x, self.acrs_intersections[i-1][-1].y))
|
||||
self.segments[i] = Segment2D(Point2D(
|
||||
self.acrs_intersections[i-1][2].x, self.acrs_intersections[i-1][2].y), Point2D(self.acrs_intersections[i][0].x, self.acrs_intersections[i][0].y))
|
||||
print(self.segments[i], i)
|
||||
|
||||
# Why -3?
|
||||
# For n points, there are n-1 segments.
|
||||
@@ -162,7 +163,8 @@ class Polyline:
|
||||
alpha_b = min(
|
||||
self.lengths[start_index] - self.alpha_radii[start_index], self.lengths[start_index + 1])
|
||||
current_radius = max(self.tangente[start_index] * self.alpha_radii[start_index],
|
||||
self.tangente[start_index + 1] * alpha_b) # Radius at initial segment
|
||||
# Radius at initial segment
|
||||
self.tangente[start_index + 1] * alpha_b)
|
||||
|
||||
if current_radius < minimum_radius:
|
||||
minimum_radius, minimum_index = current_radius, start_index
|
||||
@@ -180,7 +182,8 @@ class Polyline:
|
||||
self.lengths[end_index-2], self.lengths[end_index-1]-self.alpha_radii[end_index])
|
||||
|
||||
current_radius = max(self.tangente[end_index-1]*alpha_a, self.tangente[end_index]
|
||||
* self.alpha_radii[end_index]) # Radius at final segment
|
||||
# Radius at final segment
|
||||
* self.alpha_radii[end_index])
|
||||
|
||||
if current_radius < minimum_radius:
|
||||
minimum_radius, minimum_index = current_radius, end_index - 1
|
||||
|
||||
@@ -21,7 +21,7 @@ class Segment2D:
|
||||
def __repr__(self):
|
||||
return str(f"Segment2D(start: {self.start}, end: {self.end}, points: {self.points})")
|
||||
|
||||
def segment(self, start: Point2D = None, end: Point2D = None, overlap: LINE_OVERLAP = LINE_OVERLAP.NONE, _is_computing_thickness: int = 0) -> Union[List[Point2D], None]:
|
||||
def segment(self, start: Point2D = None, end: Point2D = None, overlap: LINE_OVERLAP = LINE_OVERLAP.NONE, _is_computing_thickness: int = -1) -> Union[List[Point2D], None]:
|
||||
"""Modified Bresenham draw (line) with optional overlap.
|
||||
|
||||
From: https://github.com/ArminJo/Arduino-BlueDisplay/blob/master/src/LocalGUI/ThickLine.hpp
|
||||
@@ -98,7 +98,7 @@ class Segment2D:
|
||||
self._add_points(
|
||||
start, _is_computing_thickness, LINE_OVERLAP.NONE)
|
||||
|
||||
if not _is_computing_thickness:
|
||||
if _is_computing_thickness < 0:
|
||||
return self.points
|
||||
return None
|
||||
|
||||
@@ -166,7 +166,7 @@ class Segment2D:
|
||||
start.y -= step_y
|
||||
end.y -= step_y
|
||||
error -= delta_2x
|
||||
error += delta_2x
|
||||
error += delta_2y
|
||||
|
||||
if not swap:
|
||||
self.segment(
|
||||
@@ -240,6 +240,16 @@ class Segment2D:
|
||||
|
||||
reel_distance = self.points_thick_by_line[0][0].distance(
|
||||
self.points_thick_by_line[-1][0])
|
||||
delta_correction = round(reel_distance - thickness)
|
||||
if delta_correction > 0:
|
||||
for i in range(delta_correction):
|
||||
if (-1) ** i == 1:
|
||||
index = -1
|
||||
else:
|
||||
index = 0
|
||||
print(i)
|
||||
del self.points_thick_by_line[index]
|
||||
del self.gaps[index]
|
||||
|
||||
return self.points_thick
|
||||
|
||||
|
||||
Reference in New Issue
Block a user