(59 * ($color->toIntComposante('green') - $this->toIntComposante('green'))) ** 2 +
(11 * ($color->toIntComposante('blue') - $this->toIntComposante('blue'))) ** 2;
}
+
+ /**
+ * @param $colors Color[]
+ * @return Color
+ */
+ public function closestColor($colors, $reverse = false)
+ {
+ $distances = [];
+ foreach ($colors as $k => $color) {
+ $distances[$k] = $this->distance($color);
+ }
+ asort($distances);
+ if ($reverse) {
+ $distances = array_reverse($distances, true);
+ }
+ $keys = array_keys($distances);
+ $k = array_shift($keys);
+ return $colors[$k];
+ }
}