Fixed typing problems and increased coverage to 100%

This commit is contained in:
gumyr 2025-11-29 11:43:27 -05:00
parent c7034202f3
commit 0bedc9c9ad
2 changed files with 53 additions and 20 deletions

View file

@ -50,7 +50,7 @@ from build123d.build_enums import (
)
from build123d.build_line import BuildLine
from build123d.geometry import Axis, Plane, Vector, VectorLike, TOLERANCE
from build123d.topology import Edge, Face, Wire, Curve
from build123d.topology import Curve, Edge, Face, Vertex, Wire
from build123d.topology.shape_core import ShapeList
@ -851,7 +851,7 @@ class FilletPolyline(BaseLineObject):
# Create a list of vertices from wire_of_lines in the same order as
# the original points so the resulting fillet edges are ordered
ordered_vertices = []
ordered_vertices: list[Vertex] = []
for pnts in lines_pts:
distance = {
@ -867,7 +867,7 @@ class FilletPolyline(BaseLineObject):
}
# For each corner vertex create a new fillet Edge (or keep as vertex if radius is 0)
fillets = []
fillets: list[None | Edge] = []
for i, (vertex, edges) in enumerate(vertex_to_edges.items()):
if len(edges) != 2:
@ -879,7 +879,9 @@ class FilletPolyline(BaseLineObject):
fillets.append(None)
else:
other_vertices = {ve for e in edges for ve in e.vertices() if ve != vertex}
other_vertices = {
ve for e in edges for ve in e.vertices() if ve != vertex
}
third_edge = Edge.make_line(*[v for v in other_vertices])
fillet_face = Face(Wire(edges + [third_edge])).fillet_2d(
current_radius, [vertex]
@ -891,18 +893,20 @@ class FilletPolyline(BaseLineObject):
interior_edges = []
for i in range(len(fillets)):
prev_fillet = fillets[i - 1]
curr_fillet = fillets[i]
prev_idx = i - 1
curr_idx = i
# Determine start and end points
if fillets[prev_idx] is None:
start_pt = ordered_vertices[prev_idx]
if prev_fillet is None:
start_pt: Vertex | Vector = ordered_vertices[prev_idx]
else:
start_pt = fillets[prev_idx] @ 1
start_pt = prev_fillet @ 1
if fillets[curr_idx] is None:
end_pt = ordered_vertices[curr_idx]
if curr_fillet is None:
end_pt: Vertex | Vector = ordered_vertices[curr_idx]
else:
end_pt = fillets[curr_idx] @ 0
end_pt = curr_fillet @ 0
interior_edges.append(Edge.make_line(start_pt, end_pt))
end_edges = []
@ -910,18 +914,22 @@ class FilletPolyline(BaseLineObject):
else:
interior_edges = []
for i in range(len(fillets) - 1):
next_fillet = fillets[i + 1]
curr_fillet = fillets[i]
curr_idx = i
next_idx = i + 1
# Determine start and end points
if fillets[curr_idx] is None:
start_pt = ordered_vertices[curr_idx + 1] # +1 because first vertex has no fillet
if curr_fillet is None:
start_pt = ordered_vertices[
curr_idx + 1
] # +1 because first vertex has no fillet
else:
start_pt = fillets[curr_idx] @ 1
start_pt = curr_fillet @ 1
if fillets[next_idx] is None:
if next_fillet is None:
end_pt = ordered_vertices[next_idx + 1]
else:
end_pt = fillets[next_idx] @ 0
end_pt = next_fillet @ 0
interior_edges.append(Edge.make_line(start_pt, end_pt))
# Handle end edges
@ -943,7 +951,6 @@ class FilletPolyline(BaseLineObject):
super().__init__(new_wire, mode=mode)
class JernArc(BaseEdgeObject):
"""Line Object: Jern Arc

View file

@ -195,7 +195,6 @@ class BuildLineTests(unittest.TestCase):
self.assertEqual(len(p.edges().filter_by(GeomType.CIRCLE)), 3)
self.assertEqual(len(p.edges().filter_by(GeomType.LINE)), 4)
with self.assertRaises(ValueError):
p = FilletPolyline(
(0, 0),
@ -253,6 +252,33 @@ class BuildLineTests(unittest.TestCase):
with self.assertRaises(ValueError):
FilletPolyline((0, 0), (1, 0), (1, 1), radius=-1)
# test filletpolyline curr_fillet None
# Middle corner radius = 0 → curr_fillet is None
with BuildLine():
p = FilletPolyline(
(0, 0),
(10, 0),
(10, 10),
(20, 10),
radius=(0, 1), # middle corner is sharp
close=False,
)
# 1 circular fillet, 3 line fillets
assert len(p.edges().filter_by(GeomType.CIRCLE)) == 1
# test filletpolyline next_fillet None:
# Second corner is sharp (radius 0) → next_fillet is None
with BuildLine():
p = FilletPolyline(
(0, 0),
(10, 0),
(10, 10),
(0, 10),
radius=(1, 0), # next_fillet is None at last interior corner
close=False,
)
assert len(p.edges()) > 0
def test_intersecting_line(self):
with BuildLine():
l1 = Line((0, 0), (10, 0))
@ -861,9 +887,9 @@ class BuildLineTests(unittest.TestCase):
min_r = 0 if case[2][0] is None else (flip_min * case[0] + case[2][0]) / 2
max_r = 1e6 if case[2][1] is None else (flip_max * case[0] + case[2][1]) / 2
print(case[1], min_r, max_r, case[0])
print(min_r + 0.01, min_r * 0.99, max_r - 0.01, max_r + 0.01)
print((case[0] - 1 * (r1 + r2)) / 2)
# print(case[1], min_r, max_r, case[0])
# print(min_r + 0.01, min_r * 0.99, max_r - 0.01, max_r + 0.01)
# print((case[0] - 1 * (r1 + r2)) / 2)
# Greater than min
l1 = ArcArcTangentArc(start_arc, end_arc, min_r + 0.01, keep=case[1])