Module: ColorContrastCalc::ThresholdFinder::Lightness

Extended by:
FinderUtils
Defined in:
lib/color_contrast_calc/threshold_finder.rb

Overview

Module that implements the main logic of the instance method Color#find_lightness_threshold().

Class Method Summary collapse

Class Method Details

.find(fixed_rgb, other_rgb, level = Checker::Level::AA) ⇒ Array<Integer>

Try to find a color who has a satisfying contrast ratio.

The color returned by this method will be created by changing the lightness of other_rgb. Even when a color that satisfies the specified level is not found, the method returns a new color anyway.



233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/color_contrast_calc/threshold_finder.rb', line 233

def self.find(fixed_rgb, other_rgb, level = Checker::Level::AA)
  other_hsl = Utils.rgb_to_hsl(other_rgb)
  criteria = Criteria.define(level, fixed_rgb, other_rgb)
  max, min = determine_minmax(fixed_rgb, other_rgb, other_hsl[2])

  boundary_rgb = lightness_boundary_rgb(fixed_rgb, max, min, criteria)
  return boundary_rgb if boundary_rgb

  last_l, passing_l = find_ratio(other_hsl, criteria,
                                 (max + min) / 2.0, max - min)

  rgb_with_better_ratio(other_hsl, criteria, last_l, passing_l)
end