mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-06 02:30:55 -08:00
Refining code and adding tests
Some checks failed
benchmarks / benchmarks (macos-13, 3.12) (push) Has been cancelled
benchmarks / benchmarks (macos-14, 3.12) (push) Has been cancelled
benchmarks / benchmarks (ubuntu-latest, 3.12) (push) Has been cancelled
benchmarks / benchmarks (windows-latest, 3.12) (push) Has been cancelled
Upload coverage reports to Codecov / run (push) Has been cancelled
pylint / lint (3.10) (push) Has been cancelled
Run type checker / typecheck (3.10) (push) Has been cancelled
Run type checker / typecheck (3.13) (push) Has been cancelled
Wheel building and publishing / Build wheel on ubuntu-latest (push) Has been cancelled
tests / tests (macos-13, 3.10) (push) Has been cancelled
tests / tests (macos-13, 3.13) (push) Has been cancelled
tests / tests (macos-14, 3.10) (push) Has been cancelled
tests / tests (macos-14, 3.13) (push) Has been cancelled
tests / tests (ubuntu-latest, 3.10) (push) Has been cancelled
tests / tests (ubuntu-latest, 3.13) (push) Has been cancelled
tests / tests (windows-latest, 3.10) (push) Has been cancelled
tests / tests (windows-latest, 3.13) (push) Has been cancelled
Wheel building and publishing / upload_pypi (push) Has been cancelled
Some checks failed
benchmarks / benchmarks (macos-13, 3.12) (push) Has been cancelled
benchmarks / benchmarks (macos-14, 3.12) (push) Has been cancelled
benchmarks / benchmarks (ubuntu-latest, 3.12) (push) Has been cancelled
benchmarks / benchmarks (windows-latest, 3.12) (push) Has been cancelled
Upload coverage reports to Codecov / run (push) Has been cancelled
pylint / lint (3.10) (push) Has been cancelled
Run type checker / typecheck (3.10) (push) Has been cancelled
Run type checker / typecheck (3.13) (push) Has been cancelled
Wheel building and publishing / Build wheel on ubuntu-latest (push) Has been cancelled
tests / tests (macos-13, 3.10) (push) Has been cancelled
tests / tests (macos-13, 3.13) (push) Has been cancelled
tests / tests (macos-14, 3.10) (push) Has been cancelled
tests / tests (macos-14, 3.13) (push) Has been cancelled
tests / tests (ubuntu-latest, 3.10) (push) Has been cancelled
tests / tests (ubuntu-latest, 3.13) (push) Has been cancelled
tests / tests (windows-latest, 3.10) (push) Has been cancelled
tests / tests (windows-latest, 3.13) (push) Has been cancelled
Wheel building and publishing / upload_pypi (push) Has been cancelled
This commit is contained in:
parent
872c62c645
commit
f0f79fccd4
5 changed files with 172 additions and 207 deletions
|
|
@ -35,11 +35,12 @@ from build123d.objects_curve import (
|
|||
IntersectingLine,
|
||||
ThreePointArc,
|
||||
)
|
||||
from build123d.objects_sketch import Rectangle
|
||||
from build123d.topology import Edge, Solid, Vertex
|
||||
from build123d.geometry import Axis, Vector
|
||||
from build123d.build_enums import PositionConstraint, LengthConstraint, LengthMode
|
||||
|
||||
from build123d.topology import Edge, Solid, Vertex, Wire, topo_explore_common_vertex
|
||||
from build123d.geometry import Axis, Vector, TOLERANCE
|
||||
from build123d.build_enums import Tangency, Sagitta, LengthMode
|
||||
from OCP.BRep import BRep_Tool
|
||||
from OCP.GeomAbs import GeomAbs_C1
|
||||
from OCP.LocalAnalysis import LocalAnalysis_CurveContinuity
|
||||
|
||||
radius = 0.5
|
||||
e1 = Line((-2, 0), (2, 0))
|
||||
|
|
@ -51,13 +52,13 @@ e1.color = "Grey"
|
|||
e2.color = "Red"
|
||||
|
||||
|
||||
def test_constrained_arcs_0():
|
||||
def test_constrained_arcs_arg_processing():
|
||||
"""Test input error handling"""
|
||||
with pytest.raises(TypeError):
|
||||
Edge.make_constrained_arcs(Solid.make_box(1, 1, 1), (1, 0), radius=0.5)
|
||||
with pytest.raises(TypeError):
|
||||
Edge.make_constrained_arcs(
|
||||
(Vector(0, 0), PositionConstraint.UNQUALIFIED), (1, 0), radius=0.5
|
||||
(Vector(0, 0), Tangency.UNQUALIFIED), (1, 0), radius=0.5
|
||||
)
|
||||
with pytest.raises(TypeError):
|
||||
Edge.make_constrained_arcs(pnt1=(1, 1, 1), pnt2=(1, 0), radius=0.5)
|
||||
|
|
@ -69,24 +70,26 @@ def test_constrained_arcs_0():
|
|||
Edge.make_constrained_arcs((0, 0), (0, 0.5), radius=-0.5)
|
||||
|
||||
|
||||
def test_constrained_arcs_1():
|
||||
def test_tan2_rad_arcs_1():
|
||||
"""2 edges & radius"""
|
||||
e1 = Line((-2, 0), (2, 0))
|
||||
e2 = Line((0, -2), (0, 2))
|
||||
|
||||
tan2_rad_edges = Edge.make_constrained_arcs(
|
||||
e1,
|
||||
e2,
|
||||
radius=0.5,
|
||||
sagitta_constraint=LengthConstraint.BOTH,
|
||||
e1, e2, radius=0.5, sagitta=Sagitta.BOTH
|
||||
)
|
||||
assert len(tan2_rad_edges) == 8
|
||||
|
||||
tan2_rad_edges = Edge.make_constrained_arcs(e1, e2, radius=0.5)
|
||||
assert len(tan2_rad_edges) == 4
|
||||
|
||||
tan2_rad_edges = Edge.make_constrained_arcs(
|
||||
(e1, Tangency.UNQUALIFIED), (e2, Tangency.UNQUALIFIED), radius=0.5
|
||||
)
|
||||
assert len(tan2_rad_edges) == 4
|
||||
|
||||
def test_constrained_arcs_2():
|
||||
|
||||
def test_tan2_rad_arcs_2():
|
||||
"""2 edges & radius"""
|
||||
e1 = CenterArc((0, 0), 1, 0, 90)
|
||||
e2 = Line((1, 0), (2, 0))
|
||||
|
|
@ -95,7 +98,7 @@ def test_constrained_arcs_2():
|
|||
assert len(tan2_rad_edges) == 1
|
||||
|
||||
|
||||
def test_constrained_arcs_3():
|
||||
def test_tan2_rad_arcs_3():
|
||||
"""2 points & radius"""
|
||||
tan2_rad_edges = Edge.make_constrained_arcs((0, 0), (0, 0.5), radius=0.5)
|
||||
assert len(tan2_rad_edges) == 2
|
||||
|
|
@ -111,129 +114,98 @@ def test_constrained_arcs_3():
|
|||
assert len(tan2_rad_edges) == 2
|
||||
|
||||
|
||||
# tan2_rad_edges = Edge.make_constrained_arcs(
|
||||
# (e1, PositionConstraint.OUTSIDE),
|
||||
# (e2, PositionConstraint.UNQUALIFIED),
|
||||
# radius=radius,
|
||||
# sagitta_constraint=LengthConstraint.SHORT,
|
||||
# )
|
||||
def test_tan2_center_on_1():
|
||||
"""2 tangents & center on"""
|
||||
c1 = PolarLine((0, 0), 4, -20, length_mode=LengthMode.HORIZONTAL)
|
||||
c2 = Line((4, -2), (4, 2))
|
||||
c3_center_on = Line((3, -2), (3, 2))
|
||||
tan2_on_edge = Edge.make_constrained_arcs(
|
||||
(c1, Tangency.UNQUALIFIED),
|
||||
(c2, Tangency.UNQUALIFIED),
|
||||
center_on=c3_center_on,
|
||||
)
|
||||
assert len(tan2_on_edge) == 1
|
||||
|
||||
|
||||
# # 2 lines & radius
|
||||
|
||||
# # 2 points & radius
|
||||
# p1 = Vector(0, 0, 0)
|
||||
# p2 = Vector(3, 0, 0)
|
||||
# tan2_rad_pnts = Edge().make_constrained_arcs(p1, p2, radius=3)
|
||||
|
||||
# #
|
||||
# # 2 tangents & center on
|
||||
# c1 = PolarLine((0, 0), 4, -20, length_mode=LengthMode.HORIZONTAL)
|
||||
# c2 = Line((4, -2), (4, 2))
|
||||
# c3_center_on_this_line = Line((3, -2), (3, 2))
|
||||
# c4 = Line((0, 0), (0, 10))
|
||||
# for c in (c1, c2, c3_center_on_this_line, c4):
|
||||
# c.color = "LightGrey"
|
||||
# tan2_on_edge = Edge.make_constrained_arcs(
|
||||
# (c1, PositionConstraint.UNQUALIFIED),
|
||||
# (c2, PositionConstraint.UNQUALIFIED),
|
||||
# center_on=c3_center_on_this_line,
|
||||
# )[0]
|
||||
# l1 = Line(tan2_on_edge @ 0, (0, 0))
|
||||
# l2 = JernArc(tan2_on_edge @ 1, tan2_on_edge % 1, tan2_on_edge.radius, 45)
|
||||
# l3 = IntersectingLine(l2 @ 1, l2 % 1, c4)
|
||||
|
||||
# #
|
||||
# # tangent & center
|
||||
# c5 = PolarLine((0, 0), 4, 60)
|
||||
# center1 = Vector(2, 1)
|
||||
# tan_center = Edge.make_constrained_arcs(
|
||||
# (c5, PositionConstraint.UNQUALIFIED), center=center1
|
||||
# )
|
||||
# #
|
||||
# # point & center
|
||||
# p3 = Vector(-2.5, 1.5)
|
||||
# center2 = Vector(-2, 1)
|
||||
# pnt_center = Edge.make_constrained_arcs(p3, center=center2)
|
||||
|
||||
# #
|
||||
# # tangent, radius, center on
|
||||
# # tan_rad_on = Edge.make_constrained_arcs(
|
||||
# # (c1, PositionConstraint.UNQUALIFIED), radius=1, center_on=c3_center_on_this_line
|
||||
# # )
|
||||
# tan_rad_on = Edge.make_constrained_arcs(c1, radius=1, center_on=c3_center_on_this_line)
|
||||
|
||||
# print(f"{len(tan_rad_on)=}")
|
||||
|
||||
# objects = [
|
||||
# (c1, PositionConstraint.ENCLOSED),
|
||||
# (Vector(1, 2, 3), None),
|
||||
# (Edge.make_line((0, 0), (1, 0)), PositionConstraint.UNQUALIFIED),
|
||||
# ]
|
||||
# s = sorted(objects, key=lambda t: not issubclass(type(t[0]), Edge))
|
||||
# print(f"{objects=},{s=}")
|
||||
# #
|
||||
# # 3 tangents
|
||||
# c6 = PolarLine((0, 0), 4, 40)
|
||||
# c7 = CenterArc((0, 0), 4, 0, 90)
|
||||
# tan3 = Edge.make_constrained_arcs(
|
||||
# (c5, PositionConstraint.UNQUALIFIED),
|
||||
# (c6, PositionConstraint.UNQUALIFIED),
|
||||
# (c7, PositionConstraint.UNQUALIFIED),
|
||||
# )
|
||||
# tan3 = Edge.make_constrained_arcs(c5, c6, c7)
|
||||
|
||||
# # v = Vertex(1, 2, 0)
|
||||
# # v.color = "Teal"
|
||||
# # show(e1, e2, tan2_rad, v)
|
||||
|
||||
# r_left, r_right = 0.75, 1.0
|
||||
# r_bottom, r_top = 6, 8
|
||||
# con_circle_left = CenterArc((-2, 0), r_left, 0, 360)
|
||||
# con_circle_right = CenterArc((2, 0), r_right, 0, 360)
|
||||
# for c in [con_circle_left, con_circle_right]:
|
||||
# c.color = "LightGrey"
|
||||
# # for con1, con2 in itertools.product(PositionConstraint, PositionConstraint):
|
||||
# # try:
|
||||
# # egg1 = Edge.make_constrained_arcs(
|
||||
# # (c8, con1),
|
||||
# # (c9, con2),
|
||||
# # radius=10,
|
||||
# # )
|
||||
# # except:
|
||||
# # print(f"{con1},{con2} failed")
|
||||
# # else:
|
||||
# # print(f"{con1},{con2} {len(egg1)=}")
|
||||
# egg_bottom = Edge.make_constrained_arcs(
|
||||
# (con_circle_right, PositionConstraint.OUTSIDE),
|
||||
# (con_circle_left, PositionConstraint.OUTSIDE),
|
||||
# radius=r_bottom,
|
||||
# ).sort_by(Axis.Y)[0]
|
||||
# egg_top = Edge.make_constrained_arcs(
|
||||
# (con_circle_right, PositionConstraint.ENCLOSING),
|
||||
# (con_circle_left, PositionConstraint.ENCLOSING),
|
||||
# radius=r_top,
|
||||
# ).sort_by(Axis.Y)[-1]
|
||||
# egg_right = ThreePointArc(
|
||||
# egg_bottom.vertices().sort_by(Axis.X)[-1],
|
||||
# con_circle_right @ 0,
|
||||
# egg_top.vertices().sort_by(Axis.X)[-1],
|
||||
# )
|
||||
# egg_left = ThreePointArc(
|
||||
# egg_bottom.vertices().sort_by(Axis.X)[0],
|
||||
# con_circle_left @ 0.5,
|
||||
# egg_top.vertices().sort_by(Axis.X)[0],
|
||||
# )
|
||||
|
||||
# egg_plant = Wire([egg_left, egg_top, egg_right, egg_bottom])
|
||||
def test_tan_center_on_1():
|
||||
"""1 tangent & center on"""
|
||||
c5 = PolarLine((0, 0), 4, 60)
|
||||
tan_center = Edge.make_constrained_arcs((c5, Tangency.UNQUALIFIED), center=(2, 1))
|
||||
assert len(tan_center) == 1
|
||||
assert tan_center[0].is_closed
|
||||
|
||||
|
||||
# make_constrained_arcs
|
||||
def test_pnt_center_1():
|
||||
"""pnt & center"""
|
||||
pnt_center = Edge.make_constrained_arcs((-2.5, 1.5), center=(-2, 1))
|
||||
assert len(pnt_center) == 1
|
||||
assert pnt_center[0].is_closed
|
||||
|
||||
|
||||
# class TestConstrainedArcs(unittest.TestCase):
|
||||
# def test_close(self):
|
||||
# self.assertAlmostEqual(
|
||||
# Edge.make_circle(1, end_angle=180).close().length, math.pi + 2, 5
|
||||
# )
|
||||
# self.assertAlmostEqual(Edge.make_circle(1).close().length, 2 * math.pi, 5)
|
||||
def test_tan_rad_center_on_1():
|
||||
"""tangent, radius, center on"""
|
||||
c1 = PolarLine((0, 0), 4, -20, length_mode=LengthMode.HORIZONTAL)
|
||||
c3_center_on = Line((3, -2), (3, 2))
|
||||
tan_rad_on = Edge.make_constrained_arcs(
|
||||
(c1, Tangency.UNQUALIFIED), radius=1, center_on=c3_center_on
|
||||
)
|
||||
assert len(tan_rad_on) == 1
|
||||
assert tan_rad_on[0].is_closed
|
||||
|
||||
|
||||
def test_tan3_1():
|
||||
"""3 tangents"""
|
||||
c5 = PolarLine((0, 0), 4, 60)
|
||||
c6 = PolarLine((0, 0), 4, 40)
|
||||
c7 = CenterArc((0, 0), 4, 0, 90)
|
||||
tan3 = Edge.make_constrained_arcs(
|
||||
(c5, Tangency.UNQUALIFIED),
|
||||
(c6, Tangency.UNQUALIFIED),
|
||||
(c7, Tangency.UNQUALIFIED),
|
||||
)
|
||||
assert len(tan3) == 1
|
||||
assert not tan3[0].is_closed
|
||||
|
||||
|
||||
def test_eggplant():
|
||||
"""complex set of 4 arcs"""
|
||||
r_left, r_right = 0.75, 1.0
|
||||
r_bottom, r_top = 6, 8
|
||||
con_circle_left = CenterArc((-2, 0), r_left, 0, 360)
|
||||
con_circle_right = CenterArc((2, 0), r_right, 0, 360)
|
||||
egg_bottom = Edge.make_constrained_arcs(
|
||||
(con_circle_right, Tangency.OUTSIDE),
|
||||
(con_circle_left, Tangency.OUTSIDE),
|
||||
radius=r_bottom,
|
||||
).sort_by(Axis.Y)[0]
|
||||
egg_top = Edge.make_constrained_arcs(
|
||||
(con_circle_right, Tangency.ENCLOSING),
|
||||
(con_circle_left, Tangency.ENCLOSING),
|
||||
radius=r_top,
|
||||
).sort_by(Axis.Y)[-1]
|
||||
egg_right = ThreePointArc(
|
||||
egg_bottom.vertices().sort_by(Axis.X)[-1],
|
||||
con_circle_right @ 0,
|
||||
egg_top.vertices().sort_by(Axis.X)[-1],
|
||||
)
|
||||
egg_left = ThreePointArc(
|
||||
egg_bottom.vertices().sort_by(Axis.X)[0],
|
||||
con_circle_left @ 0.5,
|
||||
egg_top.vertices().sort_by(Axis.X)[0],
|
||||
)
|
||||
|
||||
egg_plant = Wire([egg_left, egg_top, egg_right, egg_bottom])
|
||||
assert egg_plant.is_closed
|
||||
egg_plant_edges = egg_plant.edges().sort_by(egg_plant)
|
||||
common_vertex_cnt = sum(
|
||||
topo_explore_common_vertex(egg_plant_edges[i], egg_plant_edges[(i + 1) % 4])
|
||||
is not None
|
||||
for i in range(4)
|
||||
)
|
||||
assert common_vertex_cnt == 4
|
||||
|
||||
# C1 continuity
|
||||
assert all(
|
||||
(egg_plant_edges[i] % 1 - egg_plant_edges[(i + 1) % 4] % 0).length < TOLERANCE
|
||||
for i in range(4)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue