1
0
Fork 0

Avoid duplicate palette entries

Don't make an item an empty cluster warp candidate, if it is already
warp candidate for another cluster
This commit is contained in:
Vftdan 2024-10-03 11:26:45 +02:00
parent 5f95f895d2
commit 6028bb419e
1 changed files with 15 additions and 3 deletions

View File

@ -711,9 +711,21 @@ bool k_means_iteration(struct k_means_state *state) {
closest_distance = dist;
closest_cluster = cluster;
}
if (dist <= state->centroid_intermediate[cluster].closest_present_distance) {
state->centroid_intermediate[cluster].closest_present_item = item;
state->centroid_intermediate[cluster].closest_present_distance = dist;
if (dist < state->centroid_intermediate[cluster].closest_present_distance) {
bool can_update = true;
for (int other_cluster = 0; other_cluster < state->clusters->count; other_cluster++) {
if (other_cluster == cluster) {
continue;
}
if (state->centroid_intermediate[other_cluster].closest_present_item.v == item.v) {
can_update = false;
break;
}
}
if (can_update) {
state->centroid_intermediate[cluster].closest_present_item = item;
state->centroid_intermediate[cluster].closest_present_distance = dist;
}
}
}
if (!changed) {