private Swatch FindDominantSwatch() { int maxPop = int.MinValue; Swatch maxSwatch = null; for (int i = 0, count = _swatches.Count; i < count; i++) { Swatch swatch = _swatches.ElementAt(i); if (swatch.GetPopulation() > maxPop) { maxSwatch = swatch; maxPop = swatch.GetPopulation(); } } return(maxSwatch); }
private float GenerateScore(Swatch swatch, Target target) { float[] hsl = swatch.GetHsl(); float saturationScore = 0; float luminanceScore = 0; float populationScore = 0; int maxPopulation = _dominantSwatch?.GetPopulation() ?? 1; if (target.GetSaturationWeight() > 0) { saturationScore = target.GetSaturationWeight() * (1f - Math.Abs(hsl[1] - target.GetTargetSaturation())); } if (target.GetLightnessWeight() > 0) { luminanceScore = target.GetLightnessWeight() * (1f - Math.Abs(hsl[2] - target.GetTargetLightness())); } if (target.GetPopulationWeight() > 0) { populationScore = target.GetPopulationWeight() * (swatch.GetPopulation() / (float)maxPopulation); } return(saturationScore + luminanceScore + populationScore); }