Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6254c55

Browse files
committed
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 thoseoperators.Discussion:https://postgr.es/m/f71ba19d-d989-63b6-f04a-abf02ad9345d%40postgrespro.ruAuthor: Nikita GlukhovReviewed-by: Tom Lane, Alexander Korotkov
1 parent6e74c64 commit6254c55

File tree

5 files changed

+687
-517
lines changed

5 files changed

+687
-517
lines changed

‎src/backend/utils/adt/geo_ops.c

Lines changed: 126 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,6 +2348,17 @@ dist_pl(PG_FUNCTION_ARGS)
23482348
PG_RETURN_FLOAT8(line_closept_point(NULL,line,pt));
23492349
}
23502350

2351+
/*
2352+
* Distance from a line to a point
2353+
*/
2354+
Datum
2355+
dist_lp(PG_FUNCTION_ARGS)
2356+
{
2357+
LINE*line=PG_GETARG_LINE_P(0);
2358+
Point*pt=PG_GETARG_POINT_P(1);
2359+
2360+
PG_RETURN_FLOAT8(line_closept_point(NULL,line,pt));
2361+
}
23512362

23522363
/*
23532364
* Distance from a point to a lseg
@@ -2362,13 +2373,20 @@ dist_ps(PG_FUNCTION_ARGS)
23622373
}
23632374

23642375
/*
2365-
* Distance from apoint to apath
2376+
* Distance from alseg to apoint
23662377
*/
23672378
Datum
2368-
dist_ppath(PG_FUNCTION_ARGS)
2379+
dist_sp(PG_FUNCTION_ARGS)
2380+
{
2381+
LSEG*lseg=PG_GETARG_LSEG_P(0);
2382+
Point*pt=PG_GETARG_POINT_P(1);
2383+
2384+
PG_RETURN_FLOAT8(lseg_closept_point(NULL,lseg,pt));
2385+
}
2386+
2387+
staticfloat8
2388+
dist_ppath_internal(Point*pt,PATH*path)
23692389
{
2370-
Point*pt=PG_GETARG_POINT_P(0);
2371-
PATH*path=PG_GETARG_PATH_P(1);
23722390
float8result=0.0;/* keep compiler quiet */
23732391
boolhave_min= false;
23742392
float8tmp;
@@ -2403,7 +2421,31 @@ dist_ppath(PG_FUNCTION_ARGS)
24032421
}
24042422
}
24052423

2406-
PG_RETURN_FLOAT8(result);
2424+
returnresult;
2425+
}
2426+
2427+
/*
2428+
* Distance from a point to a path
2429+
*/
2430+
Datum
2431+
dist_ppath(PG_FUNCTION_ARGS)
2432+
{
2433+
Point*pt=PG_GETARG_POINT_P(0);
2434+
PATH*path=PG_GETARG_PATH_P(1);
2435+
2436+
PG_RETURN_FLOAT8(dist_ppath_internal(pt,path));
2437+
}
2438+
2439+
/*
2440+
* Distance from a path to a point
2441+
*/
2442+
Datum
2443+
dist_pathp(PG_FUNCTION_ARGS)
2444+
{
2445+
PATH*path=PG_GETARG_PATH_P(0);
2446+
Point*pt=PG_GETARG_POINT_P(1);
2447+
2448+
PG_RETURN_FLOAT8(dist_ppath_internal(pt,path));
24072449
}
24082450

24092451
/*
@@ -2418,6 +2460,18 @@ dist_pb(PG_FUNCTION_ARGS)
24182460
PG_RETURN_FLOAT8(box_closept_point(NULL,box,pt));
24192461
}
24202462

2463+
/*
2464+
* Distance from a box to a point
2465+
*/
2466+
Datum
2467+
dist_bp(PG_FUNCTION_ARGS)
2468+
{
2469+
BOX*box=PG_GETARG_BOX_P(0);
2470+
Point*pt=PG_GETARG_POINT_P(1);
2471+
2472+
PG_RETURN_FLOAT8(box_closept_point(NULL,box,pt));
2473+
}
2474+
24212475
/*
24222476
* Distance from a lseg to a line
24232477
*/
@@ -2430,6 +2484,18 @@ dist_sl(PG_FUNCTION_ARGS)
24302484
PG_RETURN_FLOAT8(lseg_closept_line(NULL,lseg,line));
24312485
}
24322486

