Sha256: e67698841232c9a7b4a533a40066d9e2fc09dd0e34e96d97d226b6c162a1db9b

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

module IntervalNotation
  module SweepLine
    module TraceState

      # Class allows to observe whether sweep line is inside of interval sets intersection or outside
      Intersection = Struct.new(:num_uncovered) do
        def self.initial_state(num_interval_sets)
          self.new(num_interval_sets)
        end

        # map state before point into state at point
        def state_at_point(points_on_place)
          new_state = num_uncovered
          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

        # map state at point into state after point
        def state_after_point(points_on_place)
          new_state = num_uncovered
          points_on_place.reject(&:singular_point?).each{|point|
            new_state += point.opening ? -1 : +1
          }
          
          self.class.new(new_state)
        end

        def state_convolution
          num_uncovered == 0
        end
      end

      # # More generic but less efficient version of Intersection state
      # class IntersectionMultiState < MultipleState
      #   def self.initial_state(num_interval_sets)
      #     self.new( Array.new(num_interval_sets, false) )
      #   end

      #   def state_convolution
      #     inclusion_state.all?
      #   end
      # end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
interval_notation-0.2.0 lib/interval_notation/sweep_line/trace_state/intersection.rb