Implemented review feedback - fixed mypy on shape_core.py & utils.py

This commit is contained in:
gumyr 2024-12-20 14:31:42 -05:00
parent 5b88e87bad
commit 217b70aa1e
7 changed files with 607 additions and 389 deletions

View file

@ -1,7 +1,9 @@
# Global options:
[mypy]
no_implicit_optional=False
[mypy-OCP.*]
ignore_missing_imports = True
[mypy-anytree.*]
ignore_missing_imports = True
@ -12,3 +14,11 @@ ignore_missing_imports = True
[mypy-vtkmodules.*]
ignore_missing_imports = True
[mypy-build123d.topology.jupyter_tools.*]
ignore_missing_imports = True
[mypy-IPython.lib.pretty.*]
ignore_missing_imports = True
[mypy-svgpathtools.*]
ignore_missing_imports = True

View file

@ -53,6 +53,7 @@ from OCP.HLRAlgo import HLRAlgo_Projector # type: ignore
from OCP.HLRBRep import HLRBRep_Algo, HLRBRep_HLRToShape # type: ignore
from OCP.TopAbs import TopAbs_Orientation, TopAbs_ShapeEnum # type: ignore
from OCP.TopExp import TopExp_Explorer # type: ignore
from OCP.TopoDS import TopoDS
from typing_extensions import Self
from build123d.build_enums import Unit, GeomType
@ -1060,7 +1061,7 @@ class ExportSVG(Export2D):
)
while explorer.More():
topo_wire = explorer.Current()
loose_wires.append(Wire(topo_wire))
loose_wires.append(Wire(TopoDS.Wire_s(topo_wire)))
explorer.Next()
# print(f"{len(loose_wires)} loose wires")
for wire in loose_wires:
@ -1097,12 +1098,13 @@ class ExportSVG(Export2D):
@staticmethod
def _wire_edges(wire: Wire, reverse: bool) -> List[Edge]:
edges = []
explorer = BRepTools_WireExplorer(wire.wrapped)
while explorer.More():
topo_edge = explorer.Current()
edges.append(Edge(topo_edge))
explorer.Next()
# edges = []
# explorer = BRepTools_WireExplorer(wire.wrapped)
# while explorer.More():
# topo_edge = explorer.Current()
# edges.append(Edge(topo_edge))
# explorer.Next()
edges = wire.edges()
if reverse:
edges.reverse()
return edges

View file

@ -542,7 +542,7 @@ class Vector:
#:TypeVar("VectorLike"): Tuple of float or Vector defining a position in space
VectorLike = Union[
Vector, tuple[float, float], tuple[float, float, float], Iterable[float]
Vector, tuple[float, float], tuple[float, float, float], Sequence[float]
]

File diff suppressed because it is too large Load diff

View file

@ -3211,10 +3211,6 @@ class TestShape(DirectApiTestCase):
self.assertVectorAlmostEquals(box.position, (1, 2, 3), 5)
self.assertVectorAlmostEquals(box.orientation, (10, 20, 30), 5)
def test_copy(self):
with self.assertWarns(DeprecationWarning):
Solid.make_box(1, 1, 1).copy()
def test_distance_to_with_closest_points(self):
s0 = Solid.make_sphere(1).locate(Location((0, 2.1, 0)))
s1 = Solid.make_sphere(1)

View file

@ -32,6 +32,8 @@ from build123d import (
)
from build123d.exporters import ExportSVG, ExportDXF, Drawing, LineType
from ocp_vscode import show
class ExportersTestCase(unittest.TestCase):
@staticmethod

View file

@ -87,9 +87,6 @@ Key Features:
- `_topods_bool_op`: Generic Boolean operations for TopoDS_Shapes.
- `new_edges`: Identifies newly created edges from combined shapes.
- **Utility Classes**:
- `_ClassMethodProxy`: Dynamically binds methods across classes.
- **Enhanced Math**:
- `isclose_b`: Overrides `math.isclose` with a stricter absolute tolerance.
@ -354,7 +351,7 @@ def write_topo_class_files(
"get_top_level_topods_shapes",
"_sew_topods_faces",
"shapetype",
"_topods_compound_dim",
"topods_dim",
"_topods_entities",
"_topods_face_normal_at",
"apply_ocp_monkey_patches",
@ -386,7 +383,6 @@ def write_topo_class_files(
# Define class groupings based on layers
class_groups = {
"utils": ["_ClassMethodProxy"],
"shape_core": [
"Shape",
"Comparable",
@ -456,7 +452,6 @@ license:
additional_imports.append(
"from .shape_core import Shape, ShapeList, BoundBox, SkipClean, TrimmingTool, Joint"
)
additional_imports.append("from .utils import _ClassMethodProxy")
if group_name not in ["shape_core", "vertex"]:
for sub_group_name in function_source.keys():
additional_imports.append(
@ -508,26 +503,6 @@ license:
# if group_name in ["shape_core", "utils"]:
if group_name in function_source.keys():
body = [*cst.parse_module(all_imports_code).body]
for func in function_collector.functions:
if group_name == "shape_core" and func.name.value in [
"_topods_compound_dim",
"_topods_face_normal_at",
"apply_ocp_monkey_patches",
]:
body.append(func)
# If this is the "apply_ocp_monkey_patches" function, add a call to it
if (
group_name == "shape_core"
and func.name.value == "apply_ocp_monkey_patches"
):
apply_patches_call = cst.Expr(
value=cst.Call(func=cst.Name("apply_ocp_monkey_patches"))
)
body.append(apply_patches_call)
body.append(cst.EmptyLine(indent=False))
body.append(cst.EmptyLine(indent=False))
if group_name == "shape_core":
for var in variable_collector.global_variables:
# Check the name of the assigned variable(s)
@ -562,13 +537,7 @@ license:
body.append(cst.EmptyLine(indent=False))
for func in function_collector.functions:
if func.name.value in function_source[
group_name
] and func.name.value not in [
"_topods_compound_dim",
"_topods_face_normal_at",
"apply_ocp_monkey_patches",
]:
if func.name.value in function_source[group_name]:
body.append(func)
class_module = cst.Module(body=body, header=header)
else:
@ -756,7 +725,6 @@ def main():
# Define classes to extract
class_names = [
"_ClassMethodProxy",
"BoundBox",
"Shape",
"Compound",