<commit_before>module SparkleMotion
  module Nodes
    module Transforms
      # Transform values from 0..1 into a new range.
      #
      # TODO: Allow change to range to apply over time?
      class Range < Transform
        def initialize(mid_point:, delta:, source:, mask: nil, logger:)
          super(source: source, mask: mask)
          @logger = logger
          set_range(mid_point, delta)
        end

        def update(t)
          super(t) do |x|
            (@source[x] * (@max - @min)) + @min
          end
        end

        def set_range(mid_point, delta)
          @min = clamp("min", mid_point, delta, (mid_point - delta).round)
          @max = clamp("max", mid_point, delta, (mid_point + delta).round)
        end

      protected

        def clamp(name, mid_point, delta, val)
          if val < 0
            @logger.warn { "Bad range [#{mid_point} +/- #{delta}] - #{name} was <0! (#{val})" }
            val = 0
          end
          if val > 255
            @logger.warn { "Bad range [#{mid_point} +/- #{delta}] - #{name} was >255! (#{val})" }
            val = 255
          end
          val
        end
      end
    end
  end
end<commit_msg>Aaand, I'm an idiot:  This is ranged from 0..1, not 0..255.<commit_after>module SparkleMotion
  module Nodes
    module Transforms
      # Transform values from 0..1 into a new range.
      #
      # TODO: Allow change to range to apply over time?
      class Range < Transform
        def initialize(mid_point:, delta:, source:, mask: nil, logger:)
          super(source: source, mask: mask)
          @logger = logger
          set_range(mid_point, delta)
        end

        def update(t)
          super(t) do |x|
            (@source[x] * (@max - @min)) + @min
          end
        end

        def set_range(mid_point, delta)
          @min = clamp("min", mid_point, delta, mid_point - delta)
          @max = clamp("max", mid_point, delta, mid_point + delta)
        end

      protected

        def clamp(name, mid_point, delta, val)
          if val < 0
            @logger.warn { "Bad range [#{mid_point} +/- #{delta}] - #{name} was <0! (#{val})" }
            val = 0
          end
          if val > 1.0
            @logger.warn { "Bad range [#{mid_point} +/- #{delta}] - #{name} was >1! (#{val})" }
            val = 1.0
          end
          val
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12468513853904283, 'fraction_numerical': 0.012594458438287154, 'mean_word_length': 1.627342888643881, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '6603872', 'n_tokens_mistral': 772, 'n_tokens_neox': 717, 'n_words': 231}