PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ gserialized_gist_distance_2d()

Datum gserialized_gist_distance_2d ( PG_FUNCTION_ARGS  )

Definition at line 1147 of file gserialized_gist_2d.c.

1148{
1149 GISTENTRY *entry = (GISTENTRY*) PG_GETARG_POINTER(0);
1150 BOX2DF query_box;
1151 BOX2DF *entry_box;
1152 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
1153 double distance;
1154 bool *recheck = (bool *) PG_GETARG_POINTER(4);
1155
1156 POSTGIS_DEBUG(4, "[GIST] 'distance' function called");
1157
1158 /* We are using '13' as the gist true-distance <-> strategy number
1159 * and '14' as the gist distance-between-boxes <#> strategy number */
1160 if ( strategy != 13 && strategy != 14 ) {
1161 elog(ERROR, "unrecognized strategy number: %d", strategy);
1162 PG_RETURN_FLOAT8(FLT_MAX);
1163 }
1164
1165 /* Null box should never make this far. */
1166 if ( gserialized_datum_get_box2df_p(PG_GETARG_DATUM(1), &query_box) == LW_FAILURE )
1167 {
1168 POSTGIS_DEBUG(4, "[GIST] null query_gbox_index!");
1169 PG_RETURN_FLOAT8(FLT_MAX);
1170 }
1171
1172 /* Get the entry box */
1173 entry_box = (BOX2DF*)DatumGetPointer(entry->key);
1174
1175 /* Box-style distance test */
1176 if ( strategy == 14 ) /* operator <#> */
1177 {
1178 distance = box2df_distance(entry_box, &query_box);
1179 }
1180 /* True distance test (formerly centroid distance) */
1181 else if ( strategy == 13 ) /* operator <-> */
1182 {
1183 /* In all cases, since we only have keys (boxes) we'll return */
1184 /* the minimum possible distance, which is the box2df_distance */
1185 /* and let the recheck sort things out in the case of leaves */
1186 distance = box2df_distance(entry_box, &query_box);
1187
1188 if (GIST_LEAF(entry))
1189 *recheck = true;
1190 }
1191 else
1192 {
1193 elog(ERROR, "%s: reached unreachable code", __func__);
1194 PG_RETURN_NULL();
1195 }
1196
1197 PG_RETURN_FLOAT8(distance);
1198}
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: