MCPcopy
hub / github.com/CadQuery/cadquery / offset2D

Function offset2D

cadquery/occ_impl/shapes.py:7034–7073  ·  view source on GitHub ↗

2D offset edges or wires. ctx face might be needed for ambiguous wires/edges. Only works with planar geometries.

(
    s: Shape,
    t: float,
    ctx: Shape | None = None,
    kind: Literal["arc", "intersection", "tangent"] = "arc",
    closed: bool = True,
)

Source from the content-addressed store, hash-verified

7032
7033
7034def offset2D(
7035 s: Shape,
7036 t: float,
7037 ctx: Shape | None = None,
7038 kind: Literal["arc", "intersection", "tangent"] = "arc",
7039 closed: bool = True,
7040) -> Shape:
7041 """
7042 2D offset edges or wires. ctx face might be needed for ambiguous wires/edges.
7043 Only works with planar geometries.
7044 """
7045
7046 kind_dict = {
7047 "arc": GeomAbs_JoinType.GeomAbs_Arc,
7048 "intersection": GeomAbs_JoinType.GeomAbs_Intersection,
7049 "tangent": GeomAbs_JoinType.GeomAbs_Tangent,
7050 }
7051
7052 if ctx:
7053 # build a dummy face based on the geometry of the ctx face.
7054 fbldr = BRepBuilderAPI_MakeFace(_get_one(ctx, "Face")._geomAdaptor(), 1e-6)
7055
7056 for el in _get_wires(s):
7057 fbldr.Add(el.wrapped)
7058
7059 fbldr.Build()
7060
7061 bldr = BRepOffsetAPI_MakeOffset(fbldr.Face(), kind_dict[kind], not closed)
7062
7063 else:
7064 # simple case - input wire defines a plane
7065 bldr = BRepOffsetAPI_MakeOffset()
7066 bldr.Init(kind_dict[kind], not closed)
7067
7068 for el in _get_wires(s):
7069 bldr.AddWire(el.wrapped)
7070
7071 bldr.Perform(t)
7072
7073 return _compound_or_shape(bldr.Shape())
7074
7075
7076def chamfer2D(s: Shape, verts: Shape, d: float) -> Shape:

Callers 1

test_offset2DFunction · 0.85

Calls 4

_get_oneFunction · 0.85
_get_wiresFunction · 0.85
_compound_or_shapeFunction · 0.85
_geomAdaptorMethod · 0.45

Tested by 1

test_offset2DFunction · 0.68