111 uint32_t p1 = 0, p2 = 0;
113 uint32_t duplicate_count = 1;
114 double max_dst = -1, current_distance;
115 double dst_p1, dst_p2;
121 for (i = 1; i < n; i++)
126 if ((dst_p1 > max_dst) || (dst_p2 > max_dst))
139 if ((dst_p1 == 0) || (dst_p2 == 0))
142 if (duplicate_count > 1)
144 "%s: there are at least %u duplicate inputs, number of output clusters may be less than you requested",
149 assert(p1 != p2 && max_dst >= 0);
152 centers[0] = objs[p1];
153 centers[1] = objs[p2];
158 distances =
lwalloc(
sizeof(
double) * n);
161 for (j = 0; j < n; j++)
167 for (i = 2; i < k; i++)
169 uint32_t candidate_center = 0;
170 double max_distance = -DBL_MAX;
173 for (j = 0; j < n; j++)
176 if (distances[j] < 0)
181 if (current_distance < distances[j])
182 distances[j] = current_distance;
185 if (distances[j] > max_distance)
187 candidate_center = j;
188 max_distance = distances[j];
193 assert(max_distance >= 0);
196 distances[candidate_center] = -1;
199 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)