From fd0f1f65d3de2ea9d2c9759a41eb1e45521504f1 Mon Sep 17 00:00:00 2001 From: adam-urbanczyk Date: Thu, 1 Apr 2021 22:31:30 +0200 Subject: [PATCH] Check if wires are coplanar --- cadquery/occ_impl/shapes.py | 9 +++++++++ tests/test_cadquery.py | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 7c3e2f912..68fc07462 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -2095,12 +2095,21 @@ def makeFromWires( Makes a planar face from one or more wires """ + # check if wires are coplanar + ws = Compound.makeCompound([outerWire] + innerWires) + if not BRepLib_FindSurface(ws.wrapped, OnlyPlane=True).Found(): + raise ValueError("Cannot build face(s): wires not planar") + face_builder = BRepBuilderAPI_MakeFace(outerWire.wrapped, True) for w in innerWires: face_builder.Add(w.wrapped) face_builder.Build() + + if not face_builder.IsDone(): + raise ValueError(f"Cannot build face(s): {face_builder.Error()}") + face = face_builder.Shape() return cls(face).fix() diff --git a/tests/test_cadquery.py b/tests/test_cadquery.py index ee3d029b2..1c5480adb 100644 --- a/tests/test_cadquery.py +++ b/tests/test_cadquery.py @@ -3087,6 +3087,10 @@ def testExtrude(self): delta.toTuple(), (0.0, 0.0, 2.0 * h), decimal_places ) + # check that non-conplanar extrusion raises + with self.assertRaises(ValueError): + Workplane().box(1, 1, 1).faces().circle(0.1).extrude(0.1) + def testTaperedExtrudeCutBlind(self): h = 1.0