Class: IntervalNotation::SweepLine::TraceState::MultipleState

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

Overview

MultipleState is a simple abstract class to store and manage state of intersection with sweep line of several interval sets

In order to use it one should define subclass with ‘#state_convolution` method. If specific convolution can be defined in easier terms, `#state_at_point` and `#state_after_point` also can be redefined in a subclass for perfomance and clarity reasons

Direct Known Subclasses

Subtract, SymmetricDifference

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#inclusion_stateObject

Returns the value of attribute inclusion_state

Returns:

  • (Object)

    the current value of inclusion_state



10
11
12
# File 'lib/interval_notation/sweep_line/trace_state/multiple_state.rb', line 10

def inclusion_state
  @inclusion_state
end

Instance Method Details

#state_after_point(points_on_place) ⇒ Object

map state before point (not at point!) into state after point



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/interval_notation/sweep_line/trace_state/multiple_state.rb', line 21

def state_after_point(points_on_place)
  new_state = inclusion_state.dup

  interval_boundary_points = points_on_place.reject(&:singular_point?)
  points_by_closing = interval_boundary_points.group_by(&:closing)
  closing_points = points_by_closing.fetch(true){ [] }
  opening_points = points_by_closing.fetch(false){ [] }

  closing_points.each{|point|
    new_state[point.interval_index] = false
  }
  opening_points.each{|point|
    new_state[point.interval_index] = true
  }
  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
# File 'lib/interval_notation/sweep_line/trace_state/multiple_state.rb', line 12

def state_at_point(points_on_place)
  new_state = inclusion_state.dup
  points_on_place.each{|point|
    new_state[point.interval_index] = point.included
  }
  self.class.new(new_state)
end

#state_convolutionObject

Convolve state inner state into state result

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/interval_notation/sweep_line/trace_state/multiple_state.rb', line 39

def state_convolution
  raise NotImplementedError, '#state_convolution should be redefined in a superclass'
end