PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ gserialized_gist_penalty_2d()

Datum gserialized_gist_penalty_2d ( PG_FUNCTION_ARGS  )

Definition at line 1368 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().

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