PostgreSQL Source Code  git master
spgproc.c File Reference
#include "postgres.h"
#include <math.h>
#include "access/spgist_private.h"
#include "utils/builtins.h"
#include "utils/float.h"
#include "utils/geo_decls.h"
Include dependency graph for spgproc.c:

Go to the source code of this file.

Macros

#define point_point_distance(p1, p2)
 

Functions

static double point_box_distance (Point *point, BOX *box)
 
double * spg_key_orderbys_distances (Datum key, bool isLeaf, ScanKey orderbys, int norderbys)
 
BOXbox_copy (BOX *orig)
 

Macro Definition Documentation

◆ point_point_distance

#define point_point_distance (   p1,
  p2 
)
Value:
Datum point_distance(PG_FUNCTION_ARGS)
Definition: geo_ops.c:1950
#define DatumGetFloat8(X)
Definition: postgres.h:728
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:619
#define PointPGetDatum(X)
Definition: geo_decls.h:135

Definition at line 25 of file spgproc.c.

Referenced by spg_key_orderbys_distances().

Function Documentation

◆ box_copy()

BOX* box_copy ( BOX orig)

Definition at line 82 of file spgproc.c.

References palloc().

Referenced by spg_kd_inner_consistent(), and spg_quad_inner_consistent().

83 {
84  BOX *result = palloc(sizeof(BOX));
85 
86  *result = *orig;
87  return result;
88 }
Definition: geo_decls.h:99
void * palloc(Size size)
Definition: mcxt.c:949

◆ point_box_distance()

static double point_box_distance ( Point point,
BOX box 
)
static

Definition at line 31 of file spgproc.c.

References get_float8_nan(), BOX::high, HYPOT, BOX::low, Point::x, and Point::y.

Referenced by spg_key_orderbys_distances().

32 {
33  double dx,
34  dy;
35 
36  if (isnan(point->x) || isnan(box->low.x) ||
37  isnan(point->y) || isnan(box->low.y))
38  return get_float8_nan();
39 
40  if (point->x < box->low.x)
41  dx = box->low.x - point->x;
42  else if (point->x > box->high.x)
43  dx = point->x - box->high.x;
44  else
45  dx = 0.0;
46 
47  if (point->y < box->low.y)
48  dy = box->low.y - point->y;
49  else if (point->y > box->high.y)
50  dy = point->y - box->high.y;
51  else
52  dy = 0.0;
53 
54  return HYPOT(dx, dy);
55 }
float8 x
Definition: geo_decls.h:57
static float8 get_float8_nan(void)
Definition: float.h:119
Point low
Definition: geo_decls.h:101
#define HYPOT(A, B)
Definition: geo_decls.h:50
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101

◆ spg_key_orderbys_distances()

double* spg_key_orderbys_distances ( Datum  key,
bool  isLeaf,
ScanKey  orderbys,
int  norderbys 
)

Definition at line 63 of file spgproc.c.

References DatumGetBoxP, DatumGetPointP, palloc(), point_box_distance(), and point_point_distance.

Referenced by spg_box_quad_leaf_consistent(), spg_kd_inner_consistent(), spg_quad_inner_consistent(), and spg_quad_leaf_consistent().

65 {
66  int sk_num;
67  double *distances = (double *) palloc(norderbys * sizeof(double)),
68  *distance = distances;
69 
70  for (sk_num = 0; sk_num < norderbys; ++sk_num, ++orderbys, ++distance)
71  {
72  Point *point = DatumGetPointP(orderbys->sk_argument);
73 
74  *distance = isLeaf ? point_point_distance(point, DatumGetPointP(key))
76  }
77 
78  return distances;
79 }
#define point_point_distance(p1, p2)
Definition: spgproc.c:25
#define DatumGetPointP(X)
Definition: geo_decls.h:134
#define DatumGetBoxP(X)
Definition: geo_decls.h:156
void * palloc(Size size)
Definition: mcxt.c:949
static double point_box_distance(Point *point, BOX *box)
Definition: spgproc.c:31