<commit_before>require_relative 'notched_path'

module Laser
  module Cutter
    module Geometry
      class Shift < Struct.new(:delta, :direction, :dim_index)
        POINTERS = {[1, 0]  => '   ->',
                    [-1, 0] => '<-   ',
                    [1, 1]  => '  V  ',
                    [-1, 1] => '  ^  '}

        def next(point1)
          p = Point.new(point1.to_a)
          p.coords[dim_index] += (delta * direction)
          p
        end
        def to_s
          "shift by:#{sprintf('%.2f', delta)}, #{POINTERS[[direction,dim_index]]}"
        end
      end

      # Alternating iterator
      class InfiniteIterator < Struct.new(:shift_array)
        attr_accessor :current_index
        def next
          self.current_index = -1 if current_index.nil?
          self.current_index += 1
          self.current_index = current_index % shift_array.size
          shift_array[current_index]
        end
      end

      class PathGenerator
        # Removes the items from the list that appear more than once
        # Unlike uniq-ing which keeps all elements, just ensures that are not
        # repeated, here we remove elements completely if they are seen more than once.
        # This is used to remove lines
        def self.deduplicate list
          new_list = []
          list.sort!
          list.each_with_index do |e, i|
            next if i < (list.size - 1) && e.eql?(list[i + 1])
            next if i > 0 && e.eql?(list[i - 1])
            new_list << e
          end
          new_list
        end

        attr_accessor :notch_width, :thickness
        attr_accessor :center_out, :fill_corners

        def initialize(options = {})
          @notch_width = options[:notch_width]    # only desired, will be adapted for each line
          @center_out = options[:center_out]      # when true, the notch in the middle of the edge is out, not in.
          @thickness = options[:thickness]

          # 2D array of booleans.  If true first or second end of the edge is
          # created with a corner filled in.
          @fill_corners = options[:fill_corners]
        end

        # Calculates a notched path that flows between the outer edge of the box
        # (outside_line) and inner (inside_line).  Relative location of these lines
        # also defines the direction and orientation of the box, and hence the notches.
        #
        # We always want to create a symmetric path that has a notch in the middle
        # (for center_out = true) or dip in the middle (center_out = false)
        def path(edge)
          shifts = define_shifts(edge)

          path = NotchedPath.new

          if fill_corners
            r1 = Geometry::Rect.new(edge.inside.p1, edge.outside.p1)
            r2 = Geometry::Rect.new(edge.inside.p2, edge.outside.p2)
            path.corner_boxes << r1<commit_msg>Updating comments<commit_after>require_relative 'notched_path'

module Laser
  module Cutter
    module Geometry
      class Shift < Struct.new(:delta, :direction, :dim_index)
        POINTERS = {[1, 0]  => '   ->',
                    [-1, 0] => '<-   ',
                    [1, 1]  => '  V  ',
                    [-1, 1] => '  ^  '}

        def next(point1)
          p = Point.new(point1.to_a)
          p.coords[dim_index] += (delta * direction)
          p
        end
        def to_s
          "shift by:#{sprintf('%.2f', delta)}, #{POINTERS[[direction,dim_index]]}"
        end
      end

      # Alternating iterator
      class InfiniteIterator < Struct.new(:shift_array)
        attr_accessor :current_index
        def next
          self.current_index = -1 if current_index.nil?
          self.current_index += 1
          self.current_index = current_index % shift_array.size
          shift_array[current_index]
        end
      end

      class PathGenerator
        # Removes the items from the list that appear more than once
        # Unlike uniq-ing which keeps all elements, just ensures that are not
        # repeated, here we remove elements completely if they are seen more than once.
        # This is used to remove lines that join the same two points.
        def self.deduplicate list
          new_list = []
          list.sort!
          list.each_with_index do |e, i|
            next if i < (list.size - 1) && e.eql?(list[i + 1])
            next if i > 0 && e.eql?(list[i - 1])
            new_list << e
          end
          new_list
        end

        attr_accessor :notch_width, :thickness
        attr_accessor :center_out, :fill_corners

        def initialize(options = {})
          @notch_width = options[:notch_width]    # only desired, will be adapted for each line
          @center_out = options[:center_out]      # when true, the notch in the middle of the edge is out, not in.
          @thickness = options[:thickness]
          @fill_corners = options[:fill_corners]
        end

        # Calculates a notched path that flows between the outer edge of the box
        # (outside_line) and inner (inside_line).  Relative location of these lines
        # also defines the direction and orientation of the box, and hence the notches.
        #
        # We always want to create a symmetric path that has a notch in the middle
        # (for center_out = true) or dip in the middle (center_out = false)
        def path(edge)
          shifts = define_shifts(edge)

          path = NotchedPath.new

          if fill_corners
            r1 = Geometry::Rect.new(edge.inside.p1, edge.outside.p1)
            r2 = Geometry::Rect.new(edge.inside.p2, edge.outside.p2)
            path.corner_boxes << r1
{'fraction_non_alphanumeric': 0.08840864440078586, 'fraction_numerical': 0.008751562779067691, 'mean_word_length': 1.8732683427398666, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4253344', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1591, 'n_words': 518}