PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ gserialized_gist_penalty()

Datum gserialized_gist_penalty ( PG_FUNCTION_ARGS  )

Definition at line 1343 of file gserialized_gist_nd.c.

References gidx_edge(), gidx_union_edge(), gidx_union_volume(), gidx_volume(), gserialized_gist_union(), pack_float(), and PG_FUNCTION_INFO_V1().

Referenced by gserialized_gist_picksplit_constructsplit(), and pack_float().

1344 {
1345  GISTENTRY *origentry = (GISTENTRY*) PG_GETARG_POINTER(0);
1346  GISTENTRY *newentry = (GISTENTRY*) PG_GETARG_POINTER(1);
1347  float *result = (float*) PG_GETARG_POINTER(2);
1348  GIDX *gbox_index_orig, *gbox_index_new;
1349  float size_union, size_orig, edge_union, edge_orig;
1350 
1351  POSTGIS_DEBUG(4, "[GIST] 'penalty' function called");
1352 
1353  gbox_index_orig = (GIDX*)DatumGetPointer(origentry->key);
1354  gbox_index_new = (GIDX*)DatumGetPointer(newentry->key);
1355 
1356  /* Drop out if we're dealing with null inputs. Shouldn't happen. */
1357  if ( (gbox_index_orig == NULL) && (gbox_index_new == NULL) )
1358  {
1359  POSTGIS_DEBUG(4, "[GIST] both inputs NULL! returning penalty of zero");
1360  *result = 0.0;
1361  PG_RETURN_FLOAT8(*result);
1362  }
1363 
1364  /* Calculate the size difference of the boxes (volume difference in this case). */
1365  size_union = gidx_union_volume(gbox_index_orig, gbox_index_new);
1366  size_orig = gidx_volume(gbox_index_orig);
1367  *result = size_union - size_orig;
1368 
1369  /* REALM 0: No extension is required, volume is zero, return edge */
1370  /* REALM 1: No extension is required, return nonzero area */
1371  /* REALM 2: Area extension is zero, return nonzero edge extension */
1372  /* REALM 3: Area extension is nonzero, return it */
1373 
1374  if( *result == 0 )
1375  {
1376  if (size_orig > 0)
1377  {
1378  *result = pack_float(size_orig, 1); /* REALM 1 */
1379  }
1380  else
1381  {
1382  edge_union = gidx_union_edge(gbox_index_orig, gbox_index_new);
1383  edge_orig = gidx_edge(gbox_index_orig);
1384  *result = edge_union - edge_orig;
1385  if( *result == 0 )
1386  {
1387  *result = pack_float(edge_orig, 0); /* REALM 0 */
1388  }
1389  else
1390  {
1391  *result = pack_float(*result, 2); /* REALM 2 */
1392  }
1393  }
1394  }
1395  else
1396  {
1397  *result = pack_float(*result, 3); /* REALM 3 */
1398  }
1399 
1400  POSTGIS_DEBUGF(4, "[GIST] union size (%.12f), original size (%.12f), penalty (%.12f)", size_union, size_orig, *result);
1401 
1402  PG_RETURN_POINTER(result);
1403 }
static float gidx_union_edge(GIDX *a, GIDX *b)
static float gidx_volume(GIDX *a)
static float gidx_union_volume(GIDX *a, GIDX *b)
static float pack_float(const float value, const int realm)
static float gidx_edge(GIDX *a)
Here is the call graph for this function:
Here is the caller graph for this function: