Class: CfSim::ControlField

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#link1Object (readonly)

Returns the value of attribute link1.



4
5
6
# File 'lib/cf_sim/control_field.rb', line 4

def link1
  @link1
end

#link2Object (readonly)

Returns the value of attribute link2.



4
5
6
# File 'lib/cf_sim/control_field.rb', line 4

def link2
  @link2
end

#link3Object (readonly)

Returns the value of attribute link3.



4
5
6
# File 'lib/cf_sim/control_field.rb', line 4

def link3
  @link3
end

#point1Object (readonly)

Returns the value of attribute point1.



4
5
6
# File 'lib/cf_sim/control_field.rb', line 4

def point1
  @point1
end

#point2Object (readonly)

Returns the value of attribute point2.



4
5
6
# File 'lib/cf_sim/control_field.rb', line 4

def point2
  @point2
end

#point3Object (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

#areaObject



33
34
35
# File 'lib/cf_sim/control_field.rb', line 33

def area
  @area ||= calculate_area
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/cf_sim/control_field.rb', line 17

def eql?(other)
  (points - other.points).empty?
end

#hashObject



21
22
23
# File 'lib/cf_sim/control_field.rb', line 21

def hash
  point1.hash + point2.hash + point3.hash
end

#intersected?(other) ⇒ Boolean

Returns:

  • (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


29
30
31
# File 'lib/cf_sim/control_field.rb', line 29

def links
  @links ||= [@link1, @link2, @link3].freeze
end

#pointsObject



25
26
27
# File 'lib/cf_sim/control_field.rb', line 25

def points
  @points ||= [@point1, @point2, @point3].freeze
end

#to_sObject



45
46
47
# File 'lib/cf_sim/control_field.rb', line 45

def to_s
  "#{point1.name} -> #{point2.name} -> #{point3.name}"
end