Commit a3d28448 authored by Tomas Vondra's avatar Tomas Vondra

Improve test coverage of geometric types

This commit significantly increases test coverage of geo_ops.c, adding
tests for various issues addressed by 2e2a392d (which went undetected
for a long time, at least partially due to not being covered).

This also removes alternative results expecting -0 on some platforms.
Instead the functions are should return the same results everywhere,
transforming -0 to 0 if needed.

The tests are added to geometric.sql file, sorted by the left hand side
of the operators. There are many cross datatype operators, so this seems
like the best solution.

Author: Emre Hasegeli
Reviewed-by: Tomas Vondra

Discussion: https://www.postgresql.org/message-id/CAE2gYzxF7-5djV6-cEvqQu-fNsnt%3DEqbOURx7ZDg%2BVv6ZMTWbg%40mail.gmail.com
parent 2e2a392d
......@@ -18,6 +18,7 @@
CREATE TABLE BOX_TBL (f1 box);
INSERT INTO BOX_TBL (f1) VALUES ('(2.0,2.0,0.0,0.0)');
INSERT INTO BOX_TBL (f1) VALUES ('(1.0,1.0,3.0,3.0)');
INSERT INTO BOX_TBL (f1) VALUES ('((-8, 2), (-2, -10))');
-- degenerate cases where the box is a line or a point
-- note that lines and points boxes all have zero area
INSERT INTO BOX_TBL (f1) VALUES ('(2.5, 2.5, 2.5,3.5)');
......@@ -27,6 +28,18 @@ INSERT INTO BOX_TBL (f1) VALUES ('(2.3, 4.5)');
ERROR: invalid input syntax for type box: "(2.3, 4.5)"
LINE 1: INSERT INTO BOX_TBL (f1) VALUES ('(2.3, 4.5)');
^
INSERT INTO BOX_TBL (f1) VALUES ('[1, 2, 3, 4)');
ERROR: invalid input syntax for type box: "[1, 2, 3, 4)"
LINE 1: INSERT INTO BOX_TBL (f1) VALUES ('[1, 2, 3, 4)');
^
INSERT INTO BOX_TBL (f1) VALUES ('(1, 2, 3, 4]');
ERROR: invalid input syntax for type box: "(1, 2, 3, 4]"
LINE 1: INSERT INTO BOX_TBL (f1) VALUES ('(1, 2, 3, 4]');
^
INSERT INTO BOX_TBL (f1) VALUES ('(1, 2, 3, 4) x');
ERROR: invalid input syntax for type box: "(1, 2, 3, 4) x"
LINE 1: INSERT INTO BOX_TBL (f1) VALUES ('(1, 2, 3, 4) x');
^
INSERT INTO BOX_TBL (f1) VALUES ('asdfasdf(ad');
ERROR: invalid input syntax for type box: "asdfasdf(ad"
LINE 1: INSERT INTO BOX_TBL (f1) VALUES ('asdfasdf(ad');
......@@ -36,9 +49,10 @@ SELECT '' AS four, * FROM BOX_TBL;
------+---------------------
| (2,2),(0,0)
| (3,3),(1,1)
| (-2,2),(-8,-10)
| (2.5,3.5),(2.5,2.5)
| (3,3),(3,3)
(4 rows)
(5 rows)
SELECT '' AS four, b.*, area(b.f1) as barea
FROM BOX_TBL b;
......@@ -46,9 +60,10 @@ SELECT '' AS four, b.*, area(b.f1) as barea
------+---------------------+-------
| (2,2),(0,0) | 4
| (3,3),(1,1) | 4
| (-2,2),(-8,-10) | 72
| (2.5,3.5),(2.5,2.5) | 0
| (3,3),(3,3) | 0
(4 rows)
(5 rows)
-- overlap
SELECT '' AS three, b.f1
......@@ -68,8 +83,9 @@ SELECT '' AS two, b1.*
two | f1
-----+---------------------
| (2,2),(0,0)
| (-2,2),(-8,-10)
| (2.5,3.5),(2.5,2.5)
(2 rows)
(3 rows)
-- right-or-overlap (x only)
SELECT '' AS two, b1.*
......@@ -88,8 +104,9 @@ SELECT '' AS two, b.f1
two | f1
-----+---------------------
| (2,2),(0,0)
| (-2,2),(-8,-10)
| (2.5,3.5),(2.5,2.5)
(2 rows)
(3 rows)
-- area <=
SELECT '' AS four, b.f1
......@@ -127,11 +144,12 @@ SELECT '' AS two, b.f1
SELECT '' AS two, b.f1
FROM BOX_TBL b -- zero area
WHERE b.f1 > box '(3.5,3.0,4.5,3.0)';
two | f1
-----+-------------
two | f1
-----+-----------------
| (2,2),(0,0)
| (3,3),(1,1)
(2 rows)
| (-2,2),(-8,-10)
(3 rows)
-- area >=
SELECT '' AS four, b.f1
......@@ -141,9 +159,10 @@ SELECT '' AS four, b.f1
------+---------------------
| (2,2),(0,0)
| (3,3),(1,1)
| (-2,2),(-8,-10)
| (2.5,3.5),(2.5,2.5)
| (3,3),(3,3)
(4 rows)
(5 rows)
-- right of
SELECT '' AS two, b.f1
......@@ -152,8 +171,9 @@ SELECT '' AS two, b.f1
two | f1
-----+---------------------
| (2,2),(0,0)
| (-2,2),(-8,-10)
| (2.5,3.5),(2.5,2.5)
(2 rows)
(3 rows)
-- contained in
SELECT '' AS three, b.f1
......@@ -193,9 +213,10 @@ SELECT '' AS four, @@(b1.f1) AS p
------+---------
| (1,1)
| (2,2)
| (-5,-4)
| (2.5,3)
| (3,3)
(4 rows)
(5 rows)
-- wholly-contained
SELECT '' AS one, b1.*, b2.*
......@@ -211,9 +232,10 @@ SELECT '' AS four, height(f1), width(f1) FROM BOX_TBL;
------+--------+-------
| 2 | 2
| 2 | 2
| 12 | 6
| 1 | 0
| 0 | 0
(4 rows)
(5 rows)
--
-- Test the SP-GiST index
......
......@@ -7,12 +7,22 @@ INSERT INTO CIRCLE_TBL VALUES ('<(1,2),100>');
INSERT INTO CIRCLE_TBL VALUES ('1,3,5');
INSERT INTO CIRCLE_TBL VALUES ('((1,2),3)');
INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10>');
INSERT INTO CIRCLE_TBL VALUES ('<(100,1),115>');
INSERT INTO CIRCLE_TBL VALUES (' < ( 100 , 1 ) , 115 > ');
INSERT INTO CIRCLE_TBL VALUES ('<(3,5),0>'); -- Zero radius
INSERT INTO CIRCLE_TBL VALUES ('<(3,5),NaN>'); -- NaN radius
-- bad values
INSERT INTO CIRCLE_TBL VALUES ('<(-100,0),-100>');
ERROR: invalid input syntax for type circle: "<(-100,0),-100>"
LINE 1: INSERT INTO CIRCLE_TBL VALUES ('<(-100,0),-100>');
^
INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10');
ERROR: invalid input syntax for type circle: "<(100,200),10"
LINE 1: INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10');
^
INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10> x');
ERROR: invalid input syntax for type circle: "<(100,200),10> x"
LINE 1: INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10> x');
^
INSERT INTO CIRCLE_TBL VALUES ('1abc,3,5');
ERROR: invalid input syntax for type circle: "1abc,3,5"
LINE 1: INSERT INTO CIRCLE_TBL VALUES ('1abc,3,5');
......@@ -30,7 +40,9 @@ SELECT * FROM CIRCLE_TBL;
<(1,2),3>
<(100,200),10>
<(100,1),115>
(6 rows)
<(3,5),0>
<(3,5),NaN>
(8 rows)
SELECT '' AS six, center(f1) AS center
FROM CIRCLE_TBL;
......@@ -42,7 +54,9 @@ SELECT '' AS six, center(f1) AS center
| (1,2)
| (100,200)
| (100,1)
(6 rows)
| (3,5)
| (3,5)
(8 rows)
SELECT '' AS six, radius(f1) AS radius
FROM CIRCLE_TBL;
......@@ -54,7 +68,9 @@ SELECT '' AS six, radius(f1) AS radius
| 3
| 10
| 115
(6 rows)
| 0
| NaN
(8 rows)
SELECT '' AS six, diameter(f1) AS diameter
FROM CIRCLE_TBL;
......@@ -66,14 +82,17 @@ SELECT '' AS six, diameter(f1) AS diameter
| 6
| 20
| 230
(6 rows)
| 0
| NaN
(8 rows)
SELECT '' AS two, f1 FROM CIRCLE_TBL WHERE radius(f1) < 5;
two | f1
-----+-----------
| <(5,1),3>
| <(1,2),3>
(2 rows)
| <(3,5),0>
(3 rows)
SELECT '' AS four, f1 FROM CIRCLE_TBL WHERE diameter(f1) >= 10;
four | f1
......@@ -82,7 +101,8 @@ SELECT '' AS four, f1 FROM CIRCLE_TBL WHERE diameter(f1) >= 10;
| <(1,3),5>
| <(100,200),10>
| <(100,1),115>
(4 rows)
| <(3,5),NaN>
(5 rows)
SELECT '' as five, c1.f1 AS one, c2.f1 AS two, (c1.f1 <-> c2.f1) AS distance
FROM CIRCLE_TBL c1, CIRCLE_TBL c2
......@@ -90,10 +110,13 @@ SELECT '' as five, c1.f1 AS one, c2.f1 AS two, (c1.f1 <-> c2.f1) AS distance
ORDER BY distance, area(c1.f1), area(c2.f1);
five | one | two | distance
------+----------------+----------------+------------------
| <(3,5),0> | <(1,2),3> | 0.60555127546399
| <(3,5),0> | <(5,1),3> | 1.47213595499958
| <(100,200),10> | <(100,1),115> | 74
| <(100,200),10> | <(1,2),100> | 111.370729772479
| <(1,3),5> | <(100,200),10> | 205.476756144497
| <(5,1),3> | <(100,200),10> | 207.51303816328
| <(3,5),0> | <(100,200),10> | 207.793480159531
| <(1,2),3> | <(100,200),10> | 208.370729772479
(5 rows)
(8 rows)
......@@ -157,7 +157,7 @@ SELECT count(*) FROM point_tbl WHERE box '(0,0,100,100)' @> f1;
SELECT count(*) FROM point_tbl WHERE f1 <@ polygon '(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)';
count
-------
3
5
(1 row)
SELECT count(*) FROM point_tbl WHERE f1 <@ circle '<(50,50),50>';
......@@ -175,7 +175,7 @@ SELECT count(*) FROM point_tbl p WHERE p.f1 << '(0.0, 0.0)';
SELECT count(*) FROM point_tbl p WHERE p.f1 >> '(0.0, 0.0)';
count
-------
2
3
(1 row)
SELECT count(*) FROM point_tbl p WHERE p.f1 <^ '(0.0, 0.0)';
......@@ -187,7 +187,7 @@ SELECT count(*) FROM point_tbl p WHERE p.f1 <^ '(0.0, 0.0)';
SELECT count(*) FROM point_tbl p WHERE p.f1 >^ '(0.0, 0.0)';
count
-------
3
4
(1 row)
SELECT count(*) FROM point_tbl p WHERE p.f1 ~= '(-5, -12)';
......@@ -197,16 +197,19 @@ SELECT count(*) FROM point_tbl p WHERE p.f1 ~= '(-5, -12)';
(1 row)
SELECT * FROM point_tbl ORDER BY f1 <-> '0,1';
f1
------------
f1
-------------------
(0,0)
(1e-300,-1e-300)
(-3,4)
(-10,0)
(10,10)
(-5,-12)
(5.1,34.5)
(1e+300,Infinity)
(NaN,NaN)
(7 rows)
(10 rows)
SELECT * FROM point_tbl WHERE f1 IS NULL;
f1
......@@ -215,24 +218,28 @@ SELECT * FROM point_tbl WHERE f1 IS NULL;
(1 row)
SELECT * FROM point_tbl WHERE f1 IS NOT NULL ORDER BY f1 <-> '0,1';
f1
------------
f1
-------------------
(1e-300,-1e-300)
(0,0)
(-3,4)
(-10,0)
(10,10)
(-5,-12)
(5.1,34.5)
(6 rows)
(1e+300,Infinity)
(NaN,NaN)
(9 rows)
SELECT * FROM point_tbl WHERE f1 <@ '(-10,-10),(10,10)':: box ORDER BY f1 <-> '0,1';
f1
---------
f1
------------------
(0,0)
(1e-300,-1e-300)
(-3,4)
(-10,0)
(10,10)
(4 rows)
(5 rows)
SELECT count(*) FROM quad_point_tbl WHERE p IS NULL;
count
......@@ -583,7 +590,7 @@ SELECT count(*) FROM point_tbl WHERE f1 <@ polygon '(0,0),(0,100),(100,100),(50,
SELECT count(*) FROM point_tbl WHERE f1 <@ polygon '(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)';
count
-------
3
4
(1 row)
EXPLAIN (COSTS OFF)
......@@ -628,7 +635,7 @@ SELECT count(*) FROM point_tbl p WHERE p.f1 >> '(0.0, 0.0)';
SELECT count(*) FROM point_tbl p WHERE p.f1 >> '(0.0, 0.0)';
count
-------
2
3
(1 row)
EXPLAIN (COSTS OFF)
......@@ -658,7 +665,7 @@ SELECT count(*) FROM point_tbl p WHERE p.f1 >^ '(0.0, 0.0)';
SELECT count(*) FROM point_tbl p WHERE p.f1 >^ '(0.0, 0.0)';
count
-------
3
4
(1 row)
EXPLAIN (COSTS OFF)
......@@ -685,16 +692,19 @@ SELECT * FROM point_tbl ORDER BY f1 <-> '0,1';
(2 rows)
SELECT * FROM point_tbl ORDER BY f1 <-> '0,1';
f1
------------
f1
-------------------
(10,10)
(NaN,NaN)
(0,0)
(1e-300,-1e-300)
(-3,4)
(-10,0)
(10,10)
(-5,-12)
(5.1,34.5)
(7 rows)
(1e+300,Infinity)
(10 rows)
EXPLAIN (COSTS OFF)
SELECT * FROM point_tbl WHERE f1 IS NULL;
......@@ -720,15 +730,18 @@ SELECT * FROM point_tbl WHERE f1 IS NOT NULL ORDER BY f1 <-> '0,1';
(3 rows)
SELECT * FROM point_tbl WHERE f1 IS NOT NULL ORDER BY f1 <-> '0,1';
f1
------------
f1
-------------------
(10,10)
(NaN,NaN)
(0,0)
(1e-300,-1e-300)
(-3,4)
(-10,0)
(10,10)
(-5,-12)
(5.1,34.5)
(6 rows)
(1e+300,Infinity)
(9 rows)
EXPLAIN (COSTS OFF)
SELECT * FROM point_tbl WHERE f1 <@ '(-10,-10),(10,10)':: box ORDER BY f1 <-> '0,1';
......@@ -740,13 +753,14 @@ SELECT * FROM point_tbl WHERE f1 <@ '(-10,-10),(10,10)':: box ORDER BY f1 <-> '0
(3 rows)
SELECT * FROM point_tbl WHERE f1 <@ '(-10,-10),(10,10)':: box ORDER BY f1 <-> '0,1';
f1
---------
f1
------------------
(0,0)
(1e-300,-1e-300)
(-3,4)
(-10,0)
(10,10)
(4 rows)
(5 rows)
EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_point_tbl WHERE p IS NULL;
......@@ -1407,13 +1421,14 @@ SELECT * FROM point_tbl WHERE f1 <@ '(-10,-10),(10,10)':: box ORDER BY f1 <-> '0
(6 rows)
SELECT * FROM point_tbl WHERE f1 <@ '(-10,-10),(10,10)':: box ORDER BY f1 <-> '0,1';
f1
---------
f1
------------------
(0,0)
(1e-300,-1e-300)
(-3,4)
(-10,0)
(10,10)
(4 rows)
(5 rows)
EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_point_tbl WHERE p IS NULL;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -4,24 +4,43 @@
--
--DROP TABLE LINE_TBL;
CREATE TABLE LINE_TBL (s line);
INSERT INTO LINE_TBL VALUES ('{1,-1,1}');
INSERT INTO LINE_TBL VALUES ('(0,0),(6,6)');
INSERT INTO LINE_TBL VALUES ('{0,-1,5}'); -- A == 0
INSERT INTO LINE_TBL VALUES ('{1,0,5}'); -- B == 0
INSERT INTO LINE_TBL VALUES ('{0,3,0}'); -- A == C == 0
INSERT INTO LINE_TBL VALUES (' (0,0), (6,6)');
INSERT INTO LINE_TBL VALUES ('10,-10 ,-5,-4');
INSERT INTO LINE_TBL VALUES ('[-1e6,2e2,3e5, -4e1]');
INSERT INTO LINE_TBL VALUES ('(11,22,33,44)');
INSERT INTO LINE_TBL VALUES ('[(1,0),(1,0)]');
ERROR: invalid line specification: must be two distinct points
LINE 1: INSERT INTO LINE_TBL VALUES ('[(1,0),(1,0)]');
^
INSERT INTO LINE_TBL VALUES ('{3,NaN,5}');
INSERT INTO LINE_TBL VALUES ('{NaN,NaN,NaN}');
-- horizontal
INSERT INTO LINE_TBL VALUES ('[(1,3),(2,3)]');
-- vertical
INSERT INTO LINE_TBL VALUES ('[(3,1),(3,2)]');
INSERT INTO LINE_TBL VALUES (line(point '(3,1)', point '(3,2)'));
-- bad values for parser testing
INSERT INTO LINE_TBL VALUES ('{}');
ERROR: invalid input syntax for type line: "{}"
LINE 1: INSERT INTO LINE_TBL VALUES ('{}');
^
INSERT INTO LINE_TBL VALUES ('{0');
ERROR: invalid input syntax for type line: "{0"
LINE 1: INSERT INTO LINE_TBL VALUES ('{0');
^
INSERT INTO LINE_TBL VALUES ('{0,0}');
ERROR: invalid input syntax for type line: "{0,0}"
LINE 1: INSERT INTO LINE_TBL VALUES ('{0,0}');
^
INSERT INTO LINE_TBL VALUES ('{0,0,1');
ERROR: invalid input syntax for type line: "{0,0,1"
LINE 1: INSERT INTO LINE_TBL VALUES ('{0,0,1');
^
INSERT INTO LINE_TBL VALUES ('{0,0,1}');
ERROR: invalid line specification: A and B cannot both be zero
LINE 1: INSERT INTO LINE_TBL VALUES ('{0,0,1}');
^
INSERT INTO LINE_TBL VALUES ('{0,0,1} x');
ERROR: invalid input syntax for type line: "{0,0,1} x"
LINE 1: INSERT INTO LINE_TBL VALUES ('{0,0,1} x');
^
INSERT INTO LINE_TBL VALUES ('(3asdf,2 ,3,4r2)');
ERROR: invalid input syntax for type line: "(3asdf,2 ,3,4r2)"
LINE 1: INSERT INTO LINE_TBL VALUES ('(3asdf,2 ,3,4r2)');
......@@ -38,234 +57,31 @@ INSERT INTO LINE_TBL VALUES ('[(1,2),(3,4)');
ERROR: invalid input syntax for type line: "[(1,2),(3,4)"
LINE 1: INSERT INTO LINE_TBL VALUES ('[(1,2),(3,4)');
^
INSERT INTO LINE_TBL VALUES ('[(1,2),(1,2)]');
ERROR: invalid line specification: must be two distinct points
LINE 1: INSERT INTO LINE_TBL VALUES ('[(1,2),(1,2)]');
^
INSERT INTO LINE_TBL VALUES (line(point '(1,0)', point '(1,0)'));
ERROR: invalid line specification: must be two distinct points
select * from LINE_TBL;
s
---------------------------------------------
{1,-1,1}
{0,-1,5}
{1,0,5}
{0,3,0}
{1,-1,0}
{-0.4,-1,-6}
{-0.000184615384615385,-1,15.3846153846154}
{1,-1,11}
{3,NaN,5}
{NaN,NaN,NaN}
{0,-1,3}
{-1,0,3}
(7 rows)
-- functions and operators
SELECT * FROM LINE_TBL WHERE (s <-> line '[(1,2),(3,4)]') < 10;
s
---------------------------------------------
{1,-1,1}
{1,-1,0}
{-0.4,-1,-6}
{-0.000184615384615385,-1,15.3846153846154}
{1,-1,11}
{0,-1,3}
{-1,0,3}
(7 rows)
SELECT * FROM LINE_TBL WHERE (point '(0.1,0.1)' <-> s) < 1;
s
----------
{1,-1,1}
{1,-1,0}
(2 rows)
SELECT * FROM LINE_TBL WHERE (lseg '[(0.1,0.1),(0.2,0.2)]' <-> s) < 1;
s
----------
{1,-1,1}
{1,-1,0}
(2 rows)
SELECT line '[(1,1),(2,1)]' <-> line '[(-1,-1),(-2,-1)]';
?column?
----------
2
(1 row)
SELECT lseg '[(1,1),(2,1)]' <-> line '[(-1,-1),(-2,-1)]';
?column?
----------
2
(1 row)
SELECT point '(-1,1)' <-> line '[(-3,0),(-4,0)]';
?column?
----------
1
(1 row)
SELECT lseg '[(1,1),(5,5)]' ?# line '[(2,0),(0,2)]'; -- true
?column?
----------
t
(1 row)
SELECT lseg '[(1,1),(5,5)]' ?# line '[(0,0),(1,0)]'; -- false
?column?
----------
f
(1 row)
SELECT line '[(0,0),(1,1)]' ?# box '(0,0,2,2)'; -- true
?column?
----------
t
(1 row)
SELECT line '[(3,0),(4,1)]' ?# box '(0,0,2,2)'; -- false
?column?
----------
f
(1 row)
SELECT point '(1,1)' <@ line '[(0,0),(2,2)]'; -- true
?column?
----------
t
(1 row)
SELECT point '(1,1)' <@ line '[(0,0),(1,0)]'; -- false
?column?
----------
f
(1 row)
SELECT point '(1,1)' @ line '[(0,0),(2,2)]'; -- true
?column?
----------
t
(1 row)
SELECT point '(1,1)' @ line '[(0,0),(1,0)]'; -- false
?column?
----------
f
(1 row)
SELECT lseg '[(1,1),(2,2)]' <@ line '[(0,0),(2,2)]'; -- true
?column?
----------
t
(1 row)
SELECT lseg '[(1,1),(2,1)]' <@ line '[(0,0),(1,0)]'; -- false
?column?
----------
f
(1 row)
SELECT lseg '[(1,1),(2,2)]' @ line '[(0,0),(2,2)]'; -- true
?column?
----------
t
(1 row)
SELECT lseg '[(1,1),(2,1)]' @ line '[(0,0),(1,0)]'; -- false
?column?
----------
f
(1 row)
SELECT point '(0,1)' ## line '[(0,0),(1,1)]';
?column?
-----------
(0.5,0.5)
(1 row)
SELECT line '[(0,0),(1,1)]' ## lseg '[(1,0),(2,0)]';
?column?
----------
(1,0)
(1 row)
SELECT line '[(0,0),(1,1)]' ?# line '[(1,0),(2,1)]'; -- false
?column?
----------
f
(1 row)
SELECT line '[(0,0),(1,1)]' ?# line '[(1,0),(1,1)]'; -- true
?column?
----------
t
(1 row)
SELECT line '[(0,0),(1,1)]' # line '[(1,0),(2,1)]';
?column?
----------
(1 row)
SELECT line '[(0,0),(1,1)]' # line '[(1,0),(1,1)]';
?column?
----------
(1,1)
(1 row)
SELECT line '[(0,0),(1,1)]' ?|| line '[(1,0),(2,1)]'; -- true
?column?
----------
t
(1 row)
SELECT line '[(0,0),(1,1)]' ?|| line '[(1,0),(1,1)]'; -- false
?column?
----------
f
(1 row)
SELECT line '[(0,0),(1,0)]' ?-| line '[(0,0),(0,1)]'; -- true
?column?
----------
t
(1 row)
SELECT line '[(0,0),(1,1)]' ?-| line '[(1,0),(1,1)]'; -- false
?column?
----------
f
(1 row)
SELECT ?- line '[(0,0),(1,0)]'; -- true
?column?
----------
t
(1 row)
SELECT ?- line '[(0,0),(1,1)]'; -- false
?column?
----------
f
(1 row)
SELECT ?| line '[(0,0),(0,1)]'; -- true
?column?
----------
t
(1 row)
SELECT ?| line '[(0,0),(1,1)]'; -- false
?column?
----------
f
(1 row)
SELECT line(point '(1,2)', point '(3,4)');
line
----------
{1,-1,1}
(1 row)
SELECT line '[(1,2),(3,4)]' = line '[(3,4),(4,5)]'; -- true
?column?
----------
t
(1 row)
(10 rows)
SELECT line '[(1,2),(3,4)]' = line '[(3,4),(4,4)]'; -- false
?column?
----------
f
select '{nan, 1, nan}'::line = '{nan, 1, nan}'::line as true,
'{nan, 1, nan}'::line = '{nan, 2, nan}'::line as false;
true | false
------+-------
t | f
(1 row)
......@@ -8,7 +8,10 @@ INSERT INTO LSEG_TBL VALUES ('[(1,2),(3,4)]');
INSERT INTO LSEG_TBL VALUES ('(0,0),(6,6)');
INSERT INTO LSEG_TBL VALUES ('10,-10 ,-3,-4');
INSERT INTO LSEG_TBL VALUES ('[-1e6,2e2,3e5, -4e1]');
INSERT INTO LSEG_TBL VALUES ('(11,22,33,44)');
INSERT INTO LSEG_TBL VALUES (lseg(point(11, 22), point(33,44)));
INSERT INTO LSEG_TBL VALUES ('[(-10,2),(-10,3)]'); -- vertical
INSERT INTO LSEG_TBL VALUES ('[(0,-20),(30,-20)]'); -- horizontal
INSERT INTO LSEG_TBL VALUES ('[(NaN,1),(NaN,90)]'); -- NaN
-- bad values for parser testing
INSERT INTO LSEG_TBL VALUES ('(3asdf,2 ,3,4r2)');
ERROR: invalid input syntax for type lseg: "(3asdf,2 ,3,4r2)"
......@@ -34,19 +37,8 @@ select * from LSEG_TBL;
[(10,-10),(-3,-4)]
[(-1000000,200),(300000,-40)]
[(11,22),(33,44)]
(5 rows)
SELECT * FROM LSEG_TBL WHERE s <= lseg '[(1,2),(3,4)]';
s
---------------
[(1,2),(3,4)]
(1 row)
SELECT * FROM LSEG_TBL WHERE (s <-> lseg '[(1,2),(3,4)]') < 10;
s
--------------------
[(1,2),(3,4)]
[(0,0),(6,6)]
[(10,-10),(-3,-4)]
(3 rows)
[(-10,2),(-10,3)]
[(0,-20),(30,-20)]
[(NaN,1),(NaN,90)]
(8 rows)
......@@ -4,14 +4,19 @@
--DROP TABLE PATH_TBL;
CREATE TABLE PATH_TBL (f1 path);
INSERT INTO PATH_TBL VALUES ('[(1,2),(3,4)]');
INSERT INTO PATH_TBL VALUES ('((1,2),(3,4))');
INSERT INTO PATH_TBL VALUES ('[(0,0),(3,0),(4,5),(1,6)]');
INSERT INTO PATH_TBL VALUES ('((1,2),(3,4))');
INSERT INTO PATH_TBL VALUES ('1,2 ,3,4');
INSERT INTO PATH_TBL VALUES ('[1,2,3, 4]');
INSERT INTO PATH_TBL VALUES ('[11,12,13,14]');
INSERT INTO PATH_TBL VALUES ('(11,12,13,14)');
INSERT INTO PATH_TBL VALUES (' ( ( 1 , 2 ) , ( 3 , 4 ) ) ');
INSERT INTO PATH_TBL VALUES ('[ (0,0),(3,0),(4,5),(1,6) ]');
INSERT INTO PATH_TBL VALUES ('((1,2) ,(3,4 ))');
INSERT INTO PATH_TBL VALUES ('1,2 ,3,4 ');
INSERT INTO PATH_TBL VALUES (' [1,2,3, 4] ');
INSERT INTO PATH_TBL VALUES ('((10,20))'); -- Only one point
INSERT INTO PATH_TBL VALUES ('[ 11,12,13,14 ]');
INSERT INTO PATH_TBL VALUES ('( 11,12,13,14) ');
-- bad values for parser testing
INSERT INTO PATH_TBL VALUES ('[]');
ERROR: invalid input syntax for type path: "[]"
LINE 1: INSERT INTO PATH_TBL VALUES ('[]');
^
INSERT INTO PATH_TBL VALUES ('[(,2),(3,4)]');
ERROR: invalid input syntax for type path: "[(,2),(3,4)]"
LINE 1: INSERT INTO PATH_TBL VALUES ('[(,2),(3,4)]');
......@@ -20,19 +25,14 @@ INSERT INTO PATH_TBL VALUES ('[(1,2),(3,4)');
ERROR: invalid input syntax for type path: "[(1,2),(3,4)"
LINE 1: INSERT INTO PATH_TBL VALUES ('[(1,2),(3,4)');
^
SELECT f1 FROM PATH_TBL;
f1
---------------------------
[(1,2),(3,4)]
((1,2),(3,4))
[(0,0),(3,0),(4,5),(1,6)]
((1,2),(3,4))
((1,2),(3,4))
[(1,2),(3,4)]
[(11,12),(13,14)]
((11,12),(13,14))
(8 rows)
INSERT INTO PATH_TBL VALUES ('(1,2,3,4');
ERROR: invalid input syntax for type path: "(1,2,3,4"
LINE 1: INSERT INTO PATH_TBL VALUES ('(1,2,3,4');
^
INSERT INTO PATH_TBL VALUES ('(1,2),(3,4)]');
ERROR: invalid input syntax for type path: "(1,2),(3,4)]"
LINE 1: INSERT INTO PATH_TBL VALUES ('(1,2),(3,4)]');
^
SELECT '' AS count, f1 AS open_path FROM PATH_TBL WHERE isopen(f1);
count | open_path
-------+---------------------------
......@@ -48,8 +48,9 @@ SELECT '' AS count, f1 AS closed_path FROM PATH_TBL WHERE isclosed(f1);
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((10,20))
| ((11,12),(13,14))
(4 rows)
(5 rows)
SELECT '' AS count, pclose(f1) AS closed_path FROM PATH_TBL;
count | closed_path
......@@ -60,9 +61,10 @@ SELECT '' AS count, pclose(f1) AS closed_path FROM PATH_TBL;
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((10,20))
| ((11,12),(13,14))
| ((11,12),(13,14))
(8 rows)
(9 rows)
SELECT '' AS count, popen(f1) AS open_path FROM PATH_TBL;
count | open_path
......@@ -73,7 +75,8 @@ SELECT '' AS count, popen(f1) AS open_path FROM PATH_TBL;
| [(1,2),(3,4)]
| [(1,2),(3,4)]
| [(1,2),(3,4)]
| [(10,20)]
| [(11,12),(13,14)]
| [(11,12),(13,14)]
(8 rows)
(9 rows)
This diff is collapsed.
......@@ -6,6 +6,9 @@
CREATE TABLE POLYGON_TBL(f1 polygon);
INSERT INTO POLYGON_TBL(f1) VALUES ('(2.0,0.0),(2.0,4.0),(0.0,0.0)');
INSERT INTO POLYGON_TBL(f1) VALUES ('(3.0,1.0),(3.0,3.0),(1.0,0.0)');
INSERT INTO POLYGON_TBL(f1) VALUES ('(1,2),(3,4),(5,6),(7,8)');
INSERT INTO POLYGON_TBL(f1) VALUES ('(7,8),(5,6),(3,4),(1,2)'); -- Reverse
INSERT INTO POLYGON_TBL(f1) VALUES ('(1,2),(7,8),(5,6),(3,-4)');
-- degenerate polygons
INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0,0.0)');
INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0,1.0),(0.0,1.0)');
......@@ -31,201 +34,16 @@ ERROR: invalid input syntax for type polygon: "asdf"
LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('asdf');
^
SELECT '' AS four, * FROM POLYGON_TBL;
four | f1
------+---------------------
four | f1
------+----------------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((1,2),(3,4),(5,6),(7,8))
| ((7,8),(5,6),(3,4),(1,2))
| ((1,2),(7,8),(5,6),(3,-4))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- overlap
SELECT '' AS three, p.*
FROM POLYGON_TBL p
WHERE p.f1 && '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
three | f1
-------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
(2 rows)
-- left overlap
SELECT '' AS four, p.*
FROM POLYGON_TBL p
WHERE p.f1 &< '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
four | f1
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- right overlap
SELECT '' AS two, p.*
FROM POLYGON_TBL p
WHERE p.f1 &> '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
two | f1
-----+---------------------
| ((3,1),(3,3),(1,0))
(1 row)
-- left of
SELECT '' AS one, p.*
FROM POLYGON_TBL p
WHERE p.f1 << '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
one | f1
-----+---------------
| ((0,0))
| ((0,1),(0,1))
(2 rows)
-- right of
SELECT '' AS zero, p.*
FROM POLYGON_TBL p
WHERE p.f1 >> '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
zero | f1
------+----
(0 rows)
-- contained
SELECT '' AS one, p.*
FROM POLYGON_TBL p
WHERE p.f1 <@ polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
one | f1
-----+---------------------
| ((3,1),(3,3),(1,0))
(1 row)
-- same
SELECT '' AS one, p.*
FROM POLYGON_TBL p
WHERE p.f1 ~= polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
one | f1
-----+---------------------
| ((3,1),(3,3),(1,0))
(1 row)
-- contains
SELECT '' AS one, p.*
FROM POLYGON_TBL p
WHERE p.f1 @> polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
one | f1
-----+---------------------
| ((3,1),(3,3),(1,0))
(1 row)
--
-- polygon logic
--
-- left of
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' << polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
false
-------
f
(1 row)
-- left overlap
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' << polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS true;
true
------
f
(1 row)
-- right overlap
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' &> polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
false
-------
f
(1 row)
-- right of
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' >> polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
false
-------
f
(1 row)
-- contained in
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' <@ polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
false
-------
f
(1 row)
-- contains
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' @> polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
false
-------
f
(1 row)
SELECT '((0,4),(6,4),(1,2),(6,0),(0,0))'::polygon @> '((2,1),(2,3),(3,3),(3,1))'::polygon AS "false";
false
-------
f
(1 row)
SELECT '((0,4),(6,4),(3,2),(6,0),(0,0))'::polygon @> '((2,1),(2,3),(3,3),(3,1))'::polygon AS "true";
true
------
t
(1 row)
SELECT '((1,1),(1,4),(5,4),(5,3),(2,3),(2,2),(5,2),(5,1))'::polygon @> '((3,2),(3,3),(4,3),(4,2))'::polygon AS "false";
false
-------
f
(1 row)
SELECT '((0,0),(0,3),(3,3),(3,0))'::polygon @> '((2,1),(2,2),(3,2),(3,1))'::polygon AS "true";
true
------
t
(1 row)
-- same
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' ~= polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
false
-------
f
(1 row)
-- overlap
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' && polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS true;
true
------
t
(1 row)
SELECT '((0,4),(6,4),(1,2),(6,0),(0,0))'::polygon && '((2,1),(2,3),(3,3),(3,1))'::polygon AS "true";
true
------
t
(1 row)
SELECT '((1,4),(1,1),(4,1),(4,2),(2,2),(2,4),(1,4))'::polygon && '((3,3),(4,3),(4,4),(3,4),(3,3))'::polygon AS "false";
false
-------
f
(1 row)
SELECT '((200,800),(800,800),(800,200),(200,200))' && '(1000,1000,0,0)'::polygon AS "true";
true
------
t
(1 row)
-- distance from a point
SELECT '(0,0)'::point <-> '((0,0),(1,2),(2,1))'::polygon as on_corner,
'(1,1)'::point <-> '((0,0),(2,2),(1,3))'::polygon as on_segment,
'(2,2)'::point <-> '((0,0),(1,4),(3,1))'::polygon as inside,
'(3,3)'::point <-> '((0,2),(2,0),(2,2))'::polygon as near_corner,
'(4,4)'::point <-> '((0,0),(0,3),(4,0))'::polygon as near_segment;
on_corner | on_segment | inside | near_corner | near_segment
-----------+------------+--------+-----------------+--------------
0 | 0 | 0 | 1.4142135623731 | 3.2
(1 row)
(7 rows)
--
-- Test the SP-GiST index
......
......@@ -25,6 +25,9 @@ INSERT INTO BOX_TBL (f1) VALUES ('(2.0,2.0,0.0,0.0)');
INSERT INTO BOX_TBL (f1) VALUES ('(1.0,1.0,3.0,3.0)');
INSERT INTO BOX_TBL (f1) VALUES ('((-8, 2), (-2, -10))');
-- degenerate cases where the box is a line or a point
-- note that lines and points boxes all have zero area
INSERT INTO BOX_TBL (f1) VALUES ('(2.5, 2.5, 2.5,3.5)');
......@@ -34,6 +37,12 @@ INSERT INTO BOX_TBL (f1) VALUES ('(3.0, 3.0,3.0,3.0)');
-- badly formatted box inputs
INSERT INTO BOX_TBL (f1) VALUES ('(2.3, 4.5)');
INSERT INTO BOX_TBL (f1) VALUES ('[1, 2, 3, 4)');
INSERT INTO BOX_TBL (f1) VALUES ('(1, 2, 3, 4]');
INSERT INTO BOX_TBL (f1) VALUES ('(1, 2, 3, 4) x');
INSERT INTO BOX_TBL (f1) VALUES ('asdfasdf(ad');
......
......@@ -14,12 +14,20 @@ INSERT INTO CIRCLE_TBL VALUES ('((1,2),3)');
INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10>');
INSERT INTO CIRCLE_TBL VALUES ('<(100,1),115>');
INSERT INTO CIRCLE_TBL VALUES (' < ( 100 , 1 ) , 115 > ');
INSERT INTO CIRCLE_TBL VALUES ('<(3,5),0>'); -- Zero radius
INSERT INTO CIRCLE_TBL VALUES ('<(3,5),NaN>'); -- NaN radius
-- bad values
INSERT INTO CIRCLE_TBL VALUES ('<(-100,0),-100>');
INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10');
INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10> x');
INSERT INTO CIRCLE_TBL VALUES ('1abc,3,5');
INSERT INTO CIRCLE_TBL VALUES ('(3,(1,2),3)');
......
This diff is collapsed.
......@@ -6,82 +6,37 @@
--DROP TABLE LINE_TBL;
CREATE TABLE LINE_TBL (s line);
INSERT INTO LINE_TBL VALUES ('{1,-1,1}');
INSERT INTO LINE_TBL VALUES ('(0,0),(6,6)');
INSERT INTO LINE_TBL VALUES ('{0,-1,5}'); -- A == 0
INSERT INTO LINE_TBL VALUES ('{1,0,5}'); -- B == 0
INSERT INTO LINE_TBL VALUES ('{0,3,0}'); -- A == C == 0
INSERT INTO LINE_TBL VALUES (' (0,0), (6,6)');
INSERT INTO LINE_TBL VALUES ('10,-10 ,-5,-4');
INSERT INTO LINE_TBL VALUES ('[-1e6,2e2,3e5, -4e1]');
INSERT INTO LINE_TBL VALUES ('(11,22,33,44)');
INSERT INTO LINE_TBL VALUES ('[(1,0),(1,0)]');
INSERT INTO LINE_TBL VALUES ('{3,NaN,5}');
INSERT INTO LINE_TBL VALUES ('{NaN,NaN,NaN}');
-- horizontal
INSERT INTO LINE_TBL VALUES ('[(1,3),(2,3)]');
-- vertical
INSERT INTO LINE_TBL VALUES ('[(3,1),(3,2)]');
INSERT INTO LINE_TBL VALUES (line(point '(3,1)', point '(3,2)'));
-- bad values for parser testing
INSERT INTO LINE_TBL VALUES ('{}');
INSERT INTO LINE_TBL VALUES ('{0');
INSERT INTO LINE_TBL VALUES ('{0,0}');
INSERT INTO LINE_TBL VALUES ('{0,0,1');
INSERT INTO LINE_TBL VALUES ('{0,0,1}');
INSERT INTO LINE_TBL VALUES ('{0,0,1} x');
INSERT INTO LINE_TBL VALUES ('(3asdf,2 ,3,4r2)');
INSERT INTO LINE_TBL VALUES ('[1,2,3, 4');
INSERT INTO LINE_TBL VALUES ('[(,2),(3,4)]');
INSERT INTO LINE_TBL VALUES ('[(1,2),(3,4)');
INSERT INTO LINE_TBL VALUES ('[(1,2),(1,2)]');
select * from LINE_TBL;
-- functions and operators
SELECT * FROM LINE_TBL WHERE (s <-> line '[(1,2),(3,4)]') < 10;
SELECT * FROM LINE_TBL WHERE (point '(0.1,0.1)' <-> s) < 1;
SELECT * FROM LINE_TBL WHERE (lseg '[(0.1,0.1),(0.2,0.2)]' <-> s) < 1;
SELECT line '[(1,1),(2,1)]' <-> line '[(-1,-1),(-2,-1)]';
SELECT lseg '[(1,1),(2,1)]' <-> line '[(-1,-1),(-2,-1)]';
SELECT point '(-1,1)' <-> line '[(-3,0),(-4,0)]';
SELECT lseg '[(1,1),(5,5)]' ?# line '[(2,0),(0,2)]'; -- true
SELECT lseg '[(1,1),(5,5)]' ?# line '[(0,0),(1,0)]'; -- false
SELECT line '[(0,0),(1,1)]' ?# box '(0,0,2,2)'; -- true
SELECT line '[(3,0),(4,1)]' ?# box '(0,0,2,2)'; -- false
SELECT point '(1,1)' <@ line '[(0,0),(2,2)]'; -- true
SELECT point '(1,1)' <@ line '[(0,0),(1,0)]'; -- false
SELECT point '(1,1)' @ line '[(0,0),(2,2)]'; -- true
SELECT point '(1,1)' @ line '[(0,0),(1,0)]'; -- false
INSERT INTO LINE_TBL VALUES (line(point '(1,0)', point '(1,0)'));
SELECT lseg '[(1,1),(2,2)]' <@ line '[(0,0),(2,2)]'; -- true
SELECT lseg '[(1,1),(2,1)]' <@ line '[(0,0),(1,0)]'; -- false
SELECT lseg '[(1,1),(2,2)]' @ line '[(0,0),(2,2)]'; -- true
SELECT lseg '[(1,1),(2,1)]' @ line '[(0,0),(1,0)]'; -- false
SELECT point '(0,1)' ## line '[(0,0),(1,1)]';
SELECT line '[(0,0),(1,1)]' ## lseg '[(1,0),(2,0)]';
SELECT line '[(0,0),(1,1)]' ?# line '[(1,0),(2,1)]'; -- false
SELECT line '[(0,0),(1,1)]' ?# line '[(1,0),(1,1)]'; -- true
SELECT line '[(0,0),(1,1)]' # line '[(1,0),(2,1)]';
SELECT line '[(0,0),(1,1)]' # line '[(1,0),(1,1)]';
SELECT line '[(0,0),(1,1)]' ?|| line '[(1,0),(2,1)]'; -- true
SELECT line '[(0,0),(1,1)]' ?|| line '[(1,0),(1,1)]'; -- false
SELECT line '[(0,0),(1,0)]' ?-| line '[(0,0),(0,1)]'; -- true
SELECT line '[(0,0),(1,1)]' ?-| line '[(1,0),(1,1)]'; -- false
SELECT ?- line '[(0,0),(1,0)]'; -- true
SELECT ?- line '[(0,0),(1,1)]'; -- false
SELECT ?| line '[(0,0),(0,1)]'; -- true
SELECT ?| line '[(0,0),(1,1)]'; -- false
SELECT line(point '(1,2)', point '(3,4)');
select * from LINE_TBL;
SELECT line '[(1,2),(3,4)]' = line '[(3,4),(4,5)]'; -- true
SELECT line '[(1,2),(3,4)]' = line '[(3,4),(4,4)]'; -- false
select '{nan, 1, nan}'::line = '{nan, 1, nan}'::line as true,
'{nan, 1, nan}'::line = '{nan, 2, nan}'::line as false;
......@@ -10,7 +10,10 @@ INSERT INTO LSEG_TBL VALUES ('[(1,2),(3,4)]');
INSERT INTO LSEG_TBL VALUES ('(0,0),(6,6)');
INSERT INTO LSEG_TBL VALUES ('10,-10 ,-3,-4');
INSERT INTO LSEG_TBL VALUES ('[-1e6,2e2,3e5, -4e1]');
INSERT INTO LSEG_TBL VALUES ('(11,22,33,44)');
INSERT INTO LSEG_TBL VALUES (lseg(point(11, 22), point(33,44)));
INSERT INTO LSEG_TBL VALUES ('[(-10,2),(-10,3)]'); -- vertical
INSERT INTO LSEG_TBL VALUES ('[(0,-20),(30,-20)]'); -- horizontal
INSERT INTO LSEG_TBL VALUES ('[(NaN,1),(NaN,90)]'); -- NaN
-- bad values for parser testing
INSERT INTO LSEG_TBL VALUES ('(3asdf,2 ,3,4r2)');
......@@ -19,7 +22,3 @@ INSERT INTO LSEG_TBL VALUES ('[(,2),(3,4)]');
INSERT INTO LSEG_TBL VALUES ('[(1,2),(3,4)');
select * from LSEG_TBL;
SELECT * FROM LSEG_TBL WHERE s <= lseg '[(1,2),(3,4)]';
SELECT * FROM LSEG_TBL WHERE (s <-> lseg '[(1,2),(3,4)]') < 10;
......@@ -8,26 +8,32 @@ CREATE TABLE PATH_TBL (f1 path);
INSERT INTO PATH_TBL VALUES ('[(1,2),(3,4)]');
INSERT INTO PATH_TBL VALUES ('((1,2),(3,4))');
INSERT INTO PATH_TBL VALUES (' ( ( 1 , 2 ) , ( 3 , 4 ) ) ');
INSERT INTO PATH_TBL VALUES ('[(0,0),(3,0),(4,5),(1,6)]');
INSERT INTO PATH_TBL VALUES ('[ (0,0),(3,0),(4,5),(1,6) ]');
INSERT INTO PATH_TBL VALUES ('((1,2),(3,4))');
INSERT INTO PATH_TBL VALUES ('((1,2) ,(3,4 ))');
INSERT INTO PATH_TBL VALUES ('1,2 ,3,4');
INSERT INTO PATH_TBL VALUES ('1,2 ,3,4 ');
INSERT INTO PATH_TBL VALUES ('[1,2,3, 4]');
INSERT INTO PATH_TBL VALUES (' [1,2,3, 4] ');
INSERT INTO PATH_TBL VALUES ('[11,12,13,14]');
INSERT INTO PATH_TBL VALUES ('((10,20))'); -- Only one point
INSERT INTO PATH_TBL VALUES ('(11,12,13,14)');
INSERT INTO PATH_TBL VALUES ('[ 11,12,13,14 ]');
INSERT INTO PATH_TBL VALUES ('( 11,12,13,14) ');
-- bad values for parser testing
INSERT INTO PATH_TBL VALUES ('[]');
INSERT INTO PATH_TBL VALUES ('[(,2),(3,4)]');
INSERT INTO PATH_TBL VALUES ('[(1,2),(3,4)');
SELECT f1 FROM PATH_TBL;
INSERT INTO PATH_TBL VALUES ('(1,2,3,4');
INSERT INTO PATH_TBL VALUES ('(1,2),(3,4)]');
SELECT '' AS count, f1 AS open_path FROM PATH_TBL WHERE isopen(f1);
......
......@@ -14,6 +14,12 @@ INSERT INTO POINT_TBL(f1) VALUES ('(5.1, 34.5)');
INSERT INTO POINT_TBL(f1) VALUES ('(-5.0,-12.0)');
INSERT INTO POINT_TBL(f1) VALUES ('(1e-300,-1e-300)'); -- To underflow
INSERT INTO POINT_TBL(f1) VALUES ('(1e+300,Inf)'); -- To overflow
INSERT INTO POINT_TBL(f1) VALUES (' ( Nan , NaN ) ');
-- bad format points
INSERT INTO POINT_TBL(f1) VALUES ('asdfasdf');
......@@ -21,8 +27,12 @@ INSERT INTO POINT_TBL(f1) VALUES ('10.0,10.0');
INSERT INTO POINT_TBL(f1) VALUES ('(10.0 10.0)');
INSERT INTO POINT_TBL(f1) VALUES ('(10.0, 10.0) x');
INSERT INTO POINT_TBL(f1) VALUES ('(10.0,10.0');
INSERT INTO POINT_TBL(f1) VALUES ('(10.0, 1e+500)'); -- Out of range
SELECT '' AS six, * FROM POINT_TBL;
......
......@@ -11,6 +11,10 @@ INSERT INTO POLYGON_TBL(f1) VALUES ('(2.0,0.0),(2.0,4.0),(0.0,0.0)');
INSERT INTO POLYGON_TBL(f1) VALUES ('(3.0,1.0),(3.0,3.0),(1.0,0.0)');
INSERT INTO POLYGON_TBL(f1) VALUES ('(1,2),(3,4),(5,6),(7,8)');
INSERT INTO POLYGON_TBL(f1) VALUES ('(7,8),(5,6),(3,4),(1,2)'); -- Reverse
INSERT INTO POLYGON_TBL(f1) VALUES ('(1,2),(7,8),(5,6),(3,-4)');
-- degenerate polygons
INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0,0.0)');
......@@ -30,93 +34,6 @@ INSERT INTO POLYGON_TBL(f1) VALUES ('asdf');
SELECT '' AS four, * FROM POLYGON_TBL;
-- overlap
SELECT '' AS three, p.*
FROM POLYGON_TBL p
WHERE p.f1 && '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
-- left overlap
SELECT '' AS four, p.*
FROM POLYGON_TBL p
WHERE p.f1 &< '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
-- right overlap
SELECT '' AS two, p.*
FROM POLYGON_TBL p
WHERE p.f1 &> '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
-- left of
SELECT '' AS one, p.*
FROM POLYGON_TBL p
WHERE p.f1 << '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
-- right of
SELECT '' AS zero, p.*
FROM POLYGON_TBL p
WHERE p.f1 >> '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
-- contained
SELECT '' AS one, p.*
FROM POLYGON_TBL p
WHERE p.f1 <@ polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
-- same
SELECT '' AS one, p.*
FROM POLYGON_TBL p
WHERE p.f1 ~= polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
-- contains
SELECT '' AS one, p.*
FROM POLYGON_TBL p
WHERE p.f1 @> polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
--
-- polygon logic
--
-- left of
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' << polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
-- left overlap
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' << polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS true;
-- right overlap
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' &> polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
-- right of
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' >> polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
-- contained in
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' <@ polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
-- contains
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' @> polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
SELECT '((0,4),(6,4),(1,2),(6,0),(0,0))'::polygon @> '((2,1),(2,3),(3,3),(3,1))'::polygon AS "false";
SELECT '((0,4),(6,4),(3,2),(6,0),(0,0))'::polygon @> '((2,1),(2,3),(3,3),(3,1))'::polygon AS "true";
SELECT '((1,1),(1,4),(5,4),(5,3),(2,3),(2,2),(5,2),(5,1))'::polygon @> '((3,2),(3,3),(4,3),(4,2))'::polygon AS "false";
SELECT '((0,0),(0,3),(3,3),(3,0))'::polygon @> '((2,1),(2,2),(3,2),(3,1))'::polygon AS "true";
-- same
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' ~= polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
-- overlap
SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' && polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS true;
SELECT '((0,4),(6,4),(1,2),(6,0),(0,0))'::polygon && '((2,1),(2,3),(3,3),(3,1))'::polygon AS "true";
SELECT '((1,4),(1,1),(4,1),(4,2),(2,2),(2,4),(1,4))'::polygon && '((3,3),(4,3),(4,4),(3,4),(3,3))'::polygon AS "false";
SELECT '((200,800),(800,800),(800,200),(200,200))' && '(1000,1000,0,0)'::polygon AS "true";
-- distance from a point
SELECT '(0,0)'::point <-> '((0,0),(1,2),(2,1))'::polygon as on_corner,
'(1,1)'::point <-> '((0,0),(2,2),(1,3))'::polygon as on_segment,
'(2,2)'::point <-> '((0,0),(1,4),(3,1))'::polygon as inside,
'(3,3)'::point <-> '((0,2),(2,0),(2,2))'::polygon as near_corner,
'(4,4)'::point <-> '((0,0),(0,3),(4,0))'::polygon as near_segment;
--
-- Test the SP-GiST index
--
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment