PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ gserialized_gist_distance_2d()

Datum gserialized_gist_distance_2d ( PG_FUNCTION_ARGS  )

Definition at line 1128 of file gserialized_gist_2d.c.

1129 {
1130  GISTENTRY *entry = (GISTENTRY*) PG_GETARG_POINTER(0);
1131  BOX2DF query_box;
1132  BOX2DF *entry_box;
1133  StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
1134  double distance;
1135  bool *recheck = (bool *) PG_GETARG_POINTER(4);
1136 
1137  POSTGIS_DEBUG(4, "[GIST] 'distance' function called");
1138 
1139  /* We are using '13' as the gist true-distance <-> strategy number
1140  * and '14' as the gist distance-between-boxes <#> strategy number */
1141  if ( strategy != 13 && strategy != 14 ) {
1142  elog(ERROR, "unrecognized strategy number: %d", strategy);
1143  PG_RETURN_FLOAT8(FLT_MAX);
1144  }
1145 
1146  /* Null box should never make this far. */
1147  if ( gserialized_datum_get_box2df_p(PG_GETARG_DATUM(1), &query_box) == LW_FAILURE )
1148  {
1149  POSTGIS_DEBUG(4, "[GIST] null query_gbox_index!");
1150  PG_RETURN_FLOAT8(FLT_MAX);
1151  }
1152 
1153  /* Get the entry box */
1154  entry_box = (BOX2DF*)DatumGetPointer(entry->key);
1155 
1156  /* Box-style distance test */
1157  if ( strategy == 14 ) /* operator <#> */
1158  {
1159  distance = box2df_distance(entry_box, &query_box);
1160  }
1161  /* True distance test (formerly centroid distance) */
1162  else if ( strategy == 13 ) /* operator <-> */
1163  {
1164  /* In all cases, since we only have keys (boxes) we'll return */
1165  /* the minimum possible distance, which is the box2df_distance */
1166  /* and let the recheck sort things out in the case of leaves */
1167  distance = box2df_distance(entry_box, &query_box);
1168 
1169  if (GIST_LEAF(entry))
1170  *recheck = true;
1171  }
1172  else
1173  {
1174  elog(ERROR, "%s: reached unreachable code", __func__);
1175  PG_RETURN_NULL();
1176  }
1177 
1178  PG_RETURN_FLOAT8(distance);
1179 }
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:96
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: