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:
parent
5f95f895d2
commit
6028bb419e
18
img2cpi.c
18
img2cpi.c
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue