PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ update_r()

static void update_r ( POINT2D **  objs,
int *  clusters,
uint32_t  n,
POINT2D **  centers,
uint32_t  k 
)
static

Definition at line 23 of file lwkmeans.c.

24{
25 POINT2D* obj;
26 unsigned int i;
27 double distance, curr_distance;
28 uint32_t cluster, curr_cluster;
29
30 for (i = 0; i < n; i++)
31 {
32 obj = objs[i];
33
34 /* Don't try to cluster NULL objects, just add them to the "unclusterable cluster" */
35 if (!obj)
36 {
37 clusters[i] = KMEANS_NULL_CLUSTER;
38 continue;
39 }
40
41 /* Initialize with distance to first cluster */
42 curr_distance = distance2d_sqr_pt_pt(obj, centers[0]);
43 curr_cluster = 0;
44
45 /* Check all other cluster centers and find the nearest */
46 for (cluster = 1; cluster < k; cluster++)
47 {
48 distance = distance2d_sqr_pt_pt(obj, centers[cluster]);
49 if (distance < curr_distance)
50 {
51 curr_distance = distance;
52 curr_cluster = cluster;
53 }
54 }
55
56 /* Store the nearest cluster this object is in */
57 clusters[i] = (int) curr_cluster;
58 }
59}
static double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition lwinline.h:35
#define KMEANS_NULL_CLUSTER
Definition lwkmeans.c:14
static double distance(double x1, double y1, double x2, double y2)
Definition lwtree.c:1032

References distance(), distance2d_sqr_pt_pt(), and KMEANS_NULL_CLUSTER.

Referenced by kmeans().

Here is the call graph for this function:
Here is the caller graph for this function: