Class: GravityCenter
- Inherits:
-
Object
- Object
- GravityCenter
- Defined in:
- lib/gravity_center.rb
Instance Attribute Summary collapse
-
#x1 ⇒ Object
readonly
Returns the value of attribute x1.
-
#x2 ⇒ Object
readonly
Returns the value of attribute x2.
-
#x3 ⇒ Object
readonly
Returns the value of attribute x3.
-
#y1 ⇒ Object
readonly
Returns the value of attribute y1.
-
#y2 ⇒ Object
readonly
Returns the value of attribute y2.
-
#y3 ⇒ Object
readonly
Returns the value of attribute y3.
Class Method Summary collapse
Instance Method Summary collapse
- #center ⇒ Object
- #center_sx ⇒ Object
- #center_sy ⇒ Object
- #center_x ⇒ Object
- #center_y ⇒ Object
- #sx1 ⇒ Object
- #sx2 ⇒ Object
- #sy1 ⇒ Object
- #sy2 ⇒ Object
Instance Attribute Details
#x1 ⇒ Object (readonly)
Returns the value of attribute x1.
6 7 8 |
# File 'lib/gravity_center.rb', line 6 def x1 @x1 end |
#x2 ⇒ Object (readonly)
Returns the value of attribute x2.
6 7 8 |
# File 'lib/gravity_center.rb', line 6 def x2 @x2 end |
#x3 ⇒ Object (readonly)
Returns the value of attribute x3.
6 7 8 |
# File 'lib/gravity_center.rb', line 6 def x3 @x3 end |
#y1 ⇒ Object (readonly)
Returns the value of attribute y1.
6 7 8 |
# File 'lib/gravity_center.rb', line 6 def y1 @y1 end |
#y2 ⇒ Object (readonly)
Returns the value of attribute y2.
6 7 8 |
# File 'lib/gravity_center.rb', line 6 def y2 @y2 end |
#y3 ⇒ Object (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
#center ⇒ Object
60 61 62 |
# File 'lib/gravity_center.rb', line 60 def center [center_x, center_y] end |
#center_sx ⇒ Object
42 43 44 45 |
# File 'lib/gravity_center.rb', line 42 def center_sx @center_sx ||= calc_center_sx @center_sx end |
#center_sy ⇒ Object
51 52 53 54 |
# File 'lib/gravity_center.rb', line 51 def center_sy @center_sy ||= calc_center_sy @center_sy end |
#center_x ⇒ Object
47 48 49 |
# File 'lib/gravity_center.rb', line 47 def center_x center_sx + x3 end |
#center_y ⇒ Object
56 57 58 |
# File 'lib/gravity_center.rb', line 56 def center_y center_sy + y3 end |
#sx1 ⇒ Object
22 23 24 25 |
# File 'lib/gravity_center.rb', line 22 def sx1 @sx1 ||= x1 - x3 @sx1 end |
#sx2 ⇒ Object
32 33 34 35 |
# File 'lib/gravity_center.rb', line 32 def sx2 @sx2 ||= x2 - x3 @sx2 end |
#sy1 ⇒ Object
27 28 29 30 |
# File 'lib/gravity_center.rb', line 27 def sy1 @sy1 ||= y1 - y3 @sy1 end |
#sy2 ⇒ Object
37 38 39 40 |
# File 'lib/gravity_center.rb', line 37 def sy2 @sy2 ||= y2 - y3 @sy2 end |