Class: GravityCenter

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#x1Object (readonly)

Returns the value of attribute x1.



6
7
8
# File 'lib/gravity_center.rb', line 6

def x1
  @x1
end

#x2Object (readonly)

Returns the value of attribute x2.



6
7
8
# File 'lib/gravity_center.rb', line 6

def x2
  @x2
end

#x3Object (readonly)

Returns the value of attribute x3.



6
7
8
# File 'lib/gravity_center.rb', line 6

def x3
  @x3
end

#y1Object (readonly)

Returns the value of attribute y1.



6
7
8
# File 'lib/gravity_center.rb', line 6

def y1
  @y1
end

#y2Object (readonly)

Returns the value of attribute y2.



6
7
8
# File 'lib/gravity_center.rb', line 6

def y2
  @y2
end

#y3Object (readonly)

Returns the value of attribute y3.



6
7
8
# File 'lib/gravity_center.rb', line 6

def y3
  @y3
end

Class Method Details

.create(*val) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gravity_center.rb', line 8

def self.create(*val)
  gc = self.new
  gc.instance_eval do
    v = [val].flatten
    @x1 = BigDecimal(v[0].to_s)
    @y1 = BigDecimal(v[1].to_s)
    @x2 = BigDecimal(v[2].to_s)
    @y2 = BigDecimal(v[3].to_s)
    @x3 = BigDecimal(v[4].to_s)
    @y3 = BigDecimal(v[5].to_s)
  end
  gc
end

Instance Method Details

#centerObject



60
61
62
# File 'lib/gravity_center.rb', line 60

def center
  [center_x, center_y]
end

#center_sxObject



42
43
44
45
# File 'lib/gravity_center.rb', line 42

def center_sx
  @center_sx ||= calc_center_sx
  @center_sx
end

#center_syObject



51
52
53
54
# File 'lib/gravity_center.rb', line 51

def center_sy
  @center_sy ||= calc_center_sy
  @center_sy
end

#center_xObject



47
48
49
# File 'lib/gravity_center.rb', line 47

def center_x
  center_sx + x3
end

#center_yObject



56
57
58
# File 'lib/gravity_center.rb', line 56

def center_y
  center_sy + y3
end

#sx1Object



22
23
24
25
# File 'lib/gravity_center.rb', line 22

def sx1
  @sx1 ||= x1 - x3
  @sx1
end

#sx2Object



32
33
34
35
# File 'lib/gravity_center.rb', line 32

def sx2
  @sx2 ||= x2 - x3
  @sx2
end

#sy1Object



27
28
29
30
# File 'lib/gravity_center.rb', line 27

def sy1
  @sy1 ||= y1 - y3
  @sy1
end

#sy2Object



37
38
39
40
# File 'lib/gravity_center.rb', line 37

def sy2
  @sy2 ||= y2 - y3
  @sy2
end