Skip color dist calc if exact match

This commit is contained in:
Astrash 2022-11-26 14:05:39 +11:00
parent 878bede60b
commit a97273f358

View File

@ -20,11 +20,12 @@ public class ClosestMatchColorConverter<T> implements ColorConverter<T> {
int closest = 0; int closest = 0;
int smallestDistance = Integer.MAX_VALUE; int smallestDistance = Integer.MAX_VALUE;
for(int compare : colors) { for(int compare : colors) {
int distance = ColorUtil.distance(color, compare); if(color == compare) {
if(distance == 0) {
closest = compare; closest = compare;
break; break;
} else if(distance < smallestDistance) { }
int distance = ColorUtil.distance(color, compare);
if(distance < smallestDistance) {
smallestDistance = distance; smallestDistance = distance;
closest = compare; closest = compare;
} }