Class: JennCad::Size

Inherits:
Object
  • Object
show all
Defined in:
lib/jenncad/position.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Size

Returns a new instance of Size.



4
5
6
7
8
9
10
11
# File 'lib/jenncad/position.rb', line 4

def initialize(args={})
  @size = {
    x: args[:x].to_d,
    y: args[:y].to_d,
    z: (args[:z] || args[:h]).to_d,
    d: args[:d].to_d,
  }
end

Instance Attribute Details

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'lib/jenncad/position.rb', line 3

def size
  @size
end

Instance Method Details

#add(other) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/jenncad/position.rb', line 13

def add(other)
  return self if other.nil?
  @size[:x] += other.x
  @size[:y] += other.y
  @size[:z] += other.z
  @size[:d] += other.d
  self
end

#dObject



50
51
52
# File 'lib/jenncad/position.rb', line 50

def d
  @size[:d]
end

#set(a, to) ⇒ Object



34
35
36
# File 'lib/jenncad/position.rb', line 34

def set(a, to)
  @size[a] = to
end

#to_pointObject



30
31
32
# File 'lib/jenncad/position.rb', line 30

def to_point
  Point.new(x: @size[:x], y: @size[:y], z: @size[:z])
end

#union(other) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/jenncad/position.rb', line 22

def union(other)
  @size[:x] = [@size[:x], other.x].max
  @size[:y] = [@size[:y], other.y].max
  @size[:z] = [@size[:z], other.z].max
  @size[:d] = [@size[:d], other.d].max
  self
end

#xObject



38
39
40
# File 'lib/jenncad/position.rb', line 38

def x
  @size[:x]
end

#yObject



42
43
44
# File 'lib/jenncad/position.rb', line 42

def y
  @size[:y]
end

#zObject



46
47
48
# File 'lib/jenncad/position.rb', line 46

def z
  @size[:z]
end