Class: CrystalScad::Square

Inherits:
Primitive show all
Defined in:
lib/crystalscad/CrystalScad.rb

Overview

2d primitives

Instance Attribute Summary

Attributes inherited from Primitive

#children

Attributes inherited from CrystalScadObject

#args, #transformations

Instance Method Summary collapse

Methods inherited from Primitive

#mirror, #rotate, #rotate_around, #scale, #transform, #translate, #union

Methods inherited from CrystalScadObject

#method_missing, #save, #walk_tree, #walk_tree_classes

Constructor Details

#initialize(*args) ⇒ Square

Returns a new instance of Square.



170
171
172
173
174
175
176
177
178
# File 'lib/crystalscad/CrystalScad.rb', line 170

def initialize(*args)
  super(args)
if args[0][:size].kind_of? Array
   @x,@y = args[0][:size].map{|l| l.to_f}
else
  @x = args[0][:size].to_f
  @y = @x
end   
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CrystalScad::CrystalScadObject

Instance Method Details

#center_xObject



190
191
192
193
# File 'lib/crystalscad/CrystalScad.rb', line 190

def center_x
  @transformations << Translate.new({x:-@x/2})
  self
end

#center_xyObject Also known as: center



184
185
186
187
# File 'lib/crystalscad/CrystalScad.rb', line 184

def center_xy
  @transformations << Translate.new({x:-@x/2,y:-@y/2})
  self
end

#center_yObject



195
196
197
198
# File 'lib/crystalscad/CrystalScad.rb', line 195

def center_y
  @transformations << Translate.new({y:-@y/2})
  self
end

#to_rubyscadObject



180
181
182
# File 'lib/crystalscad/CrystalScad.rb', line 180

def to_rubyscad
  return RubyScadBridge.new.square(@args)    
end