
as determined by include-what-you-use (IWYU) While IWYU also suggests to *add* a bunch of #include's (which is its main purpose), this patch does not do that. In some cases, a more specific #include replaces another less specific one. Some manual adjustments of the automatic result: - IWYU currently doesn't know about includes that provide global variable declarations (like -Wmissing-variable-declarations), so those includes are being kept manually. - All includes for port(ability) headers are being kept for now, to play it safe. - No changes of catalog/pg_foo.h to catalog/pg_foo_d.h, to keep the patch from exploding in size. Note that this patch touches just *.c files, so nothing declared in header files changes in hidden ways. As a small example, in src/backend/access/transam/rmgr.c, some IWYU pragma annotations are added to handle a special case there. Discussion: https://www.postgresql.org/message-id/flat/af837490-6b2f-46df-ba05-37ea6a6653fc%40eisentraut.org
89 lines
2.1 KiB
C
89 lines
2.1 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* spgproc.c
|
|
* Common supporting procedures for SP-GiST opclasses.
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* IDENTIFICATION
|
|
* src/backend/access/spgist/spgproc.c
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
#include <math.h>
|
|
|
|
#include "access/spgist_private.h"
|
|
#include "utils/float.h"
|
|
#include "utils/fmgrprotos.h"
|
|
#include "utils/geo_decls.h"
|
|
|
|
#define point_point_distance(p1,p2) \
|
|
DatumGetFloat8(DirectFunctionCall2(point_distance, \
|
|
PointPGetDatum(p1), PointPGetDatum(p2)))
|
|
|
|
/* Point-box distance in the assumption that box is aligned by axis */
|
|
static double
|
|
point_box_distance(Point *point, BOX *box)
|
|
{
|
|
double dx,
|
|
dy;
|
|
|
|
if (isnan(point->x) || isnan(box->low.x) ||
|
|
isnan(point->y) || isnan(box->low.y))
|
|
return get_float8_nan();
|
|
|
|
if (point->x < box->low.x)
|
|
dx = box->low.x - point->x;
|
|
else if (point->x > box->high.x)
|
|
dx = point->x - box->high.x;
|
|
else
|
|
dx = 0.0;
|
|
|
|
if (point->y < box->low.y)
|
|
dy = box->low.y - point->y;
|
|
else if (point->y > box->high.y)
|
|
dy = point->y - box->high.y;
|
|
else
|
|
dy = 0.0;
|
|
|
|
return HYPOT(dx, dy);
|
|
}
|
|
|
|
/*
|
|
* Returns distances from given key to array of ordering scan keys. Leaf key
|
|
* is expected to be point, non-leaf key is expected to be box. Scan key
|
|
* arguments are expected to be points.
|
|
*/
|
|
double *
|
|
spg_key_orderbys_distances(Datum key, bool isLeaf,
|
|
ScanKey orderbys, int norderbys)
|
|
{
|
|
int sk_num;
|
|
double *distances = (double *) palloc(norderbys * sizeof(double)),
|
|
*distance = distances;
|
|
|
|
for (sk_num = 0; sk_num < norderbys; ++sk_num, ++orderbys, ++distance)
|
|
{
|
|
Point *point = DatumGetPointP(orderbys->sk_argument);
|
|
|
|
*distance = isLeaf ? point_point_distance(point, DatumGetPointP(key))
|
|
: point_box_distance(point, DatumGetBoxP(key));
|
|
}
|
|
|
|
return distances;
|
|
}
|
|
|
|
BOX *
|
|
box_copy(BOX *orig)
|
|
{
|
|
BOX *result = palloc(sizeof(BOX));
|
|
|
|
*result = *orig;
|
|
return result;
|
|
}
|