PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ update_r()

static uint8_t update_r ( POINT4D objs,
uint32_t *  clusters,
uint32_t  n,
POINT4D centers,
double *  radii,
uint32_t  k 
)
static

Definition at line 109 of file lwkmeans.c.

110 {
111  uint8_t converged = LW_TRUE;
112  if (radii)
113  memset(radii, 0, sizeof(double) * k);
114 
115  for (uint32_t i = 0; i < n; i++)
116  {
117  POINT4D obj = objs[i];
118 
119  /* Initialize with distance to first cluster */
120  double curr_distance = distance3d_sqr_pt4d_pt4d(&obj, &centers[0]);
121  uint32_t curr_cluster = 0;
122 
123  /* Check all other cluster centers and find the nearest */
124  for (uint32_t cluster = 1; cluster < k; cluster++)
125  {
126  double distance = distance3d_sqr_pt4d_pt4d(&obj, &centers[cluster]);
127  if (distance < curr_distance)
128  {
129  curr_distance = distance;
130  curr_cluster = cluster;
131  }
132  }
133 
134  /* Store the nearest cluster this object is in */
135  if (clusters[i] != curr_cluster)
136  {
137  converged = LW_FALSE;
138  clusters[i] = curr_cluster;
139  }
140  if (radii)
141  if (radii[curr_cluster] < curr_distance)
142  radii[curr_cluster] = curr_distance;
143  }
144  return converged;
145 }
#define LW_FALSE
Definition: liblwgeom.h:94
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
static double distance3d_sqr_pt4d_pt4d(const POINT4D *p1, const POINT4D *p2)
Definition: lwkmeans.c:31
static double distance(double x1, double y1, double x2, double y2)
Definition: lwtree.c:1032

References distance(), distance3d_sqr_pt4d_pt4d(), LW_FALSE, and LW_TRUE.

Referenced by kmeans().

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