Skip to content

Commit

Permalink
🐛 Patch for tolerance of faces
Browse files Browse the repository at this point in the history
  • Loading branch information
je-cook committed Nov 18, 2024
1 parent 3899524 commit 4cad6e3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
13 changes: 7 additions & 6 deletions bluemira/codes/_freecadapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def offset_wire(
])
raise FreeCADError(msg) from None

fix_wire(wire)
fix_shape(wire)
if not wire.isClosed() and not open_wire:
raise FreeCADError("offset failed to close wire")
return wire
Expand Down Expand Up @@ -1537,6 +1537,7 @@ def import_cad(
if len(objs) > 0:
return [(scale_shape(obj.copy(), scale), lab) for obj, lab in objs]
bluemira_warn("No objects found in import")

Check warning on line 1539 in bluemira/codes/_freecadapi.py

View check run for this annotation

Codecov / codecov/patch

bluemira/codes/_freecadapi.py#L1539

Added line #L1539 was not covered by tests

if filetype not in CADFileType.unitless_formats():
return [(scale_shape(obj.copy(), scale), lab) for obj, lab in objs]
return objs

Check warning on line 1543 in bluemira/codes/_freecadapi.py

View check run for this annotation

Codecov / codecov/patch

bluemira/codes/_freecadapi.py#L1543

Added line #L1543 was not covered by tests
Expand Down Expand Up @@ -2331,22 +2332,22 @@ def _make_shapes_coaxis(shapes):
# ======================================================================================


def fix_wire(
wire: apiWire, precision: float = EPS_FREECAD, min_length: float = MINIMUM_LENGTH
def fix_shape(
shape: apiShape, precision: float = EPS_FREECAD, min_length: float = MINIMUM_LENGTH
):
"""
Fix a wire by removing any small edges and joining the remaining edges.
Fix a shape by removing any small edges and joining the remaining edges.
Parameters
----------
wire:
shape:
Wire to fix
precision:
General precision with which to work
min_length:
Minimum edge length
"""
wire.fix(precision, min_length, min_length)
shape.fix(precision, min_length, min_length)


# ======================================================================================
Expand Down
3 changes: 3 additions & 0 deletions bluemira/geometry/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def _create_face(self, *, check_reverse: bool = True):
else:
raise DisjointedFaceError("Any or more than one face has been created.")

if not cadapi.is_valid(face):
cadapi.fix_shape(face)

if check_reverse:
return self._check_reverse(face)
return face
Expand Down
4 changes: 4 additions & 0 deletions bluemira/geometry/wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def _create_shape(self) -> cadapi.apiWire:

def _create_wire(self, *, check_reverse: bool = True):
wire = cadapi.apiWire(self._get_wires())

if not cadapi.is_valid(wire):
cadapi.fix_shape(wire)

Check warning on line 88 in bluemira/geometry/wire.py

View check run for this annotation

Codecov / codecov/patch

bluemira/geometry/wire.py#L88

Added line #L88 was not covered by tests

if check_reverse:
return self._check_reverse(wire)
return wire
Expand Down

0 comments on commit 4cad6e3

Please sign in to comment.