Skip to content

Commit

Permalink
api(text): Improve HSV distance calculation
Browse files Browse the repository at this point in the history
Tested-by: jmp <jasonpenilla2@me.com>

ref #377
  • Loading branch information
Cxom committed May 22, 2021
1 parent 94ce70e commit 10b7fd1
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public final class NamedTextColor implements TextColor {
*/
private static float distance(final @NonNull HSVLike self, final @NonNull HSVLike other) {
// weight hue more heavily than saturation and brightness. kind of magic numbers, but is fine for our use case of downsampling to a set of colors
final float hueDistance = 3 * Math.abs(self.h() - other.h());
final float hueDistance = 3 * Math.min(Math.abs(self.h() - other.h()), 1f - Math.abs(self.h() - other.h()));
final float saturationDiff = self.s() - other.s();
final float valueDiff = self.v() - other.v();
return hueDistance * hueDistance + saturationDiff * saturationDiff + valueDiff * valueDiff;
Expand Down

0 comments on commit 10b7fd1

Please sign in to comment.