Module: Termin::ANSIColor::RGBColorMetricsHelpers::WeightedEuclideanDistance

Instance Method Summary collapse

Instance Method Details

#weighted_euclidean_distance_to(other, weights = [ 1.0 ] * values.size) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/termin/ansicolor/rgb_color_metrics.rb', line 5

def weighted_euclidean_distance_to(other, weights = [ 1.0 ] * values.size)
  sum = 0.0
  values.zip(other.values, weights) do |s, o, w|
    sum += w * (s - o) ** 2
  end
  Math.sqrt(sum)
end