Skip to content

Commit 26f05c5

Browse files
authored
Merge pull request #1257 from lorenzncode/1180-polygon-close
Add close option to Wire.makePolygon
2 parents 4c96410 + 24ae7bc commit 26f05c5

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

cadquery/cq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3816,7 +3816,7 @@ def interpPlate(
38163816

38173817
# Creates interpolated plate
38183818
f: Face = Face.makeNSidedSurface(
3819-
edges if not points else [Wire.makePolygon(points).close()],
3819+
edges if not points else [Wire.makePolygon(points, False, True)],
38203820
surf_pts,
38213821
degree=degree,
38223822
nbPtsOnCur=nbPtsOnCur,

cadquery/occ_impl/shapes.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,14 +2067,23 @@ def makeEllipse(
20672067

20682068
@classmethod
20692069
def makePolygon(
2070-
cls, listOfVertices: Iterable[VectorLike], forConstruction: bool = False,
2070+
cls,
2071+
listOfVertices: Iterable[VectorLike],
2072+
forConstruction: bool = False,
2073+
close: bool = False,
20712074
) -> "Wire":
2072-
# convert list of tuples into Vectors.
2075+
"""
2076+
Construct a polygonal wire from points.
2077+
"""
2078+
20732079
wire_builder = BRepBuilderAPI_MakePolygon()
20742080

20752081
for v in listOfVertices:
20762082
wire_builder.Add(Vector(v).toPnt())
20772083

2084+
if close:
2085+
wire_builder.Close()
2086+
20782087
w = cls(wire_builder.Wire())
20792088
w.forConstruction = forConstruction
20802089

cadquery/sketch.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ def polygon(
307307
Construct a polygonal face.
308308
"""
309309

310-
w = Wire.makePolygon(p if isinstance(p, Vector) else Vector(*p) for p in pts)
310+
w = Wire.makePolygon(
311+
(p if isinstance(p, Vector) else Vector(*p) for p in pts), False, True
312+
)
311313

312314
return self.face(w, angle, mode, tag)
313315

tests/test_cad_objects.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# system modules
22
import math
3+
import pytest
34
import unittest
45
from tests import BaseTest
56
from OCP.gp import gp_Vec, gp_Pnt, gp_Ax2, gp_Circ, gp_Elips, gp, gp_XYZ, gp_Trsf
@@ -721,5 +722,18 @@ def testEdgeWrapperRadius(self):
721722
self.assertAlmostEqual(many_rad.radius(), 1.0)
722723

723724

725+
@pytest.mark.parametrize(
726+
"points, close, expected_edges",
727+
[
728+
(((0, 0, 0), (0, 1, 0), (1, 0, 0)), False, 2),
729+
(((0, 0, 0), (0, 1, 0), (1, 0, 0)), True, 3),
730+
(((0, 0, 0), (0, 1, 0), (1, 0, 0), (0, 0, 0)), False, 3),
731+
(((0, 0, 0), (0, 1, 0), (1, 0, 0), (0, 0, 0)), True, 3),
732+
],
733+
)
734+
def test_wire_makepolygon(points, close, expected_edges):
735+
assert len(Wire.makePolygon(points, False, close).Edges()) == expected_edges
736+
737+
724738
if __name__ == "__main__":
725739
unittest.main()

tests/test_cadquery.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5264,6 +5264,11 @@ def testSketch(self):
52645264

52655265
self.assertEqual(len(r4.solids().vals()), 1)
52665266

5267+
r5 = (
5268+
Workplane().sketch().polygon([(0, 0), (0, 1), (1, 0)]).finalize().extrude(1)
5269+
)
5270+
assert r5.val().Volume() == approx(0.5)
5271+
52675272
def testCircumscribedPolygon(self):
52685273
"""
52695274
Test that circumscribed polygons result in the correct shapes

0 commit comments

Comments
 (0)