diff --git a/cadquery/cq.py b/cadquery/cq.py index 15ff3ad1..15065767 100644 --- a/cadquery/cq.py +++ b/cadquery/cq.py @@ -3816,7 +3816,7 @@ class Workplane(object): # Creates interpolated plate f: Face = Face.makeNSidedSurface( - edges if not points else [Wire.makePolygon(points).close()], + edges if not points else [Wire.makePolygon(points, False, True)], surf_pts, degree=degree, nbPtsOnCur=nbPtsOnCur, diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 033217aa..1d8ae6d1 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -2067,14 +2067,23 @@ class Wire(Shape, Mixin1D): @classmethod def makePolygon( - cls, listOfVertices: Iterable[VectorLike], forConstruction: bool = False, + cls, + listOfVertices: Iterable[VectorLike], + forConstruction: bool = False, + close: bool = False, ) -> "Wire": - # convert list of tuples into Vectors. + """ + Construct a polygonal wire from points. + """ + wire_builder = BRepBuilderAPI_MakePolygon() for v in listOfVertices: wire_builder.Add(Vector(v).toPnt()) + if close: + wire_builder.Close() + w = cls(wire_builder.Wire()) w.forConstruction = forConstruction diff --git a/cadquery/sketch.py b/cadquery/sketch.py index e6e463d5..adc874a0 100644 --- a/cadquery/sketch.py +++ b/cadquery/sketch.py @@ -307,7 +307,9 @@ class Sketch(object): Construct a polygonal face. """ - w = Wire.makePolygon(p if isinstance(p, Vector) else Vector(*p) for p in pts) + w = Wire.makePolygon( + (p if isinstance(p, Vector) else Vector(*p) for p in pts), False, True + ) return self.face(w, angle, mode, tag) diff --git a/tests/test_cad_objects.py b/tests/test_cad_objects.py index ffc5e6db..339636d6 100644 --- a/tests/test_cad_objects.py +++ b/tests/test_cad_objects.py @@ -1,5 +1,6 @@ # system modules import math +import pytest import unittest from tests import BaseTest from OCP.gp import gp_Vec, gp_Pnt, gp_Ax2, gp_Circ, gp_Elips, gp, gp_XYZ, gp_Trsf @@ -721,5 +722,18 @@ class TestCadObjects(BaseTest): self.assertAlmostEqual(many_rad.radius(), 1.0) +@pytest.mark.parametrize( + "points, close, expected_edges", + [ + (((0, 0, 0), (0, 1, 0), (1, 0, 0)), False, 2), + (((0, 0, 0), (0, 1, 0), (1, 0, 0)), True, 3), + (((0, 0, 0), (0, 1, 0), (1, 0, 0), (0, 0, 0)), False, 3), + (((0, 0, 0), (0, 1, 0), (1, 0, 0), (0, 0, 0)), True, 3), + ], +) +def test_wire_makepolygon(points, close, expected_edges): + assert len(Wire.makePolygon(points, False, close).Edges()) == expected_edges + + if __name__ == "__main__": unittest.main() diff --git a/tests/test_cadquery.py b/tests/test_cadquery.py index 94c56e68..079f4bcb 100644 --- a/tests/test_cadquery.py +++ b/tests/test_cadquery.py @@ -5264,6 +5264,11 @@ class TestCadQuery(BaseTest): self.assertEqual(len(r4.solids().vals()), 1) + r5 = ( + Workplane().sketch().polygon([(0, 0), (0, 1), (1, 0)]).finalize().extrude(1) + ) + assert r5.val().Volume() == approx(0.5) + def testCircumscribedPolygon(self): """ Test that circumscribed polygons result in the correct shapes