Sha256: 3fe8267c6258228486a8d71cf4771adc4622e5ba6d8a8b8201672fe16b568962

Contents?: true

Size: 813 Bytes

Versions: 1

Compression:

Stored size: 813 Bytes

Contents

# Rectification maps values to an interval treated either as a cycle or a
# cutoff.

# Adds recticiation to Numerics and their progeny
class Numeric

  # Treats the interval between low and high as a cycle, returning the result
  # of wrapping the instance around this interval.
  def wrap_rectify(high=1,low=0)
    if (high != low)
      low,high = high,low if low > high
      diff = high-low
      self-diff*((self-low)/diff).floor
    else
      low
    end
  end
  
  # Treats the low and high as limits, returning low or high if the instance
  # is respectively below or above these values, or the instance if between
  # the two.
  def cut_rectify(high=1,low=0)
    low,high = high,low if low > high
    if (self < low)
      low
    elsif (self > high)
      high
    else
      self
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eymiha_math-0.1.0 lib/rectify.rb