Skip to content

Commit

Permalink
spoint_dwithin: Use FPle, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
df7cb committed Oct 16, 2023
1 parent 727f0dc commit 89dc41d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
16 changes: 16 additions & 0 deletions expected/points.out
Original file line number Diff line number Diff line change
Expand Up @@ -666,3 +666,19 @@ SELECT '( 0h 2m 30s , -90d 0m 0s)'::spoint<->'( 12h 2m 30s , -90d 0m 0s)'::spoin
0
(1 row)

-- spoint_dwithin function ----------
SELECT a, b, radius, a <-> b AS "<->", spoint_dwithin(a, b, radius)
FROM (VALUES
('(0, 0)'::spoint, '(0, 0)'::spoint, 0),
('(0, 0)', '(0, 1)', 1),
('(0, 0)', '(0.1, 0.1)', 0.14),
('(0, 0)', '(0.1, 0.1)', 0.15)
) sub (a, b, radius);
a | b | radius | <-> | spoint_dwithin
---------+-------------+--------+-----------------+----------------
(0 , 0) | (0 , 0) | 0 | 0 | t
(0 , 0) | (0 , 1) | 1 | 1 | t
(0 , 0) | (0.1 , 0.1) | 0.14 | 0.1413032986961 | f
(0 , 0) | (0.1 , 0.1) | 0.15 | 0.1413032986961 | t
(4 rows)

9 changes: 9 additions & 0 deletions sql/points.sql
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,12 @@ SELECT '( 0h 2m 30s , 90d 0m 0s)'::spoint<->'( 12h 2m 30s , 90d 0m 0s)'::spoint;

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

-- spoint_dwithin function ----------

SELECT a, b, radius, a <-> b AS "<->", spoint_dwithin(a, b, radius)
FROM (VALUES
('(0, 0)'::spoint, '(0, 0)'::spoint, 0),
('(0, 0)', '(0, 1)', 1),
('(0, 0)', '(0.1, 0.1)', 0.14),
('(0, 0)', '(0.1, 0.1)', 0.15)
) sub (a, b, radius);
2 changes: 1 addition & 1 deletion src/point.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ spherepoint_dwithin(PG_FUNCTION_ARGS)
float8 within = PG_GETARG_FLOAT8(2);
float8 dist = spoint_dist(p1, p2);

PG_RETURN_BOOL(dist <= within);
PG_RETURN_BOOL(FPle(dist, within));
}


Expand Down

0 comments on commit 89dc41d

Please sign in to comment.