forked from hkc/cc-stuff
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
14
img2cpi.c
14
img2cpi.c
|
@ -711,11 +711,23 @@ bool k_means_iteration(struct k_means_state *state) {
|
|||
closest_distance = dist;
|
||||
closest_cluster = cluster;
|
||||
}
|
||||
if (dist <= state->centroid_intermediate[cluster].closest_present_distance) {
|
||||
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) {
|
||||
changed = state->predicted_cluster[i] != closest_cluster;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue