Class: IntervalNotation::SweepLine::TraceState::MultipleState
- Inherits:
-
Struct
- Object
- Struct
- IntervalNotation::SweepLine::TraceState::MultipleState
- 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
Instance Attribute Summary collapse
-
#inclusion_state ⇒ Object
Returns the value of attribute inclusion_state.
Instance Method Summary collapse
-
#state_after_point(points_on_place) ⇒ Object
map state before point (not at point!) into state after point.
-
#state_at_point(points_on_place) ⇒ Object
map state before point into state at point.
-
#state_convolution ⇒ Object
Convolve state inner state into state result.
Instance Attribute Details
#inclusion_state ⇒ Object
Returns the value of attribute 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_convolution ⇒ Object
Convolve state inner state into state result
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 |