2487+
/*
2488+
* Distance from a line to a lseg
2489+
*/
2490+
Datum
2491+
dist_ls(PG_FUNCTION_ARGS)
2492+
{
2493+
LINE*line=PG_GETARG_LINE_P(0);
2494+
LSEG*lseg=PG_GETARG_LSEG_P(1);
2495+
2496+
PG_RETURN_FLOAT8(lseg_closept_line(NULL,lseg,line));
2497+
}
2498+
24332499
/*
24342500
* Distance from a lseg to a box
24352501
*/
@@ -2442,6 +2508,18 @@ dist_sb(PG_FUNCTION_ARGS)
24422508
PG_RETURN_FLOAT8(box_closept_lseg(NULL,box,lseg));
24432509
}
24442510

2511+
/*
2512+
* Distance from a box to a lseg
2513+
*/
2514+
Datum
2515+
dist_bs(PG_FUNCTION_ARGS)
2516+
{
2517+
BOX*box=PG_GETARG_BOX_P(0);
2518+
LSEG*lseg=PG_GETARG_LSEG_P(1);
2519+
2520+
PG_RETURN_FLOAT8(box_closept_lseg(NULL,box,lseg));
2521+
}
2522+
24452523
/*
24462524
* Distance from a line to a box
24472525
*/
@@ -2462,13 +2540,27 @@ dist_lb(PG_FUNCTION_ARGS)
24622540
}
24632541

24642542
/*
2465-
* Distance from acircle to apolygon
2543+
* Distance from abox to aline
24662544
*/
24672545
Datum
2468-
dist_cpoly(PG_FUNCTION_ARGS)
2546+
dist_bl(PG_FUNCTION_ARGS)
2547+
{
2548+
#ifdefNOT_USED
2549+
BOX*box=PG_GETARG_BOX_P(0);
2550+
LINE*line=PG_GETARG_LINE_P(1);
2551+
#endif
2552+
2553+
/* need to think about this one for a while */
2554+
ereport(ERROR,
2555+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2556+
errmsg("function \"dist_bl\" not implemented")));
2557+
2558+
PG_RETURN_NULL();
2559+
}
2560+
2561+
staticfloat8
2562+
dist_cpoly_internal(CIRCLE*circle,POLYGON*poly)
24692563
{
2470-
CIRCLE*circle=PG_GETARG_CIRCLE_P(0);
2471-
POLYGON*poly=PG_GETARG_POLYGON_P(1);
24722564
float8result;
24732565

24742566
/* calculate distance to center, and subtract radius */
@@ -2477,7 +2569,31 @@ dist_cpoly(PG_FUNCTION_ARGS)
24772569
if (result<0.0)
24782570
result=0.0;
24792571

2480-
PG_RETURN_FLOAT8(result);
2572+
returnresult;
2573+
}
2574+
2575+
/*
2576+
* Distance from a circle to a polygon
2577+
*/
2578+
Datum
2579+
dist_cpoly(PG_FUNCTION_ARGS)
2580+
{
2581+
CIRCLE*circle=PG_GETARG_CIRCLE_P(0);
2582+
POLYGON*poly=PG_GETARG_POLYGON_P(1);
2583+
2584+
PG_RETURN_FLOAT8(dist_cpoly_internal(circle,poly));
2585+
}
2586+
2587+
/*
2588+
* Distance from a polygon to a circle
2589+
*/
2590+
Datum
2591+
dist_polyc(PG_FUNCTION_ARGS)
2592+
{
2593+
POLYGON*poly=PG_GETARG_POLYGON_P(0);
2594+
CIRCLE*circle=PG_GETARG_CIRCLE_P(1);
2595+
2596+
PG_RETURN_FLOAT8(dist_cpoly_internal(circle,poly));
24812597
}
24822598

