gumyr / build123d

A python CAD programming library
Apache License 2.0
395 stars 72 forks source link

-offset(loft(slot)) fails but works in FreeCad #545

Open MatthiasJ1 opened 5 months ago

MatthiasJ1 commented 5 months ago
p = loft([
    SlotOverall(10, 6).clean(),
    Pos(Z=4)*SlotOverall(6, 4).clean(),
])

p = offset(p, -0.5, p.faces()>>Axis.Z)

gives

OCP.Standard.Standard_Failure: Geom_TrimmedCurve::parameters out of range

FreeCad has no problem performing this exact operation so the issue lies within how B3D is calling OCCT.

Screenshot
gumyr commented 4 months ago

The problem occurs in the fix() method after the offset is complete.

p = loft([SlotOverall(10, 6).clean(), Pos(Z=4) * SlotOverall(6, 4).clean()])
p_solid = p.solid()
top = p_solid.faces().sort_by(Axis.Z)[-1]
hollow = p_solid.offset_3d([top], -0.5, kind=Kind.ARC)
print(hollow.is_valid()) # False
fixed = hollow.fix() # OCP.Standard.Standard_ConstructionError: Geom_TrimmedCurve::parameters out of range

image

So, the part isn't valid but looks as though it is and fix can't fix it.

As far as I can tell FreeCAD also uses BRepOffsetAPI_MakeThickSolid to create the shell. I've tried changing its parameters but could not get it to generate a valid part. It could be that FreeCAD just returns the part even though it isn't valid but I don't know.

The attempted fix could be put in a try block and the broken part returned with a warning if thefix failed. Would that be better?