Skip to content

Commit 7b1a99c

Browse files
authored
Workplane.rect: test and document negative lengths (#774)
1 parent ea27006 commit 7b1a99c

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

cadquery/cq.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,10 +2491,8 @@ def rect(
24912491
"""
24922492
Make a rectangle for each item on the stack.
24932493
2494-
:param xLen: length in xDirection ( in workplane coordinates )
2495-
:type xLen: float > 0
2496-
:param yLen: length in yDirection ( in workplane coordinates )
2497-
:type yLen: float > 0
2494+
:param xLen: length in the x direction (in workplane coordinates)
2495+
:param yLen: length in the y direction (in workplane coordinates)
24982496
:param centered: If True, the rectangle will be centered around the reference
24992497
point. If False, the corner of the rectangle will be on the reference point and
25002498
it will extend in the positive x and y directions. Can also use a 2-tuple to
@@ -2511,6 +2509,9 @@ def rect(
25112509
25122510
Creates 4 circles at the corners of a square centered on the origin.
25132511
2512+
Negative values for xLen and yLen are permitted, although they only have an effect when
2513+
centered is False.
2514+
25142515
Future Enhancements:
25152516
* project points not in the workplane plane onto the workplane plane
25162517
"""

tests/test_cadquery.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,27 @@ def testRect(self):
434434
)
435435
self.assertTupleAlmostEquals(v0, v1, 3)
436436

437+
# test negative lengths
438+
r0 = Workplane().rect(-x, -y, centered=False)
439+
self.assertTupleAlmostEquals(
440+
(0, 0, 0), r0.vertices(">X and >Y").val().toTuple(), 3
441+
)
442+
self.assertTupleAlmostEquals(
443+
(-x, -y, 0), r0.vertices("<X and <Y").val().toTuple(), 3
444+
)
445+
# test move plus negative length
446+
r1 = Workplane().move(x, y).rect(-x, -y, centered=False)
447+
self.assertTupleAlmostEquals(
448+
(x, y, 0), r1.vertices(">X and >Y").val().toTuple(), 3
449+
)
450+
self.assertTupleAlmostEquals(
451+
(0, 0, 0), r1.vertices("<X and <Y").val().toTuple(), 3
452+
)
453+
# negative length should have no effect with centered=True
454+
v2 = Workplane().rect(x, y).vertices(">X and >Y").val().toTuple()
455+
v3 = Workplane().rect(-x, -y).vertices(">X and >Y").val().toTuple()
456+
self.assertTupleAlmostEquals(v2, v3, 3)
457+
437458
def testLoft(self):
438459
"""
439460
Test making a lofted solid

0 commit comments

Comments
 (0)