PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ gserialized_gist_penalty_2d()

Datum gserialized_gist_penalty_2d ( PG_FUNCTION_ARGS  )

Definition at line 1313 of file gserialized_gist_2d.c.

References box2df_edge(), box2df_size(), box2df_union_edge(), box2df_union_size(), gserialized_gist_union_2d(), pack_float(), and PG_FUNCTION_INFO_V1().

Referenced by pack_float().

1314 {
1315  GISTENTRY *origentry = (GISTENTRY*) PG_GETARG_POINTER(0);
1316  GISTENTRY *newentry = (GISTENTRY*) PG_GETARG_POINTER(1);
1317  float *result = (float*) PG_GETARG_POINTER(2);
1318  BOX2DF *gbox_index_orig, *gbox_index_new;
1319  float size_union, size_orig, edge_union, edge_orig;
1320 
1321  POSTGIS_DEBUG(4, "[GIST] 'penalty' function called");
1322 
1323  gbox_index_orig = (BOX2DF*)DatumGetPointer(origentry->key);
1324  gbox_index_new = (BOX2DF*)DatumGetPointer(newentry->key);
1325 
1326  /* Drop out if we're dealing with null inputs. Shouldn't happen. */
1327  if ( (gbox_index_orig == NULL) && (gbox_index_new == NULL) )
1328  {
1329  POSTGIS_DEBUG(4, "[GIST] both inputs NULL! returning penalty of zero");
1330  *result = 0.0;
1331  PG_RETURN_FLOAT8(*result);
1332  }
1333 
1334  /* Calculate the size difference of the boxes. */
1335  size_union = box2df_union_size(gbox_index_orig, gbox_index_new);
1336  size_orig = box2df_size(gbox_index_orig);
1337  *result = size_union - size_orig;
1338 
1339  /* REALM 0: No extension is required, volume is zero, return edge */
1340  /* REALM 1: No extension is required, return nonzero area */
1341  /* REALM 2: Area extension is zero, return nonzero edge extension */
1342  /* REALM 3: Area extension is nonzero, return it */
1343 
1344  if( *result == 0 )
1345  {
1346  if (size_orig > 0)
1347  {
1348  *result = pack_float(size_orig, 1); /* REALM 1 */
1349  }
1350  else
1351  {
1352  edge_union = box2df_union_edge(gbox_index_orig, gbox_index_new);
1353  edge_orig = box2df_edge(gbox_index_orig);
1354  *result = edge_union - edge_orig;
1355  if( *result == 0 )
1356  {
1357  *result = pack_float(edge_orig, 0); /* REALM 0 */
1358  }
1359  else
1360  {
1361  *result = pack_float(*result, 2); /* REALM 2 */
1362  }
1363  }
1364  }
1365  else
1366  {
1367  *result = pack_float(*result, 3); /* REALM 3 */
1368  }
1369 
1370  POSTGIS_DEBUGF(4, "[GIST] 'penalty', union size (%.12f), original size (%.12f), penalty (%.12f)", size_union, size_orig, *result);
1371 
1372  PG_RETURN_POINTER(result);
1373 }
static float box2df_union_edge(const BOX2DF *a, const BOX2DF *b)
static float box2df_size(const BOX2DF *a)
static float pack_float(const float value, const int realm)
static float box2df_union_size(const BOX2DF *a, const BOX2DF *b)
static float box2df_edge(const BOX2DF *a)
Here is the call graph for this function:
Here is the caller graph for this function: