mirror of
https://github.com/postgres/postgres.git
synced 2025-09-08 00:47:37 +03:00
Add missing commutators for distance operators
Some of <-> operators between geometric types have their commutators missed. This commit adds them. The motivation is upcoming kNN support for some of those operators. Discussion: https://postgr.es/m/f71ba19d-d989-63b6-f04a-abf02ad9345d%40postgrespro.ru Author: Nikita Glukhov Reviewed-by: Tom Lane, Alexander Korotkov
This commit is contained in:
@@ -2348,6 +2348,17 @@ dist_pl(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_FLOAT8(line_closept_point(NULL, line, pt));
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a line to a point
|
||||
*/
|
||||
Datum
|
||||
dist_lp(PG_FUNCTION_ARGS)
|
||||
{
|
||||
LINE *line = PG_GETARG_LINE_P(0);
|
||||
Point *pt = PG_GETARG_POINT_P(1);
|
||||
|
||||
PG_RETURN_FLOAT8(line_closept_point(NULL, line, pt));
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a point to a lseg
|
||||
@@ -2362,13 +2373,20 @@ dist_ps(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a point to a path
|
||||
* Distance from a lseg to a point
|
||||
*/
|
||||
Datum
|
||||
dist_ppath(PG_FUNCTION_ARGS)
|
||||
dist_sp(PG_FUNCTION_ARGS)
|
||||
{
|
||||
LSEG *lseg = PG_GETARG_LSEG_P(0);
|
||||
Point *pt = PG_GETARG_POINT_P(1);
|
||||
|
||||
PG_RETURN_FLOAT8(lseg_closept_point(NULL, lseg, pt));
|
||||
}
|
||||
|
||||
static float8
|
||||
dist_ppath_internal(Point *pt, PATH *path)
|
||||
{
|
||||
Point *pt = PG_GETARG_POINT_P(0);
|
||||
PATH *path = PG_GETARG_PATH_P(1);
|
||||
float8 result = 0.0; /* keep compiler quiet */
|
||||
bool have_min = false;
|
||||
float8 tmp;
|
||||
@@ -2403,7 +2421,31 @@ dist_ppath(PG_FUNCTION_ARGS)
|
||||
}
|
||||
}
|
||||
|
||||
PG_RETURN_FLOAT8(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a point to a path
|
||||
*/
|
||||
Datum
|
||||
dist_ppath(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Point *pt = PG_GETARG_POINT_P(0);
|
||||
PATH *path = PG_GETARG_PATH_P(1);
|
||||
|
||||
PG_RETURN_FLOAT8(dist_ppath_internal(pt, path));
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a path to a point
|
||||
*/
|
||||
Datum
|
||||
dist_pathp(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PATH *path = PG_GETARG_PATH_P(0);
|
||||
Point *pt = PG_GETARG_POINT_P(1);
|
||||
|
||||
PG_RETURN_FLOAT8(dist_ppath_internal(pt, path));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2418,6 +2460,18 @@ dist_pb(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_FLOAT8(box_closept_point(NULL, box, pt));
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a box to a point
|
||||
*/
|
||||
Datum
|
||||
dist_bp(PG_FUNCTION_ARGS)
|
||||
{
|
||||
BOX *box = PG_GETARG_BOX_P(0);
|
||||
Point *pt = PG_GETARG_POINT_P(1);
|
||||
|
||||
PG_RETURN_FLOAT8(box_closept_point(NULL, box, pt));
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a lseg to a line
|
||||
*/
|
||||
@@ -2430,6 +2484,18 @@ dist_sl(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_FLOAT8(lseg_closept_line(NULL, lseg, line));
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a line to a lseg
|
||||
*/
|
||||
Datum
|
||||
dist_ls(PG_FUNCTION_ARGS)
|
||||
{
|
||||
LINE *line = PG_GETARG_LINE_P(0);
|
||||
LSEG *lseg = PG_GETARG_LSEG_P(1);
|
||||
|
||||
PG_RETURN_FLOAT8(lseg_closept_line(NULL, lseg, line));
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a lseg to a box
|
||||
*/
|
||||
@@ -2442,6 +2508,18 @@ dist_sb(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_FLOAT8(box_closept_lseg(NULL, box, lseg));
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a box to a lseg
|
||||
*/
|
||||
Datum
|
||||
dist_bs(PG_FUNCTION_ARGS)
|
||||
{
|
||||
BOX *box = PG_GETARG_BOX_P(0);
|
||||
LSEG *lseg = PG_GETARG_LSEG_P(1);
|
||||
|
||||
PG_RETURN_FLOAT8(box_closept_lseg(NULL, box, lseg));
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a line to a box
|
||||
*/
|
||||
@@ -2462,13 +2540,27 @@ dist_lb(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a circle to a polygon
|
||||
* Distance from a box to a line
|
||||
*/
|
||||
Datum
|
||||
dist_cpoly(PG_FUNCTION_ARGS)
|
||||
dist_bl(PG_FUNCTION_ARGS)
|
||||
{
|
||||
#ifdef NOT_USED
|
||||
BOX *box = PG_GETARG_BOX_P(0);
|
||||
LINE *line = PG_GETARG_LINE_P(1);
|
||||
#endif
|
||||
|
||||
/* need to think about this one for a while */
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("function \"dist_bl\" not implemented")));
|
||||
|
||||
PG_RETURN_NULL();
|
||||
}
|
||||
|
||||
static float8
|
||||
dist_cpoly_internal(CIRCLE *circle, POLYGON *poly)
|
||||
{
|
||||
CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
|
||||
POLYGON *poly = PG_GETARG_POLYGON_P(1);
|
||||
float8 result;
|
||||
|
||||
/* calculate distance to center, and subtract radius */
|
||||
@@ -2477,7 +2569,31 @@ dist_cpoly(PG_FUNCTION_ARGS)
|
||||
if (result < 0.0)
|
||||
result = 0.0;
|
||||
|
||||
PG_RETURN_FLOAT8(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a circle to a polygon
|
||||
*/
|
||||
Datum
|
||||
dist_cpoly(PG_FUNCTION_ARGS)
|
||||
{
|
||||
CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
|
||||
POLYGON *poly = PG_GETARG_POLYGON_P(1);
|
||||
|
||||
PG_RETURN_FLOAT8(dist_cpoly_internal(circle, poly));
|
||||
}
|
||||
|
||||
/*
|
||||
* Distance from a polygon to a circle
|
||||
*/
|
||||
Datum
|
||||
dist_polyc(PG_FUNCTION_ARGS)
|
||||
{
|
||||
POLYGON *poly = PG_GETARG_POLYGON_P(0);
|
||||
CIRCLE *circle = PG_GETARG_CIRCLE_P(1);
|
||||
|
||||
PG_RETURN_FLOAT8(dist_cpoly_internal(circle, poly));
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user