Class: SPCore::Scale
- Inherits:
-
Object
- Object
- SPCore::Scale
- Defined in:
- lib/spcore/util/scale.rb
Overview
Provide methods for generating sequences that scale linearly or exponentially.
Class Method Summary collapse
- .exponential(range, n_points) ⇒ Object
-
.linear(range, n_points) ⇒ Object
Produce a sequence of values that progresses in a linear fashion.
Class Method Details
.exponential(range, n_points) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/spcore/util/scale.rb', line 27 def self.exponential range, n_points raise ArgumentError, "n_points is < 2" if n_points < 2 multiplier = (range.last / range.first)**(1.0/(n_points-1)) points = Array.new(n_points) value = range.first points.each_index do |i| points[i] = value value *= multiplier end return points end |
.linear(range, n_points) ⇒ Object
Produce a sequence of values that progresses in a linear fashion.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/spcore/util/scale.rb', line 8 def self.linear range, n_points raise ArgumentError, "n_points is < 2" if n_points < 2 incr = (range.last - range.first) / (n_points - 1) points = Array.new(n_points) value = range.first points.each_index do |i| points[i] = value value += incr end return points end |