Skip to content

Commit 89dc41d

Browse files
committed
spoint_dwithin: Use FPle, add tests
1 parent 727f0dc commit 89dc41d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

expected/points.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,3 +666,19 @@ SELECT '( 0h 2m 30s , -90d 0m 0s)'::spoint<->'( 12h 2m 30s , -90d 0m 0s)'::spoin
666666
0
667667
(1 row)
668668

669+
-- spoint_dwithin function ----------
670+
SELECT a, b, radius, a <-> b AS "<->", spoint_dwithin(a, b, radius)
671+
FROM (VALUES
672+
('(0, 0)'::spoint, '(0, 0)'::spoint, 0),
673+
('(0, 0)', '(0, 1)', 1),
674+
('(0, 0)', '(0.1, 0.1)', 0.14),
675+
('(0, 0)', '(0.1, 0.1)', 0.15)
676+
) sub (a, b, radius);
677+
a | b | radius | <-> | spoint_dwithin
678+
---------+-------------+--------+-----------------+----------------
679+
(0 , 0) | (0 , 0) | 0 | 0 | t
680+
(0 , 0) | (0 , 1) | 1 | 1 | t
681+
(0 , 0) | (0.1 , 0.1) | 0.14 | 0.1413032986961 | f
682+
(0 , 0) | (0.1 , 0.1) | 0.15 | 0.1413032986961 | t
683+
(4 rows)
684+

sql/points.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,12 @@ SELECT '( 0h 2m 30s , 90d 0m 0s)'::spoint<->'( 12h 2m 30s , 90d 0m 0s)'::spoint;
240240

241241
SELECT '( 0h 2m 30s , -90d 0m 0s)'::spoint<->'( 12h 2m 30s , -90d 0m 0s)'::spoint;
242242

243+
-- spoint_dwithin function ----------
244+
245+
SELECT a, b, radius, a <-> b AS "<->", spoint_dwithin(a, b, radius)
246+
FROM (VALUES
247+
('(0, 0)'::spoint, '(0, 0)'::spoint, 0),
248+
('(0, 0)', '(0, 1)', 1),
249+
('(0, 0)', '(0.1, 0.1)', 0.14),
250+
('(0, 0)', '(0.1, 0.1)', 0.15)
251+
) sub (a, b, radius);

src/point.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ spherepoint_dwithin(PG_FUNCTION_ARGS)
232232
float8 within = PG_GETARG_FLOAT8(2);
233233
float8 dist = spoint_dist(p1, p2);
234234

235-
PG_RETURN_BOOL(dist <= within);
235+
PG_RETURN_BOOL(FPle(dist, within));
236236
}
237237

238238

0 commit comments

Comments
 (0)