PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ gserialized_gist_distance_2d()

Datum gserialized_gist_distance_2d ( PG_FUNCTION_ARGS  )

Definition at line 1112 of file gserialized_gist_2d.c.

1113 {
1114  GISTENTRY *entry = (GISTENTRY*) PG_GETARG_POINTER(0);
1115  BOX2DF query_box;
1116  BOX2DF *entry_box;
1117  StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
1118  double distance;
1119  bool *recheck = (bool *) PG_GETARG_POINTER(4);
1120 
1121  POSTGIS_DEBUG(4, "[GIST] 'distance' function called");
1122 
1123  /* We are using '13' as the gist true-distance <-> strategy number
1124  * and '14' as the gist distance-between-boxes <#> strategy number */
1125  if ( strategy != 13 && strategy != 14 ) {
1126  elog(ERROR, "unrecognized strategy number: %d", strategy);
1127  PG_RETURN_FLOAT8(FLT_MAX);
1128  }
1129 
1130  /* Null box should never make this far. */
1131  if ( gserialized_datum_get_box2df_p(PG_GETARG_DATUM(1), &query_box) == LW_FAILURE )
1132  {
1133  POSTGIS_DEBUG(4, "[GIST] null query_gbox_index!");
1134  PG_RETURN_FLOAT8(FLT_MAX);
1135  }
1136 
1137  /* Get the entry box */
1138  entry_box = (BOX2DF*)DatumGetPointer(entry->key);
1139 
1140  /* Box-style distance test */
1141  if ( strategy == 14 ) /* operator <#> */
1142  {
1143  distance = box2df_distance(entry_box, &query_box);
1144  }
1145  /* True distance test (formerly centroid distance) */
1146  else if ( strategy == 13 ) /* operator <-> */
1147  {
1148  /* In all cases, since we only have keys (boxes) we'll return */
1149  /* the minimum possible distance, which is the box2df_distance */
1150  /* and let the recheck sort things out in the case of leaves */
1151  distance = box2df_distance(entry_box, &query_box);
1152 
1153  if (GIST_LEAF(entry))
1154  *recheck = true;
1155  }
1156  else
1157  {
1158  elog(ERROR, "%s: reached unreachable code", __func__);
1159  PG_RETURN_NULL();
1160  }
1161 
1162  PG_RETURN_FLOAT8(distance);
1163 }
static double box2df_distance(const BOX2DF *a, const BOX2DF *b)
Calculate the box->box distance.
int gserialized_datum_get_box2df_p(Datum gsdatum, BOX2DF *box2df)
#define LW_FAILURE
Definition: liblwgeom.h:110
static double distance(double x1, double y1, double x2, double y2)
Definition: lwtree.c:1032

References box2df_distance(), distance(), gserialized_datum_get_box2df_p(), and LW_FAILURE.

Here is the call graph for this function: