class SolidRuby::Primitives::Square

Public Class Methods

new(att) click to toggle source
Calls superclass method SolidRuby::SolidRubyObject::new
# File lib/solidruby/primitives/square.rb, line 20
def initialize(att)
  if att.is_a? Array
    att = { size: att }
  elsif att.is_a? Numeric
    att = { size: att }
  end

  att[:center] ||= att.delete(:c)
  att.delete(:center) unless att[:center]

  super(att)

  unless @attributes[:size]
    x = @attributes.delete(:x) || 0
    y = @attributes.delete(:y) || 0
    @attributes[:size] = [x, y]
  end
end

Public Instance Methods

center()
Alias for: center_xy
center_x() click to toggle source
# File lib/solidruby/primitives/square.rb, line 65
def center_x
  @transformations << Translate.new(x: -self.x / 2.0)
  self
end
center_xy() click to toggle source
# File lib/solidruby/primitives/square.rb, line 59
def center_xy
  @attributes[:center] = true
  self
end
Also aliased as: center
center_y() click to toggle source
# File lib/solidruby/primitives/square.rb, line 70
def center_y
  @transformations << Translate.new(y: -self.y / 2.0)
  self
end
centered?() click to toggle source
# File lib/solidruby/primitives/square.rb, line 75
def centered?
  return @attributes[:center] || false
end
to_rubyscad() click to toggle source
# File lib/solidruby/primitives/square.rb, line 55
def to_rubyscad
  RubyScadBridge.new.square(@attributes)
end
x() click to toggle source
# File lib/solidruby/primitives/square.rb, line 39
def x
  if @attributes[:size].is_a? Array
    @attributes[:size][0]
  else
    @attributes[:size]
  end
end
y() click to toggle source
# File lib/solidruby/primitives/square.rb, line 47
def y
  if @attributes[:size].is_a? Array
    @attributes[:size][1]
  else
    @attributes[:size]
  end
end