Sha256: 63b91fa78c6dd353b4acb5148b0057824e81d8abb6317e104266a587ec3c1dea

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

module IntervalNotation
  module SweepLine
    module TraceState

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

        # map state before point into state at point
        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

        # map state at point into state after point
        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

        def state_convolution
          num_covered > 0
        end
      end

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

      #   def state_convolution
      #     inclusion_state.any?
      #   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/union.rb