Skip to content

Conversation

@Outfluencer
Copy link
Collaborator

Introducing the ChatColor#closestDefaultColor(java.awt.Color) Method

It computes the closest legacy default chatcolor (§1, §a, §e...) by using squared Euclidean distance calculation It can be very usefull if you just want to translate the new hex color back to old clients

Introducing the ChatColor#closestDefaultColor(java.awt.Color)
Method

It computes the closest legacy default chatcolor (§1, §a, §e...) by using squared Euclidean distance calculation
It can be very usefull if you just want to translate the new hex color back to old clients
@md-5
Copy link
Member

md-5 commented Sep 29, 2025

My suggestion: https://gist.github.com/Janmm14/c57dea617d33d6867ea34f8d8183c66e

What's the point of the static 3D array? Surely doesn't need to be static

@Janmm14
Copy link
Contributor

Janmm14 commented Sep 29, 2025

My suggestion: https://gist.github.com/Janmm14/c57dea617d33d6867ea34f8d8183c66e
@md-5
What's the point of the static 3D array? Surely doesn't need to be static

It was just a 2D array (size 16x3). That was just my first idea of making it more performant. I have since thought of even better optimizations, e.g. calculting the distance at which where can't be an other color nearer to abort early.

I won't bother creating a fixed 3D decision tree tho, if anyone wants to do that, feel free, its probably even faster.

Get rid of hashmap values toArray call, just precompute the array
@Outfluencer
Copy link
Collaborator Author

Outfluencer commented Sep 30, 2025

I guess more optimization just overcomplicates the simple task (jit will optimize it anyway), but the values() call was pretty heavy due to the hashmap, so i guess its fine to be precomputed

@Janmm14
Copy link
Contributor

Janmm14 commented Sep 30, 2025

Feel free to copy the corrected MAX_CLOSEST_COLOR_DIST_SQ optimization from my PR @Outfluencer, otherwise our PR's are now quite similar again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants