Class: CfSim::ControlField
- Inherits:
-
Object
- Object
- CfSim::ControlField
- Defined in:
- lib/cf_sim/control_field.rb
Instance Attribute Summary collapse
-
#link1 ⇒ Object
readonly
Returns the value of attribute link1.
-
#link2 ⇒ Object
readonly
Returns the value of attribute link2.
-
#link3 ⇒ Object
readonly
Returns the value of attribute link3.
-
#point1 ⇒ Object
readonly
Returns the value of attribute point1.
-
#point2 ⇒ Object
readonly
Returns the value of attribute point2.
-
#point3 ⇒ Object
readonly
Returns the value of attribute point3.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #area ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(point1, point2, point3) ⇒ ControlField
constructor
A new instance of ControlField.
- #intersected?(other) ⇒ Boolean
- #links ⇒ Object
- #points ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(point1, point2, point3) ⇒ ControlField
Returns a new instance of ControlField.
6 7 8 9 10 11 |
# File 'lib/cf_sim/control_field.rb', line 6 def initialize(point1, point2, point3) @point1, @point2, @point3 = point1, point2, point3 @link1 = CfSim::Link.new(point1, point2) @link2 = CfSim::Link.new(point2, point3) @link3 = CfSim::Link.new(point3, point1) end |
Instance Attribute Details
#link1 ⇒ Object (readonly)
Returns the value of attribute link1.
4 5 6 |
# File 'lib/cf_sim/control_field.rb', line 4 def link1 @link1 end |
#link2 ⇒ Object (readonly)
Returns the value of attribute link2.
4 5 6 |
# File 'lib/cf_sim/control_field.rb', line 4 def link2 @link2 end |
#link3 ⇒ Object (readonly)
Returns the value of attribute link3.
4 5 6 |
# File 'lib/cf_sim/control_field.rb', line 4 def link3 @link3 end |
#point1 ⇒ Object (readonly)
Returns the value of attribute point1.
4 5 6 |
# File 'lib/cf_sim/control_field.rb', line 4 def point1 @point1 end |
#point2 ⇒ Object (readonly)
Returns the value of attribute point2.
4 5 6 |
# File 'lib/cf_sim/control_field.rb', line 4 def point2 @point2 end |
#point3 ⇒ Object (readonly)
Returns the value of attribute point3.
4 5 6 |
# File 'lib/cf_sim/control_field.rb', line 4 def point3 @point3 end |
Instance Method Details
#==(other) ⇒ Object
13 14 15 |
# File 'lib/cf_sim/control_field.rb', line 13 def ==(other) eql?(other) end |
#area ⇒ Object
33 34 35 |
# File 'lib/cf_sim/control_field.rb', line 33 def area @area ||= calculate_area end |
#eql?(other) ⇒ Boolean
17 18 19 |
# File 'lib/cf_sim/control_field.rb', line 17 def eql?(other) (points - other.points).empty? end |
#hash ⇒ Object
21 22 23 |
# File 'lib/cf_sim/control_field.rb', line 21 def hash point1.hash + point2.hash + point3.hash end |
#intersected?(other) ⇒ Boolean
37 38 39 40 41 42 43 |
# File 'lib/cf_sim/control_field.rb', line 37 def intersected?(other) links.any? do |link1| other.links.any? do |link2| link1.intersected?(link2) end end end |
#links ⇒ Object
29 30 31 |
# File 'lib/cf_sim/control_field.rb', line 29 def links @links ||= [@link1, @link2, @link3].freeze end |
#points ⇒ Object
25 26 27 |
# File 'lib/cf_sim/control_field.rb', line 25 def points @points ||= [@point1, @point2, @point3].freeze end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/cf_sim/control_field.rb', line 45 def to_s "#{point1.name} -> #{point2.name} -> #{point3.name}" end |