MCPcopy Create free account
hub / github.com/comaps/comaps / GetDistance

Function GetDistance

libs/transit/world_feed/color_picker.cpp:20–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18}
19
20double GetDistance(dp::Color const & color1, dp::Color const & color2)
21{
22 auto [r1, g1, b1] = GetColors(color1);
23 auto [r2, g2, b2] = GetColors(color2);
24
25 // We use the cmetric (Color metric) for calculating the distance between two colors.
26 // https://en.wikipedia.org/wiki/Color_difference
27 // It reflects human perception of closest match for a specific colour. The formula weights RGB
28 // values to better fit eye perception and performs well at proper determinations of colors
29 // contributions, brightness of these colors, and degree to which human vision has less tolerance
30 // for these colors.
31 double const redMean = (r1 + r2) / 2.0;
32
33 double const redDelta = r1 - r2;
34 double const greenDelta = g1 - g2;
35 double const blueDelta = b1 - b2;
36
37 return (2.0 + redMean / 256.0) * redDelta * redDelta + 4 * greenDelta * greenDelta +
38 (2.0 + (255.0 - redMean) / 256.0) * blueDelta * blueDelta;
39}
40} // namespace
41
42namespace transit

Callers 1

GetNearestColorMethod · 0.70

Calls 1

GetColorsFunction · 0.85

Tested by

no test coverage detected