Class: SolidRuby::Primitives::Square

Inherits:
Primitive show all
Defined in:
lib/solidruby/primitives/square.rb

Instance Attribute Summary

Attributes inherited from SolidRubyObject

#attributes, #children, #siblings, #transformations

Instance Method Summary collapse

Methods inherited from SolidRubyObject

#&, alias_attr, #debug, #debug?, #mirror, #place, #rotate, #rotate_around, #save, #scale, #translate, #union, #walk_tree, #walk_tree_classes

Constructor Details

#initialize(att) ⇒ Square

Returns a new instance of Square.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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

Instance Method Details

#center_xObject



65
66
67
68
# File 'lib/solidruby/primitives/square.rb', line 65

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

#center_xyObject Also known as: center



59
60
61
62
# File 'lib/solidruby/primitives/square.rb', line 59

def center_xy
  @attributes[:center] = true
  self
end

#center_yObject



70
71
72
73
# File 'lib/solidruby/primitives/square.rb', line 70

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

#centered?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/solidruby/primitives/square.rb', line 75

def centered?
  return @attributes[:center] || false
end

#to_rubyscadObject



55
56
57
# File 'lib/solidruby/primitives/square.rb', line 55

def to_rubyscad
  RubyScadBridge.new.square(@attributes)
end

#xObject



39
40
41
42
43
44
45
# File 'lib/solidruby/primitives/square.rb', line 39

def x
  if @attributes[:size].is_a? Array
    @attributes[:size][0]
  else
    @attributes[:size]
  end
end

#yObject



47
48
49
50
51
52
53
# File 'lib/solidruby/primitives/square.rb', line 47

def y
  if @attributes[:size].is_a? Array
    @attributes[:size][1]
  else
    @attributes[:size]
  end
end