Class: IntervalNotation::SweepLine::TraceState::Union

Inherits:
Struct
  • Object
show all
Defined in:
lib/interval_notation/sweep_line/trace_state/union.rb

Overview

Class allows to observe whether sweep line is inside of interval sets union or outside

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#num_coveredObject

Returns the value of attribute num_covered

Returns:

  • (Object)

    the current value of num_covered



6
7
8
# File 'lib/interval_notation/sweep_line/trace_state/union.rb', line 6

def num_covered
  @num_covered
end

Class Method Details

.initial_state(num_interval_sets) ⇒ Object



7
8
9
# File 'lib/interval_notation/sweep_line/trace_state/union.rb', line 7

def self.initial_state(num_interval_sets)
  self.new(0)
end

Instance Method Details

#state_after_point(points_on_place) ⇒ Object

map state at point into state after point



29
30
31
32
33
34
35
36
# File 'lib/interval_notation/sweep_line/trace_state/union.rb', line 29

def state_after_point(points_on_place)
  new_state = num_covered
  points_on_place.reject(&:singular_point?).each{|point|
    new_state += point.opening ? 1 : -1
  }
  
  self.class.new(new_state)
end

#state_at_point(points_on_place) ⇒ Object

map state before point into state at point



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/interval_notation/sweep_line/trace_state/union.rb', line 12

def state_at_point(points_on_place)
  new_state = num_covered
  points_on_place.each{|point|
    if point.singular_point?
      new_state += 1
    else
      if point.closing && !point.included
        new_state -= 1
      elsif point.opening && point.included
        new_state += 1
      end
    end
  }
  self.class.new(new_state)
end

#state_convolutionObject



38
39
40
# File 'lib/interval_notation/sweep_line/trace_state/union.rb', line 38

def state_convolution
  num_covered > 0
end