PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ gserialized_gist_penalty_2d()

Datum gserialized_gist_penalty_2d ( PG_FUNCTION_ARGS  )

Definition at line 1377 of file gserialized_gist_2d.c.

1378 {
1379  GISTENTRY *origentry = (GISTENTRY*) PG_GETARG_POINTER(0);
1380  GISTENTRY *newentry = (GISTENTRY*) PG_GETARG_POINTER(1);
1381  float *result = (float*) PG_GETARG_POINTER(2);
1382  BOX2DF *gbox_index_orig, *gbox_index_new;
1383  float size_union, size_orig, edge_union, edge_orig;
1384 
1385  POSTGIS_DEBUG(4, "[GIST] 'penalty' function called");
1386 
1387  gbox_index_orig = (BOX2DF*)DatumGetPointer(origentry->key);
1388  gbox_index_new = (BOX2DF*)DatumGetPointer(newentry->key);
1389 
1390  /* Drop out if we're dealing with null inputs. Shouldn't happen. */
1391  if ( (gbox_index_orig == NULL) && (gbox_index_new == NULL) )
1392  {
1393  POSTGIS_DEBUG(4, "[GIST] both inputs NULL! returning penalty of zero");
1394  *result = 0.0;
1395  PG_RETURN_FLOAT8(*result);
1396  }
1397 
1398  /* Calculate the size difference of the boxes. */
1399  size_union = box2df_union_size(gbox_index_orig, gbox_index_new);
1400  size_orig = box2df_size(gbox_index_orig);
1401  *result = size_union - size_orig;
1402 
1403  /* REALM 0: No extension is required, volume is zero, return edge */
1404  /* REALM 1: No extension is required, return nonzero area */
1405  /* REALM 2: Area extension is zero, return nonzero edge extension */
1406  /* REALM 3: Area extension is nonzero, return it */
1407 
1408  if( *result == 0 )
1409  {
1410  if (size_orig > 0)
1411  {
1412  *result = pack_float(size_orig, 1); /* REALM 1 */
1413  }
1414  else
1415  {
1416  edge_union = box2df_union_edge(gbox_index_orig, gbox_index_new);
1417  edge_orig = box2df_edge(gbox_index_orig);
1418  *result = edge_union - edge_orig;
1419  if( *result == 0 )
1420  {
1421  *result = pack_float(edge_orig, 0); /* REALM 0 */
1422  }
1423  else
1424  {
1425  *result = pack_float(*result, 2); /* REALM 2 */
1426  }
1427  }
1428  }
1429  else
1430  {
1431  *result = pack_float(*result, 3); /* REALM 3 */
1432  }
1433 
1434  POSTGIS_DEBUGF(4, "[GIST] 'penalty', union size (%.12f), original size (%.12f), penalty (%.12f)", size_union, size_orig, *result);
1435 
1436  PG_RETURN_POINTER(result);
1437 }
static float box2df_size(const BOX2DF *a)
static float box2df_union_size(const BOX2DF *a, const BOX2DF *b)
static float pack_float(const float value, const int realm)
static float box2df_union_edge(const BOX2DF *a, const BOX2DF *b)
static float box2df_edge(const BOX2DF *a)

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

Here is the call graph for this function: