From 9204b128e426a942df406a0771a8c6e44a6eea97 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Fri, 19 Dec 2014 07:40:34 -0500 Subject: [PATCH] Added rotate function at the CQ object level and an associated test. --- cadquery/CQ.py | 19 +++++++++++++++++++ tests/TestCadQuery.py | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/cadquery/CQ.py b/cadquery/CQ.py index 21579e9..bc31bfc 100644 --- a/cadquery/CQ.py +++ b/cadquery/CQ.py @@ -682,6 +682,25 @@ class CQ(object): return self.each(_rot, False) + def rotate(self, axisStartPoint, axisEndPoint, angleDegrees): + """Returns a copy of all of the items on the stack rotated through and angle around the axis of rotation. + + :param axisStartPoint: The first point of the axis of rotation + :type axisStartPoint: a 3-tuple of floats + :type axisEndPoint: The second point of the axis of rotation + :type axisEndPoint: a 3-tuple of floats + :param angleDegrees: the rotation angle, in degrees + :type angleDegrees: float + :returns: a CQ object + + WARNING: the underlying objects are modified, not copied. + + Future Enhancements: + A version of this method that returns a transformed copy instead + of modifying the originals. + """ + return self.newObject([o.rotate(axisStartPoint, axisEndPoint, angleDegrees) for o in self.objects]) + def translate(self,vec): """ Returns a copy of all of the items on the stack moved by the specified translation vector. diff --git a/tests/TestCadQuery.py b/tests/TestCadQuery.py index 054bd6a..48d1bd5 100644 --- a/tests/TestCadQuery.py +++ b/tests/TestCadQuery.py @@ -195,6 +195,21 @@ class TestCadQuery(BaseTest): self.assertEqual(type(r.val()), Solid) self.assertEqual(type(r.first().val()),Solid) + def testRotate(self): + """Test solid rotation at the CQ object level.""" + box = Workplane("XY").box(1, 1, 5) + box.rotate((0, 0, 0), (1, 0, 0), 90) + startPoint = box.faces("