Offset or thicken faces or shells.
(
s: Shape,
t: float,
cap: bool = True,
both: bool = False,
tol: float = 1e-6,
history: History | None = None,
name: str | None = None,
)
| 6967 | |
| 6968 | |
| 6969 | def offset( |
| 6970 | s: Shape, |
| 6971 | t: float, |
| 6972 | cap: bool = True, |
| 6973 | both: bool = False, |
| 6974 | tol: float = 1e-6, |
| 6975 | history: History | None = None, |
| 6976 | name: str | None = None, |
| 6977 | ) -> Shape: |
| 6978 | """ |
| 6979 | Offset or thicken faces or shells. |
| 6980 | """ |
| 6981 | |
| 6982 | def _offset(t: float): |
| 6983 | |
| 6984 | results = [] |
| 6985 | builders = [] |
| 6986 | |
| 6987 | for el in _get(s, ("Face", "Shell")): |
| 6988 | |
| 6989 | builder = BRepOffset_MakeOffset() |
| 6990 | builders.append(builder) |
| 6991 | |
| 6992 | builder.Initialize( |
| 6993 | el.wrapped, |
| 6994 | t, |
| 6995 | tol, |
| 6996 | BRepOffset_Mode.BRepOffset_Skin, |
| 6997 | False, |
| 6998 | False, |
| 6999 | GeomAbs_Intersection, |
| 7000 | cap, |
| 7001 | ) |
| 7002 | |
| 7003 | builder.MakeOffsetShape() |
| 7004 | |
| 7005 | results.append(builder.Shape()) |
| 7006 | |
| 7007 | return results, builders |
| 7008 | |
| 7009 | if both: |
| 7010 | results_pos, builders1 = _offset(t) |
| 7011 | results_neg, builders2 = _offset(-t) |
| 7012 | |
| 7013 | results_both = [ |
| 7014 | Shape(el1) + Shape(el2) for el1, el2 in zip(results_pos, results_neg) |
| 7015 | ] |
| 7016 | |
| 7017 | _update_history(history, name, [s], *builders1, *builders2) |
| 7018 | _update_removed(history, s.Faces()) |
| 7019 | |
| 7020 | if len(results_both) == 1: |
| 7021 | rv = results_both[0] |
| 7022 | else: |
| 7023 | rv = Compound.makeCompound(results_both) |
| 7024 | |
| 7025 | else: |
| 7026 | results, builders = _offset(t) |