178 uint32_t p1 = 0, p2 = 0;
179 uint32_t duplicate_count = 1;
186 centers[0] = objs[0];
191 for (uint32_t i = 1; i < n; i++)
196 if ((dst_p1 > max_dst) || (dst_p2 > max_dst))
209 if ((dst_p1 == 0) || (dst_p2 == 0))
212 if (duplicate_count > 1)
214 "%s: there are at least %u duplicate inputs, number of output clusters may be less than you requested",
219 assert(p1 != p2 && max_dst >= 0);
222 centers[0] = objs[p1];
223 centers[1] = objs[p2];
228 distances =
lwalloc(
sizeof(
double) * n);
231 for (uint32_t j = 0; j < n; j++)
237 for (uint32_t i = 2; i < k; i++)
239 uint32_t candidate_center = 0;
240 double max_distance = -DBL_MAX;
243 for (uint32_t j = 0; j < n; j++)
246 if (distances[j] < 0)
251 if (current_distance < distances[j])
252 distances[j] = current_distance;
255 if (distances[j] > max_distance)
257 candidate_center = j;
258 max_distance = distances[j];
263 assert(max_distance >= 0);
266 distances[candidate_center] = -1;
269 centers[i] = objs[candidate_center];
void * lwalloc(size_t size)
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
static double distance3d_sqr_pt4d_pt4d(const POINT4D *p1, const POINT4D *p2)