24832599
/*

‎src/include/catalog/pg_operator.dat

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -660,22 +660,40 @@
660660

661661
{ oid => '613', descr => 'distance between',
662662
oprname => '<->', oprleft => 'point', oprright => 'line',
663-
oprresult => 'float8', oprcode => 'dist_pl' },
663+
oprresult => 'float8', oprcom => '<->(line,point)',oprcode => 'dist_pl' },
664+
{ oid => '760', descr => 'distance between',
665+
oprname => '<->', oprleft => 'line', oprright => 'point',
666+
oprresult => 'float8', oprcom => '<->(point,line)', oprcode => 'dist_lp' },
664667
{ oid => '614', descr => 'distance between',
665668
oprname => '<->', oprleft => 'point', oprright => 'lseg',
666-
oprresult => 'float8', oprcode => 'dist_ps' },
669+
oprresult => 'float8', oprcom => '<->(lseg,point)',oprcode => 'dist_ps' },
670+
{ oid => '761', descr => 'distance between',
671+
oprname => '<->', oprleft => 'lseg', oprright => 'point',
672+
oprresult => 'float8', oprcom => '<->(point,lseg)', oprcode => 'dist_sp' },
667673
{ oid => '615', descr => 'distance between',
668674
oprname => '<->', oprleft => 'point', oprright => 'box',
669-
oprresult => 'float8', oprcode => 'dist_pb' },
675+
oprresult => 'float8', oprcom => '<->(box,point)', oprcode => 'dist_pb' },
676+
{ oid => '606', descr => 'distance between',
677+
oprname => '<->', oprleft => 'box', oprright => 'point',
678+
oprresult => 'float8', oprcom => '<->(point,box)', oprcode => 'dist_bp' },
670679
{ oid => '616', descr => 'distance between',
671680
oprname => '<->', oprleft => 'lseg', oprright => 'line',
672-
oprresult => 'float8', oprcode => 'dist_sl' },
681+
oprresult => 'float8', oprcom => '<->(line,lseg)', oprcode => 'dist_sl' },
682+
{ oid => '762', descr => 'distance between',
683+
oprname => '<->', oprleft => 'line', oprright => 'lseg',
684+
oprresult => 'float8', oprcom => '<->(lseg,line)', oprcode => 'dist_ls' },
673685
{ oid => '617', descr => 'distance between',
674686
oprname => '<->', oprleft => 'lseg', oprright => 'box', oprresult => 'float8',
675-
oprcode => 'dist_sb' },
687+
oprcom => '<->(box,lseg)', oprcode => 'dist_sb' },
688+
{ oid => '763', descr => 'distance between',
689+
oprname => '<->', oprleft => 'box', oprright => 'lseg', oprresult => 'float8',
690+
oprcom => '<->(lseg,box)', oprcode => 'dist_bs' },
676691
{ oid => '618', descr => 'distance between',
677692
oprname => '<->', oprleft => 'point', oprright => 'path',
678-
oprresult => 'float8', oprcode => 'dist_ppath' },
693+
oprresult => 'float8', oprcom => '<->(path,point)', oprcode => 'dist_ppath' },
694+
{ oid => '784', descr => 'distance between',
695+
oprname => '<->', oprleft => 'path', oprright => 'point',
696+
oprresult => 'float8', oprcom => '<->(point,path)', oprcode => 'dist_pathp' },
679697

680698
{ oid => '620', descr => 'equal',
681699
oprname => '=', oprcanmerge => 't', oprcanhash => 't', oprleft => 'float4',
@@ -1692,12 +1710,20 @@
16921710
oprcode => 'dist_polyp' },
16931711
{ oid => '1523', descr => 'distance between',
16941712
oprname => '<->', oprleft => 'circle', oprright => 'polygon',
1695-
oprresult => 'float8', oprcode => 'dist_cpoly' },
1713+
oprresult => 'float8', oprcom => '<->(polygon,circle)',
1714+
oprcode => 'dist_cpoly' },
1715+
{ oid => '1383', descr => 'distance between',
1716+
oprname => '<->', oprleft => 'polygon', oprright => 'circle',
1717+
oprresult => 'float8', oprcom => '<->(circle,polygon)',
1718+
oprcode => 'dist_polyc' },
16961719

16971720
# additional geometric operators - thomas 1997-07-09
16981721
{ oid => '1524', descr => 'distance between',
16991722
oprname => '<->', oprleft => 'line', oprright => 'box', oprresult => 'float8',
1700-
oprcode => 'dist_lb' },
1723+
oprcom => '<->(box,line)', oprcode => 'dist_lb' },
1724+
{ oid => '1382', descr => 'distance between',
1725+
oprname => '<->', oprleft => 'box', oprright => 'line', oprresult => 'float8',
1726+
oprcom => '<->(line,box)', oprcode => 'dist_bl' },
17011727

17021728
{ oid => '1525', descr => 'intersect',
17031729
oprname => '?#', oprleft => 'lseg', oprright => 'lseg', oprresult => 'bool',

‎src/include/catalog/pg_proc.dat

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,12 +1062,21 @@
10621062
{ oid => '363',
10631063
proname => 'dist_ps', prorettype => 'float8', proargtypes => 'point lseg',
10641064
prosrc => 'dist_ps' },
1065+
{ oid => '380',
1066+
proname => 'dist_sp', prorettype => 'float8', proargtypes => 'lseg point',
1067+
prosrc => 'dist_sp' },
10651068
{ oid => '364',
10661069
proname => 'dist_pb', prorettype => 'float8', proargtypes => 'point box',
10671070
prosrc => 'dist_pb' },
1071+
{ oid => '357',
1072+
proname => 'dist_bp', prorettype => 'float8', proargtypes => 'box point',
1073+
prosrc => 'dist_bp' },
10681074
{ oid => '365',
10691075
proname => 'dist_sb', prorettype => 'float8', proargtypes => 'lseg box',
10701076
prosrc => 'dist_sb' },
1077+
{ oid => '381',
1078+
proname => 'dist_bs', prorettype => 'float8', proargtypes => 'box lseg',
1079+
prosrc => 'dist_bs' },
10711080
{ oid => '366',
10721081
proname => 'close_ps', prorettype => 'point', proargtypes => 'point lseg',
10731082
prosrc => 'close_ps' },
@@ -1086,6 +1095,9 @@
10861095
{ oid => '371',
10871096
proname => 'dist_ppath', prorettype => 'float8', proargtypes => 'point path',
10881097
prosrc => 'dist_ppath' },
1098+
{ oid => '421',
1099+
proname => 'dist_pathp', prorettype => 'float8', proargtypes => 'path point',
1100+
prosrc => 'dist_pathp' },
10891101
{ oid => '372',
10901102
proname => 'on_sb', prorettype => 'bool', proargtypes => 'lseg box',
10911103
prosrc => 'on_sb' },
@@ -1403,15 +1415,28 @@
14031415
{ oid => '725',
14041416
proname => 'dist_pl', prorettype => 'float8', proargtypes => 'point line',
14051417
prosrc => 'dist_pl' },
1418+
{ oid => '702',
1419+
proname => 'dist_lp', prorettype => 'float8', proargtypes => 'line point',
1420+
prosrc => 'dist_lp' },
14061421
{ oid => '726',
14071422
proname => 'dist_lb', prorettype => 'float8', proargtypes => 'line box',
14081423
prosrc => 'dist_lb' },
1424+
{ oid => '703',
1425+
proname => 'dist_bl', prorettype => 'float8', proargtypes => 'box line',
1426+
prosrc => 'dist_bl' },
14091427
{ oid => '727',
14101428
proname => 'dist_sl', prorettype => 'float8', proargtypes => 'lseg line',
14111429
prosrc => 'dist_sl' },
1430+
{ oid => '704',
1431+
proname => 'dist_ls', prorettype => 'float8', proargtypes => 'line lseg',
1432+
prosrc => 'dist_ls' },
1433+
14121434
{ oid => '728',
14131435
proname => 'dist_cpoly', prorettype => 'float8',
14141436
proargtypes => 'circle polygon', prosrc => 'dist_cpoly' },
1437+
{ oid => '785',
1438+
proname => 'dist_polyc', prorettype => 'float8',
1439+
proargtypes => 'polygon circle', prosrc => 'dist_polyc' },
14151440
{ oid => '729',
14161441
proname => 'poly_distance', prorettype => 'float8',
14171442
proargtypes => 'polygon polygon', prosrc => 'poly_distance' },

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp