Commits

Ed Blake  committed f16c075

Added optional parameters to Cylinder and Rotate.
Added Doc strings and comments.

  • Participants
  • Parent commits 27addc6

Comments (0)

Files changed (3)

File py2scad/base.py

     """Scad object wrapper base class."""
 
     def __init__(self,center=True,mod=''):
-        self.type = None
-        self.center = center
-        self.cmp = False
-        self.mod = mod
+        self.type = None    # ?
+        self.center = center# Centered or positive quadrent
+        self.cmp = False    # Is compound
+        self.mod = mod      # Rendering modifier (*,%,#,!)
 
     def center_str(self):
         return str(self.center).lower()

File py2scad/primitives.py

 """
-Copyright 2010  IO Rodeo Inc. 
+Copyright 2010  IO Rodeo Inc.
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
     def cmd_str(self,tab_level=0):
         size_str = utility.val_to_str(self.size)
         center_str = self.center_str()
-        return 'cube(size=%s,center=%s);'%(size_str,center_str) 
+        return 'cube(size=%s,center=%s);'%(size_str,center_str)
 
 class Sphere(base.SCAD_Object):
 
 
 class Cylinder(base.SCAD_Object):
 
-    def __init__(self, h=1.0, r1=1.0, r2=1.0, center=True,mod=''):
+    def __init__(self, h=1.0, r1=1.0, r2=None, center=True, mod=''):
         base.SCAD_Object.__init__(self,center=center,mod=mod)
         self.h = float(h)
         self.r1 = float(r1)
-        self.r2 = float(r2)
+        # r2 is optional
+        self.r2 = r2
+        if r2:
+            self.r2 = float(r2)
 
     def cmd_str(self,tab_level=0):
+        center_str = self.center_str()
         h_str = utility.val_to_str(self.h)
         r1_str = utility.val_to_str(self.r1)
-        r2_str = utility.val_to_str(self.r2)
-        center_str = self.center_str()
-        return 'cylinder(h=%s,r1=%s,r2=%s,center=%s);'%(h_str, r1_str, r2_str, center_str)
-        
+        if self.r2:
+            r2_str = utility.val_to_str(self.r2)
+            return 'cylinder(h=%s,r1=%s,r2=%s,center=%s);'%(h_str, r1_str, r2_str, center_str)
+        return 'cylinder(h=%s,r1=%s,center=%s);'%(h_str, r1_str, center_str)
+
 class Polyhedron(base.SCAD_Object):
 
     def __init__(self, points, faces, center=True, mod=''):

File py2scad/transforms.py

 """
-Copyright 2010  IO Rodeo Inc. 
+Copyright 2010  IO Rodeo Inc.
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 # 3D transformations ---------------------------------------------------------
 
 class Scale(base.SCAD_CMP_Object):
-
+    """Scale contained object along local x,y,z."""
     def __init__(self,obj,v=[1.0,1.0,1.0], mod=''):
         base.SCAD_CMP_Object.__init__(self, obj, mod=mod)
         self.v = utility.float_list3(v)
         return 'scale(v=%s)'%(v_str)
 
 class Rotate(base.SCAD_CMP_Object):
+    """Rotate contained objects."""
 
-    def __init__(self,obj,a=0.0,v=[1.0,0.0,0.0],mod=''):
+    def __init__(self, obj, v=[1.0,0.0,0.0], a=None, mod=''):
         base.SCAD_CMP_Object.__init__(self,obj,mod=mod)
-        self.a = float(a)
-        self.v = utility.float_list3(v) 
+        self.v = utility.float_list3(v)
+        self.a = a
 
     def cmd_str(self,tab_level=0):
-        a_str = utility.val_to_str(self.a)
         v_str = utility.val_to_str(self.v)
-        return 'rotate(a=%s,v=%s)'%(a_str,v_str)
+        if self.a: # If there's an angle use axis/angle
+            a_str = utility.val_to_str(self.a)
+            return 'rotate(a=%s,v=%s)'%(a_str,v_str)
+        # If not a then interpret v as a vector of angles
+        return 'rotate(a=%s)'%(v_str)
+
 
 class AnimRotate(base.SCAD_CMP_Object):
 
 
     def cmd_str(self,tab_level=0):
         return 'translate(v=%s)'%(self.v,)
-       
+
 class Mirror(base.SCAD_CMP_Object):
 
     def __init__(self,obj,v=[1.0,0.0,0.0],mod=''):
 
     def cmd_str(self,tab_level=0):
         return 'intersection()'
-    
+
 # 2D to 3D Extrusion -----------------------------------------------------------
 
 class Linear_Extrude(base.SCAD_CMP_Object):