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 source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
--
-- GEOMETRY
--
-- Back off displayed precision a little bit to reduce platform-to-platform
-- variation in results.
SET extra_float_digits TO -3;
--
-- Points
--
SELECT '' AS four, center(f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS four, (@@ f1) AS center
FROM BOX_TBL;
four | center
------+---------
| (1,1)
| (2,2)
| (2.5,3)
| (3,3)
(4 rows)
SELECT '' AS six, point(f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (5,1)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,1)
(6 rows)
SELECT '' AS six, (@@ f1) AS center
FROM CIRCLE_TBL;
six | center
-----+-----------
| (5,1)
| (1,2)
| (1,3)
| (1,2)
| (100,200)
| (100,1)
(6 rows)
SELECT '' AS two, (@@ f1) AS center
FROM POLYGON_TBL
WHERE (# f1) > 2;
two | center
-----+-------------------------------
| (1.33333333333,1.33333333333)
| (2.33333333333,1.33333333333)
(2 rows)
-- "is horizontal" function
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE ishorizontal(p1.f1, point '(0,0)');
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is horizontal" operator
SELECT '' AS two, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?- point '(0,0)';
two | f1
-----+---------
| (0,0)
| (-10,0)
(2 rows)
-- "is vertical" function
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE isvertical(p1.f1, point '(5.1,34.5)');
one | f1
-----+------------
| (5.1,34.5)
(1 row)
-- "is vertical" operator
SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
one | f1
-----+------------
| (5.1,34.5)
(1 row)
--
-- Line segments
--
-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: operator does not exist: lseg # point
LINE 1: SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
thirty | f1 | s | closest
--------+------------+-------------------------------+----------------------------------
| (0,0) | [(1,2),(3,4)] | (1,2)
| (0,0) | [(0,0),(6,6)] | (0,0)
| (0,0) | [(10,-10),(-3,-4)] | (-2.0487804878,-4.43902439024)
| (0,0) | [(-1000000,200),(300000,-40)] | (0.00284023658959,15.3846148603)
| (0,0) | [(11,22),(33,44)] | (11,22)
| (-10,0) | [(1,2),(3,4)] | (1,2)
| (-10,0) | [(0,0),(6,6)] | (0,0)
| (-10,0) | [(10,-10),(-3,-4)] | (-3,-4)
| (-10,0) | [(-1000000,200),(300000,-40)] | (-9.99715942258,15.386461014)
| (-10,0) | [(11,22),(33,44)] | (11,22)
| (-3,4) | [(1,2),(3,4)] | (1,2)
| (-3,4) | [(0,0),(6,6)] | (0.5,0.5)
| (-3,4) | [(10,-10),(-3,-4)] | (-3,-4)
| (-3,4) | [(-1000000,200),(300000,-40)] | (-2.99789812268,15.3851688427)
| (-3,4) | [(11,22),(33,44)] | (11,22)
| (5.1,34.5) | [(1,2),(3,4)] | (3,4)
| (5.1,34.5) | [(0,0),(6,6)] | (6,6)
| (5.1,34.5) | [(10,-10),(-3,-4)] | (-3,-4)
| (5.1,34.5) | [(-1000000,200),(300000,-40)] | (5.09647083221,15.3836744977)
| (5.1,34.5) | [(11,22),(33,44)] | (14.3,25.3)
| (-5,-12) | [(1,2),(3,4)] | (1,2)
| (-5,-12) | [(0,0),(6,6)] | (0,0)
| (-5,-12) | [(10,-10),(-3,-4)] | (-1.60487804878,-4.64390243902)
| (-5,-12) | [(-1000000,200),(300000,-40)] | (-4.99494420846,15.3855375282)
| (-5,-12) | [(11,22),(33,44)] | (11,22)
| (10,10) | [(1,2),(3,4)] | (3,4)
| (10,10) | [(0,0),(6,6)] | (6,6)
| (10,10) | [(10,-10),(-3,-4)] | (2.39024390244,-6.48780487805)
| (10,10) | [(-1000000,200),(300000,-40)] | (10.000993742,15.3827690473)
| (10,10) | [(11,22),(33,44)] | (11,22)
(30 rows)
--
-- Boxes
--
SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
six | box
-----+----------------------------------------------------------------
| (7.12132034356,3.12132034356),(2.87867965644,-1.12132034356)
| (71.7106781187,72.7106781187),(-69.7106781187,-68.7106781187)
| (4.53553390593,6.53553390593),(-2.53553390593,-0.535533905933)
| (3.12132034356,4.12132034356),(-1.12132034356,-0.12132034356)
| (107.071067812,207.071067812),(92.9289321881,192.928932188)
| (181.317279836,82.3172798365),(18.6827201635,-80.3172798365)
(6 rows)
-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+-------------------------
| (2,2),(0,0)
| (3,3),(1,1)
| (2.5,3.5),(2.5,2.5)
| (3,3),(3,3)
| (-8,2),(-10,0)
| (-7,3),(-9,1)
| (-7.5,3.5),(-7.5,2.5)
| (-7,3),(-7,3)
| (-1,6),(-3,4)
| (0,7),(-2,5)
| (-0.5,7.5),(-0.5,6.5)
| (0,7),(0,7)
| (7.1,36.5),(5.1,34.5)
| (8.1,37.5),(6.1,35.5)
| (7.6,38),(7.6,37)
| (8.1,37.5),(8.1,37.5)
| (-3,-10),(-5,-12)
| (-2,-9),(-4,-11)
| (-2.5,-8.5),(-2.5,-9.5)
| (-2,-9),(-2,-9)
| (12,12),(10,10)
| (13,13),(11,11)
| (12.5,13.5),(12.5,12.5)
| (13,13),(13,13)
(24 rows)
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | translation
------------+---------------------------
| (2,2),(0,0)
| (3,3),(1,1)
| (2.5,3.5),(2.5,2.5)
| (3,3),(3,3)
| (12,2),(10,0)
| (13,3),(11,1)
| (12.5,3.5),(12.5,2.5)
| (13,3),(13,3)
| (5,-2),(3,-4)
| (6,-1),(4,-3)
| (5.5,-0.5),(5.5,-1.5)
| (6,-1),(6,-1)
| (-3.1,-32.5),(-5.1,-34.5)
| (-2.1,-31.5),(-4.1,-33.5)
| (-2.6,-31),(-2.6,-32)
| (-2.1,-31.5),(-2.1,-31.5)
| (7,14),(5,12)
| (8,15),(6,13)
| (7.5,15.5),(7.5,14.5)
| (8,15),(8,15)
| (-8,-8),(-10,-10)
| (-7,-7),(-9,-9)
| (-7.5,-6.5),(-7.5,-7.5)
| (-7,-7),(-7,-7)
(24 rows)
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
twentyfour | rotation
------------+-----------------------------
| (0,0),(0,0)
| (0,0),(0,0)
| (0,0),(0,0)
| (0,0),(0,0)
| (-0,0),(-20,-20)
| (-10,-10),(-30,-30)
| (-25,-25),(-25,-35)
| (-30,-30),(-30,-30)
| (-0,2),(-14,0)
| (-7,3),(-21,1)
| (-17.5,2.5),(-21.5,-0.5)
| (-21,3),(-21,3)
| (0,79.2),(-58.8,0)
| (-29.4,118.8),(-88.2,39.6)
| (-73.5,104.1),(-108,99)
| (-88.2,118.8),(-88.2,118.8)
| (14,-0),(0,-34)
| (21,-17),(7,-51)
| (29.5,-42.5),(17.5,-47.5)
| (21,-51),(21,-51)
| (0,40),(0,0)
| (0,60),(0,20)
| (0,60),(-10,50)
| (0,60),(0,60)
(24 rows)
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
twenty | rotation
--------+----------------------------------------------------------------------
| (0,-0),(-0.2,-0.2)
| (0.08,-0),(0,-0.56)
| (0.0651176557644,0),(0,-0.0483449262493)
| (-0,0.0828402366864),(-0.201183431953,0)
| (0.2,0),(0,0)
| (-0.1,-0.1),(-0.3,-0.3)
| (0.12,-0.28),(0.04,-0.84)
| (0.0976764836466,-0.0241724631247),(0.0325588278822,-0.072517389374)
| (-0.100591715976,0.12426035503),(-0.301775147929,0.0414201183432)
| (0.3,0),(0.1,0)
| (-0.25,-0.25),(-0.25,-0.35)
| (0.26,-0.7),(0.1,-0.82)
| (0.109762715209,-0.0562379754329),(0.0813970697055,-0.0604311578117)
| (-0.251479289941,0.103550295858),(-0.322485207101,0.0739644970414)
| (0.3,0.05),(0.25,0)
| (-0.3,-0.3),(-0.3,-0.3)
| (0.12,-0.84),(0.12,-0.84)
| (0.0976764836466,-0.072517389374),(0.0976764836466,-0.072517389374)
| (-0.301775147929,0.12426035503),(-0.301775147929,0.12426035503)
| (0.3,0),(0.3,0)
(20 rows)
SELECT f1::box
FROM POINT_TBL;
f1
-----------------------
(0,0),(0,0)
(-10,0),(-10,0)
(-3,4),(-3,4)
(5.1,34.5),(5.1,34.5)
(-5,-12),(-5,-12)
(10,10),(10,10)
(6 rows)
SELECT bound_box(a.f1, b.f1)
FROM BOX_TBL a, BOX_TBL b;
bound_box
---------------------
(2,2),(0,0)
(3,3),(0,0)
(2.5,3.5),(0,0)
(3,3),(0,0)
(3,3),(0,0)
(3,3),(1,1)
(3,3.5),(1,1)
(3,3),(1,1)
(2.5,3.5),(0,0)
(3,3.5),(1,1)
(2.5,3.5),(2.5,2.5)
(3,3.5),(2.5,2.5)
(3,3),(0,0)
(3,3),(1,1)
(3,3.5),(2.5,2.5)
(3,3),(3,3)
(16 rows)
--
-- Paths
--
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
eight | npoints | path
-------+---------+---------------------------
| 2 | [(1,2),(3,4)]
| 2 | ((1,2),(3,4))
| 4 | [(0,0),(3,0),(4,5),(1,6)]
| 2 | ((1,2),(3,4))
| 2 | ((1,2),(3,4))
| 2 | [(1,2),(3,4)]
| 2 | [(11,12),(13,14)]
| 2 | ((11,12),(13,14))
(8 rows)
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
four | path
------+---------------------
| ((2,0),(2,4),(0,0))
| ((3,1),(3,3),(1,0))
| ((0,0))
| ((0,1),(0,1))
(4 rows)
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
eight | dist_add
-------+-----------------------------------
| [(11,12),(13,14)]
| ((11,12),(13,14))
| [(10,10),(13,10),(14,15),(11,16)]
| ((11,12),(13,14))
| ((11,12),(13,14))
| [(11,12),(13,14)]
| [(21,22),(23,24)]
| ((21,22),(23,24))
(8 rows)
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
eight | dist_mul
-------+------------------------------
| [(4,3),(10,5)]
| ((4,3),(10,5))
| [(0,0),(6,-3),(13,6),(8,11)]
| ((4,3),(10,5))
| ((4,3),(10,5))
| [(4,3),(10,5)]
| [(34,13),(40,15)]
| ((34,13),(40,15))
(8 rows)
--
-- Polygons
--
-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 @> p.f1 AS contains
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contains
------------+------------+---------------------+----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((0,0)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((0,0)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((0,0)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((0,0)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 <@ poly.f1 AS contained
FROM POLYGON_TBL poly, POINT_TBL p;
twentyfour | f1 | f1 | contained
------------+------------+---------------------+-----------
| (0,0) | ((2,0),(2,4),(0,0)) | t
| (0,0) | ((3,1),(3,3),(1,0)) | f
| (0,0) | ((0,0)) | t
| (0,0) | ((0,1),(0,1)) | f
| (-10,0) | ((2,0),(2,4),(0,0)) | f
| (-10,0) | ((3,1),(3,3),(1,0)) | f
| (-10,0) | ((0,0)) | f
| (-10,0) | ((0,1),(0,1)) | f
| (-3,4) | ((2,0),(2,4),(0,0)) | f
| (-3,4) | ((3,1),(3,3),(1,0)) | f
| (-3,4) | ((0,0)) | f
| (-3,4) | ((0,1),(0,1)) | f
| (5.1,34.5) | ((2,0),(2,4),(0,0)) | f
| (5.1,34.5) | ((3,1),(3,3),(1,0)) | f
| (5.1,34.5) | ((0,0)) | f
| (5.1,34.5) | ((0,1),(0,1)) | f
| (-5,-12) | ((2,0),(2,4),(0,0)) | f
| (-5,-12) | ((3,1),(3,3),(1,0)) | f
| (-5,-12) | ((0,0)) | f
| (-5,-12) | ((0,1),(0,1)) | f
| (10,10) | ((2,0),(2,4),(0,0)) | f
| (10,10) | ((3,1),(3,3),(1,0)) | f
| (10,10) | ((0,0)) | f
| (10,10) | ((0,1),(0,1)) | f
(24 rows)
SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
FROM POLYGON_TBL;
four | npoints | polygon
------+---------+---------------------
| 3 | ((2,0),(2,4),(0,0))
| 3 | ((3,1),(3,3),(1,0))
| 1 | ((0,0))
| 2 | ((0,1),(0,1))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM BOX_TBL;
four | polygon
------+-------------------------------------------
| ((0,0),(0,2),(2,2),(2,0))
| ((1,1),(1,3),(3,3),(3,1))
| ((2.5,2.5),(2.5,3.5),(2.5,3.5),(2.5,2.5))
| ((3,3),(3,3),(3,3),(3,3))
(4 rows)
SELECT '' AS four, polygon(f1)
FROM PATH_TBL WHERE isclosed(f1);
four | polygon
------+-------------------
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((1,2),(3,4))
| ((11,12),(13,14))
(4 rows)
SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
four | open_path | polygon
------+---------------------------+---------------------------
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(0,0),(3,0),(4,5),(1,6)] | ((0,0),(3,0),(4,5),(1,6))
| [(1,2),(3,4)] | ((1,2),(3,4))
| [(11,12),(13,14)] | ((11,12),(13,14))
(4 rows)
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
six | polygon
-----+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((2,1),(2.40192378865,2.5),(3.5,3.59807621135),(5,4),(6.5,3.59807621135),(7.59807621135,2.5),(8,1),(7.59807621135,-0.5),(6.5,-1.59807621135),(5,-2),(3.5,-1.59807621135),(2.40192378865,-0.5))
| ((-99,2),(-85.6025403784,52),(-49,88.6025403784),(1,102),(51,88.6025403784),(87.6025403784,52),(101,2),(87.6025403784,-48),(51,-84.6025403784),(1,-98),(-49,-84.6025403784),(-85.6025403784,-48))
| ((-4,3),(-3.33012701892,5.5),(-1.5,7.33012701892),(1,8),(3.5,7.33012701892),(5.33012701892,5.5),(6,3),(5.33012701892,0.5),(3.5,-1.33012701892),(1,-2),(-1.5,-1.33012701892),(-3.33012701892,0.5))
| ((-2,2),(-1.59807621135,3.5),(-0.5,4.59807621135),(1,5),(2.5,4.59807621135),(3.59807621135,3.5),(4,2),(3.59807621135,0.5),(2.5,-0.598076211353),(1,-1),(-0.5,-0.598076211353),(-1.59807621135,0.5))
| ((90,200),(91.3397459622,205),(95,208.660254038),(100,210),(105,208.660254038),(108.660254038,205),(110,200),(108.660254038,195),(105,191.339745962),(100,190),(95,191.339745962),(91.3397459622,195))
| ((-15,1),(0.40707856479,58.5),(42.5,100.592921435),(100,116),(157.5,100.592921435),(199.592921435,58.5),(215,1),(199.592921435,-56.5),(157.5,-98.5929214352),(100,-114),(42.5,-98.5929214352),(0.40707856479,-56.5))
(6 rows)
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
six | polygon
-----+------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ((2,1),(2.87867965644,3.12132034356),(5,4),(7.12132034356,3.12132034356),(8,1),(7.12132034356,-1.12132034356),(5,-2),(2.87867965644,-1.12132034356))
| ((-99,2),(-69.7106781187,72.7106781187),(1,102),(71.7106781187,72.7106781187),(101,2),(71.7106781187,-68.7106781187),(1,-98),(-69.7106781187,-68.7106781187))
| ((-4,3),(-2.53553390593,6.53553390593),(1,8),(4.53553390593,6.53553390593),(6,3),(4.53553390593,-0.535533905933),(1,-2),(-2.53553390593,-0.535533905933))
| ((-2,2),(-1.12132034356,4.12132034356),(1,5),(3.12132034356,4.12132034356),(4,2),(3.12132034356,-0.12132034356),(1,-1),(-1.12132034356,-0.12132034356))
| ((90,200),(92.9289321881,207.071067812),(100,210),(107.071067812,207.071067812),(110,200),(107.071067812,192.928932188),(100,190),(92.9289321881,192.928932188))
| ((-15,1),(18.6827201635,82.3172798365),(100,116),(181.317279836,82.3172798365),(215,1),(181.317279836,-80.3172798365),(100,-114),(18.6827201635,-80.3172798365))
(6 rows)
--
-- Circles
--
SELECT '' AS six, circle(f1, 50.0)
FROM POINT_TBL;
six | circle
-----+-----------------
| <(0,0),50>
| <(-10,0),50>
| <(-3,4),50>
| <(5.1,34.5),50>
| <(-5,-12),50>
| <(10,10),50>
(6 rows)
SELECT '' AS four, circle(f1)
FROM BOX_TBL;
four | circle
------+-----------------------
| <(1,1),1.41421356237>
| <(2,2),1.41421356237>
| <(2.5,3),0.5>
| <(3,3),0>
(4 rows)
SELECT '' AS two, circle(f1)
FROM POLYGON_TBL
WHERE (# f1) >= 3;
two | circle
-----+-----------------------------------------------
| <(1.33333333333,1.33333333333),2.04168905064>
| <(2.33333333333,1.33333333333),1.47534300379>
(2 rows)
SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, area(c1.f1), p1.f1[0];
twentyfour | circle | point | distance
------------+----------------+------------+---------------
| <(1,2),3> | (-3,4) | 1.472135955
| <(5,1),3> | (0,0) | 2.09901951359
| <(5,1),3> | (-3,4) | 5.54400374532
| <(1,3),5> | (-10,0) | 6.40175425099
| <(1,3),5> | (10,10) | 6.40175425099
| <(5,1),3> | (10,10) | 7.29563014099
| <(1,2),3> | (-10,0) | 8.1803398875
| <(1,2),3> | (10,10) | 9.04159457879
| <(1,3),5> | (-5,-12) | 11.1554944214
| <(5,1),3> | (-10,0) | 12.0332963784
| <(1,2),3> | (-5,-12) | 12.2315462117
| <(5,1),3> | (-5,-12) | 13.4012194669
| <(1,3),5> | (5.1,34.5) | 26.7657047773
| <(1,2),3> | (5.1,34.5) | 29.7575945393
| <(5,1),3> | (5.1,34.5) | 30.5001492534
| <(100,200),10> | (5.1,34.5) | 180.778038568
| <(100,200),10> | (10,10) | 200.237960416
| <(100,200),10> | (-3,4) | 211.415898255
| <(100,200),10> | (0,0) | 213.60679775
| <(100,200),10> | (-10,0) | 218.25424421
| <(100,200),10> | (-5,-12) | 226.577682802
(21 rows)
......@@ -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)
......@@ -7,6 +7,9 @@ INSERT INTO POINT_TBL(f1) VALUES ('(-10.0,0.0)');
INSERT INTO POINT_TBL(f1) VALUES ('(-3.0,4.0)');
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');
ERROR: invalid input syntax for type point: "asdfasdf"
......@@ -17,20 +20,31 @@ INSERT INTO POINT_TBL(f1) VALUES ('(10.0 10.0)');
ERROR: invalid input syntax for type point: "(10.0 10.0)"
LINE 1: INSERT INTO POINT_TBL(f1) VALUES ('(10.0 10.0)');
^
INSERT INTO POINT_TBL(f1) VALUES ('(10.0, 10.0) x');
ERROR: invalid input syntax for type point: "(10.0, 10.0) x"
LINE 1: INSERT INTO POINT_TBL(f1) VALUES ('(10.0, 10.0) x');
^
INSERT INTO POINT_TBL(f1) VALUES ('(10.0,10.0');
ERROR: invalid input syntax for type point: "(10.0,10.0"
LINE 1: INSERT INTO POINT_TBL(f1) VALUES ('(10.0,10.0');
^
INSERT INTO POINT_TBL(f1) VALUES ('(10.0, 1e+500)'); -- Out of range
ERROR: "1e+500" is out of range for type double precision
LINE 1: INSERT INTO POINT_TBL(f1) VALUES ('(10.0, 1e+500)');
^
SELECT '' AS six, * FROM POINT_TBL;
six | f1
-----+------------
six | f1
-----+-------------------
| (0,0)
| (-10,0)
| (-3,4)
| (5.1,34.5)
| (-5,-12)
| (1e-300,-1e-300)
| (1e+300,Infinity)
| (NaN,NaN)
| (10,10)
(6 rows)
(9 rows)
-- left of
SELECT '' AS three, p.* FROM POINT_TBL p WHERE p.f1 << '(0.0, 0.0)';
......@@ -92,158 +106,268 @@ SELECT '' AS three, p.* FROM POINT_TBL p
SELECT '' AS three, p.* FROM POINT_TBL p
WHERE not p.f1 <@ box '(0,0,100,100)';
three | f1
-------+----------
three | f1
-------+-------------------
| (-10,0)
| (-3,4)
| (-5,-12)
(3 rows)
| (1e-300,-1e-300)
| (1e+300,Infinity)
| (NaN,NaN)
(6 rows)
SELECT '' AS two, p.* FROM POINT_TBL p
WHERE p.f1 <@ path '[(0,0),(-10,0),(-10,10)]';
two | f1
-----+---------
two | f1
-----+------------------
| (0,0)
| (-10,0)
(2 rows)
| (1e-300,-1e-300)
(3 rows)
SELECT '' AS three, p.* FROM POINT_TBL p
WHERE not box '(0,0,100,100)' @> p.f1;
three | f1
-------+----------
three | f1
-------+-------------------
| (-10,0)
| (-3,4)
| (-5,-12)
(3 rows)
| (1e-300,-1e-300)
| (1e+300,Infinity)
| (NaN,NaN)
(6 rows)
SELECT '' AS six, p.f1, p.f1 <-> point '(0,0)' AS dist
FROM POINT_TBL p
ORDER BY dist;
six | f1 | dist
-----+------------+------------------
| (0,0) | 0
| (-3,4) | 5
| (-10,0) | 10
| (-5,-12) | 13
| (10,10) | 14.142135623731
| (5.1,34.5) | 34.8749193547455
(6 rows)
six | f1 | dist
-----+-------------------+----------------------
| (0,0) | 0
| (1e-300,-1e-300) | 1.4142135623731e-300
| (-3,4) | 5
| (-10,0) | 10
| (-5,-12) | 13
| (10,10) | 14.142135623731
| (5.1,34.5) | 34.8749193547455
| (1e+300,Infinity) | Infinity
| (NaN,NaN) | NaN
(9 rows)
SELECT '' AS thirtysix, p1.f1 AS point1, p2.f1 AS point2, p1.f1 <-> p2.f1 AS dist
FROM POINT_TBL p1, POINT_TBL p2
ORDER BY dist, p1.f1[0], p2.f1[0];
thirtysix | point1 | point2 | dist
-----------+------------+------------+------------------
| (-10,0) | (-10,0) | 0
| (-5,-12) | (-5,-12) | 0
| (-3,4) | (-3,4) | 0
| (0,0) | (0,0) | 0
| (5.1,34.5) | (5.1,34.5) | 0
| (10,10) | (10,10) | 0
| (-3,4) | (0,0) | 5
| (0,0) | (-3,4) | 5
| (-10,0) | (-3,4) | 8.06225774829855
| (-3,4) | (-10,0) | 8.06225774829855
| (-10,0) | (0,0) | 10
| (0,0) | (-10,0) | 10
| (-10,0) | (-5,-12) | 13
| (-5,-12) | (-10,0) | 13
| (-5,-12) | (0,0) | 13
| (0,0) | (-5,-12) | 13
| (0,0) | (10,10) | 14.142135623731
| (10,10) | (0,0) | 14.142135623731
| (-3,4) | (10,10) | 14.3178210632764
| (10,10) | (-3,4) | 14.3178210632764
| (-5,-12) | (-3,4) | 16.1245154965971
| (-3,4) | (-5,-12) | 16.1245154965971
| (-10,0) | (10,10) | 22.3606797749979
| (10,10) | (-10,0) | 22.3606797749979
| (5.1,34.5) | (10,10) | 24.9851956166046
| (10,10) | (5.1,34.5) | 24.9851956166046
| (-5,-12) | (10,10) | 26.6270539113887
| (10,10) | (-5,-12) | 26.6270539113887
| (-3,4) | (5.1,34.5) | 31.5572495632937
| (5.1,34.5) | (-3,4) | 31.5572495632937
| (0,0) | (5.1,34.5) | 34.8749193547455
| (5.1,34.5) | (0,0) | 34.8749193547455
| (-10,0) | (5.1,34.5) | 37.6597928831267
| (5.1,34.5) | (-10,0) | 37.6597928831267
| (-5,-12) | (5.1,34.5) | 47.5842410888311
| (5.1,34.5) | (-5,-12) | 47.5842410888311
(36 rows)
thirtysix | point1 | point2 | dist
-----------+-------------------+-------------------+----------------------
| (-10,0) | (-10,0) | 0
| (-5,-12) | (-5,-12) | 0
| (-3,4) | (-3,4) | 0
| (0,0) | (0,0) | 0
| (1e-300,-1e-300) | (1e-300,-1e-300) | 0
| (5.1,34.5) | (5.1,34.5) | 0
| (10,10) | (10,10) | 0
| (0,0) | (1e-300,-1e-300) | 1.4142135623731e-300
| (1e-300,-1e-300) | (0,0) | 1.4142135623731e-300
| (-3,4) | (0,0) | 5
| (-3,4) | (1e-300,-1e-300) | 5
| (0,0) | (-3,4) | 5
| (1e-300,-1e-300) | (-3,4) | 5
| (-10,0) | (-3,4) | 8.06225774829855
| (-3,4) | (-10,0) | 8.06225774829855
| (-10,0) | (0,0) | 10
| (-10,0) | (1e-300,-1e-300) | 10
| (0,0) | (-10,0) | 10
| (1e-300,-1e-300) | (-10,0) | 10
| (-10,0) | (-5,-12) | 13
| (-5,-12) | (-10,0) | 13
| (-5,-12) | (0,0) | 13
| (-5,-12) | (1e-300,-1e-300) | 13
| (0,0) | (-5,-12) | 13
| (1e-300,-1e-300) | (-5,-12) | 13
| (0,0) | (10,10) | 14.142135623731
| (1e-300,-1e-300) | (10,10) | 14.142135623731
| (10,10) | (0,0) | 14.142135623731
| (10,10) | (1e-300,-1e-300) | 14.142135623731
| (-3,4) | (10,10) | 14.3178210632764
| (10,10) | (-3,4) | 14.3178210632764
| (-5,-12) | (-3,4) | 16.1245154965971
| (-3,4) | (-5,-12) | 16.1245154965971
| (-10,0) | (10,10) | 22.3606797749979
| (10,10) | (-10,0) | 22.3606797749979
| (5.1,34.5) | (10,10) | 24.9851956166046
| (10,10) | (5.1,34.5) | 24.9851956166046
| (-5,-12) | (10,10) | 26.6270539113887
| (10,10) | (-5,-12) | 26.6270539113887
| (-3,4) | (5.1,34.5) | 31.5572495632937
| (5.1,34.5) | (-3,4) | 31.5572495632937
| (0,0) | (5.1,34.5) | 34.8749193547455
| (1e-300,-1e-300) | (5.1,34.5) | 34.8749193547455
| (5.1,34.5) | (0,0) | 34.8749193547455
| (5.1,34.5) | (1e-300,-1e-300) | 34.8749193547455
| (-10,0) | (5.1,34.5) | 37.6597928831267
| (5.1,34.5) | (-10,0) | 37.6597928831267
| (-5,-12) | (5.1,34.5) | 47.5842410888311
| (5.1,34.5) | (-5,-12) | 47.5842410888311
| (-10,0) | (1e+300,Infinity) | Infinity
| (-5,-12) | (1e+300,Infinity) | Infinity
| (-3,4) | (1e+300,Infinity) | Infinity
| (0,0) | (1e+300,Infinity) | Infinity
| (1e-300,-1e-300) | (1e+300,Infinity) | Infinity
| (5.1,34.5) | (1e+300,Infinity) | Infinity
| (10,10) | (1e+300,Infinity) | Infinity
| (1e+300,Infinity) | (-10,0) | Infinity
| (1e+300,Infinity) | (-5,-12) | Infinity
| (1e+300,Infinity) | (-3,4) | Infinity
| (1e+300,Infinity) | (0,0) | Infinity
| (1e+300,Infinity) | (1e-300,-1e-300) | Infinity
| (1e+300,Infinity) | (5.1,34.5) | Infinity
| (1e+300,Infinity) | (10,10) | Infinity
| (-10,0) | (NaN,NaN) | NaN
| (-5,-12) | (NaN,NaN) | NaN
| (-3,4) | (NaN,NaN) | NaN
| (0,0) | (NaN,NaN) | NaN
| (1e-300,-1e-300) | (NaN,NaN) | NaN
| (5.1,34.5) | (NaN,NaN) | NaN
| (10,10) | (NaN,NaN) | NaN
| (1e+300,Infinity) | (1e+300,Infinity) | NaN
| (1e+300,Infinity) | (NaN,NaN) | NaN
| (NaN,NaN) | (-10,0) | NaN
| (NaN,NaN) | (-5,-12) | NaN
| (NaN,NaN) | (-3,4) | NaN
| (NaN,NaN) | (0,0) | NaN
| (NaN,NaN) | (1e-300,-1e-300) | NaN
| (NaN,NaN) | (5.1,34.5) | NaN
| (NaN,NaN) | (10,10) | NaN
| (NaN,NaN) | (1e+300,Infinity) | NaN
| (NaN,NaN) | (NaN,NaN) | NaN
(81 rows)
SELECT '' AS thirty, p1.f1 AS point1, p2.f1 AS point2
FROM POINT_TBL p1, POINT_TBL p2
WHERE (p1.f1 <-> p2.f1) > 3;
thirty | point1 | point2
--------+------------+------------
| (0,0) | (-10,0)
| (0,0) | (-3,4)
| (0,0) | (5.1,34.5)
| (0,0) | (-5,-12)
| (0,0) | (10,10)
| (-10,0) | (0,0)
| (-10,0) | (-3,4)
| (-10,0) | (5.1,34.5)
| (-10,0) | (-5,-12)
| (-10,0) | (10,10)
| (-3,4) | (0,0)
| (-3,4) | (-10,0)
| (-3,4) | (5.1,34.5)
| (-3,4) | (-5,-12)
| (-3,4) | (10,10)
| (5.1,34.5) | (0,0)
| (5.1,34.5) | (-10,0)
| (5.1,34.5) | (-3,4)
| (5.1,34.5) | (-5,-12)
| (5.1,34.5) | (10,10)
| (-5,-12) | (0,0)
| (-5,-12) | (-10,0)
| (-5,-12) | (-3,4)
| (-5,-12) | (5.1,34.5)
| (-5,-12) | (10,10)
| (10,10) | (0,0)
| (10,10) | (-10,0)
| (10,10) | (-3,4)
| (10,10) | (5.1,34.5)
| (10,10) | (-5,-12)
(30 rows)
thirty | point1 | point2
--------+-------------------+-------------------
| (0,0) | (-10,0)
| (0,0) | (-3,4)
| (0,0) | (5.1,34.5)
| (0,0) | (-5,-12)
| (0,0) | (1e+300,Infinity)
| (0,0) | (NaN,NaN)
| (0,0) | (10,10)
| (-10,0) | (0,0)
| (-10,0) | (-3,4)
| (-10,0) | (5.1,34.5)
| (-10,0) | (-5,-12)
| (-10,0) | (1e-300,-1e-300)
| (-10,0) | (1e+300,Infinity)
| (-10,0) | (NaN,NaN)
| (-10,0) | (10,10)
| (-3,4) | (0,0)
| (-3,4) | (-10,0)
| (-3,4) | (5.1,34.5)
| (-3,4) | (-5,-12)
| (-3,4) | (1e-300,-1e-300)
| (-3,4) | (1e+300,Infinity)
| (-3,4) | (NaN,NaN)
| (-3,4) | (10,10)
| (5.1,34.5) | (0,0)
| (5.1,34.5) | (-10,0)
| (5.1,34.5) | (-3,4)
| (5.1,34.5) | (-5,-12)
| (5.1,34.5) | (1e-300,-1e-300)
| (5.1,34.5) | (1e+300,Infinity)
| (5.1,34.5) | (NaN,NaN)
| (5.1,34.5) | (10,10)
| (-5,-12) | (0,0)
| (-5,-12) | (-10,0)
| (-5,-12) | (-3,4)
| (-5,-12) | (5.1,34.5)
| (-5,-12) | (1e-300,-1e-300)
| (-5,-12) | (1e+300,Infinity)
| (-5,-12) | (NaN,NaN)
| (-5,-12) | (10,10)
| (1e-300,-1e-300) | (-10,0)
| (1e-300,-1e-300) | (-3,4)
| (1e-300,-1e-300) | (5.1,34.5)
| (1e-300,-1e-300) | (-5,-12)
| (1e-300,-1e-300) | (1e+300,Infinity)
| (1e-300,-1e-300) | (NaN,NaN)
| (1e-300,-1e-300) | (10,10)
| (1e+300,Infinity) | (0,0)
| (1e+300,Infinity) | (-10,0)
| (1e+300,Infinity) | (-3,4)
| (1e+300,Infinity) | (5.1,34.5)
| (1e+300,Infinity) | (-5,-12)
| (1e+300,Infinity) | (1e-300,-1e-300)
| (1e+300,Infinity) | (1e+300,Infinity)
| (1e+300,Infinity) | (NaN,NaN)
| (1e+300,Infinity) | (10,10)
| (NaN,NaN) | (0,0)
| (NaN,NaN) | (-10,0)
| (NaN,NaN) | (-3,4)
| (NaN,NaN) | (5.1,34.5)
| (NaN,NaN) | (-5,-12)
| (NaN,NaN) | (1e-300,-1e-300)
| (NaN,NaN) | (1e+300,Infinity)
| (NaN,NaN) | (NaN,NaN)
| (NaN,NaN) | (10,10)
| (10,10) | (0,0)
| (10,10) | (-10,0)
| (10,10) | (-3,4)
| (10,10) | (5.1,34.5)
| (10,10) | (-5,-12)
| (10,10) | (1e-300,-1e-300)
| (10,10) | (1e+300,Infinity)
| (10,10) | (NaN,NaN)
(72 rows)
-- put distance result into output to allow sorting with GEQ optimizer - tgl 97/05/10
SELECT '' AS fifteen, p1.f1 AS point1, p2.f1 AS point2, (p1.f1 <-> p2.f1) AS distance
FROM POINT_TBL p1, POINT_TBL p2
WHERE (p1.f1 <-> p2.f1) > 3 and p1.f1 << p2.f1
ORDER BY distance, p1.f1[0], p2.f1[0];
fifteen | point1 | point2 | distance
---------+------------+------------+------------------
| (-3,4) | (0,0) | 5
| (-10,0) | (-3,4) | 8.06225774829855
| (-10,0) | (0,0) | 10
| (-10,0) | (-5,-12) | 13
| (-5,-12) | (0,0) | 13
| (0,0) | (10,10) | 14.142135623731
| (-3,4) | (10,10) | 14.3178210632764
| (-5,-12) | (-3,4) | 16.1245154965971
| (-10,0) | (10,10) | 22.3606797749979
| (5.1,34.5) | (10,10) | 24.9851956166046
| (-5,-12) | (10,10) | 26.6270539113887
| (-3,4) | (5.1,34.5) | 31.5572495632937
| (0,0) | (5.1,34.5) | 34.8749193547455
| (-10,0) | (5.1,34.5) | 37.6597928831267
| (-5,-12) | (5.1,34.5) | 47.5842410888311
(15 rows)
fifteen | point1 | point2 | distance
---------+------------------+-------------------+------------------
| (-3,4) | (0,0) | 5
| (-3,4) | (1e-300,-1e-300) | 5
| (-10,0) | (-3,4) | 8.06225774829855
| (-10,0) | (0,0) | 10
| (-10,0) | (1e-300,-1e-300) | 10
| (-10,0) | (-5,-12) | 13
| (-5,-12) | (0,0) | 13
| (-5,-12) | (1e-300,-1e-300) | 13
| (0,0) | (10,10) | 14.142135623731
| (1e-300,-1e-300) | (10,10) | 14.142135623731
| (-3,4) | (10,10) | 14.3178210632764
| (-5,-12) | (-3,4) | 16.1245154965971
| (-10,0) | (10,10) | 22.3606797749979
| (5.1,34.5) | (10,10) | 24.9851956166046
| (-5,-12) | (10,10) | 26.6270539113887
| (-3,4) | (5.1,34.5) | 31.5572495632937
| (0,0) | (5.1,34.5) | 34.8749193547455
| (1e-300,-1e-300) | (5.1,34.5) | 34.8749193547455
| (-10,0) | (5.1,34.5) | 37.6597928831267
| (-5,-12) | (5.1,34.5) | 47.5842410888311
| (-10,0) | (1e+300,Infinity) | Infinity
| (-5,-12) | (1e+300,Infinity) | Infinity
| (-3,4) | (1e+300,Infinity) | Infinity
| (0,0) | (1e+300,Infinity) | Infinity
| (1e-300,-1e-300) | (1e+300,Infinity) | Infinity
| (5.1,34.5) | (1e+300,Infinity) | Infinity
| (10,10) | (1e+300,Infinity) | Infinity
(27 rows)
-- put distance result into output to allow sorting with GEQ optimizer - tgl 97/05/10
SELECT '' AS three, p1.f1 AS point1, p2.f1 AS point2, (p1.f1 <-> p2.f1) AS distance
FROM POINT_TBL p1, POINT_TBL p2
WHERE (p1.f1 <-> p2.f1) > 3 and p1.f1 << p2.f1 and p1.f1 >^ p2.f1
ORDER BY distance;
three | point1 | point2 | distance
-------+------------+----------+------------------
| (-3,4) | (0,0) | 5
| (-10,0) | (-5,-12) | 13
| (5.1,34.5) | (10,10) | 24.9851956166046
(3 rows)
three | point1 | point2 | distance
-------+------------+------------------+------------------
| (-3,4) | (0,0) | 5
| (-3,4) | (1e-300,-1e-300) | 5
| (-10,0) | (-5,-12) | 13
| (5.1,34.5) | (10,10) | 24.9851956166046
(4 rows)
-- Test that GiST indexes provide same behavior as sequential scan
CREATE TEMP TABLE point_gist_tbl(f1 point);
......
......@@ -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)');
......
......@@ -46,6 +46,103 @@ SELECT '' AS one, p1.f1
FROM POINT_TBL p1
WHERE p1.f1 ?| point '(5.1,34.5)';
-- Slope
SELECT p1.f1, p2.f1, slope(p1.f1, p2.f1) FROM POINT_TBL p1, POINT_TBL p2;
-- Add point
SELECT p1.f1, p2.f1, p1.f1 + p2.f1 FROM POINT_TBL p1, POINT_TBL p2;
-- Subtract point
SELECT p1.f1, p2.f1, p1.f1 - p2.f1 FROM POINT_TBL p1, POINT_TBL p2;
-- Multiply with point
SELECT p1.f1, p2.f1, p1.f1 * p2.f1 FROM POINT_TBL p1, POINT_TBL p2 WHERE p1.f1[0] BETWEEN 1 AND 1000;
-- Underflow error
SELECT p1.f1, p2.f1, p1.f1 * p2.f1 FROM POINT_TBL p1, POINT_TBL p2 WHERE p1.f1[0] < 1;
-- Divide by point
SELECT p1.f1, p2.f1, p1.f1 / p2.f1 FROM POINT_TBL p1, POINT_TBL p2 WHERE p2.f1[0] BETWEEN 1 AND 1000;
-- Overflow error
SELECT p1.f1, p2.f1, p1.f1 / p2.f1 FROM POINT_TBL p1, POINT_TBL p2 WHERE p2.f1[0] > 1000;
-- Division by 0 error
SELECT p1.f1, p2.f1, p1.f1 / p2.f1 FROM POINT_TBL p1, POINT_TBL p2 WHERE p2.f1 ~= '(0,0)'::point;
-- Distance to line
SELECT p.f1, l.s, p.f1 <-> l.s FROM POINT_TBL p, LINE_TBL l;
-- Distance to line segment
SELECT p.f1, l.s, p.f1 <-> l.s FROM POINT_TBL p, LSEG_TBL l;
-- Distance to box
SELECT p.f1, b.f1, p.f1 <-> b.f1 FROM POINT_TBL p, BOX_TBL b;
-- Distance to path
SELECT p.f1, p1.f1, p.f1 <-> p1.f1 FROM POINT_TBL p, PATH_TBL p1;
-- Distance to polygon
SELECT p.f1, p1.f1, p.f1 <-> p1.f1 FROM POINT_TBL p, POLYGON_TBL p1;
-- Closest point to line
SELECT p.f1, l.s, p.f1 ## l.s FROM POINT_TBL p, LINE_TBL l;
-- Closest point to line segment
SELECT p.f1, l.s, p.f1 ## l.s FROM POINT_TBL p, LSEG_TBL l;
-- Closest point to box
SELECT p.f1, b.f1, p.f1 ## b.f1 FROM POINT_TBL p, BOX_TBL b;
-- On line
SELECT p.f1, l.s FROM POINT_TBL p, LINE_TBL l WHERE p.f1 <@ l.s;
-- On line segment
SELECT p.f1, l.s FROM POINT_TBL p, LSEG_TBL l WHERE p.f1 <@ l.s;
-- On path
SELECT p.f1, p1.f1 FROM POINT_TBL p, PATH_TBL p1 WHERE p.f1 <@ p1.f1;
--
-- Lines
--
-- Vertical
SELECT s FROM LINE_TBL WHERE ?| s;
-- Horizontal
SELECT s FROM LINE_TBL WHERE ?- s;
-- Same as line
SELECT l1.s, l2.s FROM LINE_TBL l1, LINE_TBL l2 WHERE l1.s = l2.s;
-- Parallel to line
SELECT l1.s, l2.s FROM LINE_TBL l1, LINE_TBL l2 WHERE l1.s ?|| l2.s;
-- Perpendicular to line
SELECT l1.s, l2.s FROM LINE_TBL l1, LINE_TBL l2 WHERE l1.s ?-| l2.s;
-- Distance to line
SELECT l1.s, l2.s, l1.s <-> l2.s FROM LINE_TBL l1, LINE_TBL l2;
-- Distance to box
SELECT l.s, b.f1, l.s <-> b.f1 FROM LINE_TBL l, BOX_TBL b;
-- Intersect with line
SELECT l1.s, l2.s FROM LINE_TBL l1, LINE_TBL l2 WHERE l1.s ?# l2.s;
-- Intersect with box
SELECT l.s, b.f1 FROM LINE_TBL l, BOX_TBL b WHERE l.s ?# b.f1;
-- Intersection point with line
SELECT l1.s, l2.s, l1.s # l2.s FROM LINE_TBL l1, LINE_TBL l2;
-- Closest point to line segment
SELECT l.s, l1.s, l.s ## l1.s FROM LINE_TBL l, LSEG_TBL l1;
-- Closest point to box
SELECT l.s, b.f1, l.s ## b.f1 FROM LINE_TBL l, BOX_TBL b;
--
-- Line segments
--
......@@ -54,9 +151,77 @@ SELECT '' AS one, p1.f1
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
FROM LSEG_TBL l, POINT_TBL p;
-- Length
SELECT s, @-@ s FROM LSEG_TBL;
-- Vertical
SELECT s FROM LSEG_TBL WHERE ?| s;
-- Horizontal
SELECT s FROM LSEG_TBL WHERE ?- s;
-- Center
SELECT s, @@ s FROM LSEG_TBL;
-- To point
SELECT s, s::point FROM LSEG_TBL;
-- Has points less than line segment
SELECT l1.s, l2.s FROM LSEG_TBL l1, LSEG_TBL l2 WHERE l1.s < l2.s;
-- Has points less than or equal to line segment
SELECT l1.s, l2.s FROM LSEG_TBL l1, LSEG_TBL l2 WHERE l1.s <= l2.s;
-- Has points equal to line segment
SELECT l1.s, l2.s FROM LSEG_TBL l1, LSEG_TBL l2 WHERE l1.s = l2.s;
-- Has points greater than or equal to line segment
SELECT l1.s, l2.s FROM LSEG_TBL l1, LSEG_TBL l2 WHERE l1.s >= l2.s;
-- Has points greater than line segment
SELECT l1.s, l2.s FROM LSEG_TBL l1, LSEG_TBL l2 WHERE l1.s > l2.s;
-- Has points not equal to line segment
SELECT l1.s, l2.s FROM LSEG_TBL l1, LSEG_TBL l2 WHERE l1.s != l2.s;
-- Parallel with line segment
SELECT l1.s, l2.s FROM LSEG_TBL l1, LSEG_TBL l2 WHERE l1.s ?|| l2.s;
-- Perpendicular with line segment
SELECT l1.s, l2.s FROM LSEG_TBL l1, LSEG_TBL l2 WHERE l1.s ?-| l2.s;
-- Distance to line
SELECT l.s, l1.s, l.s <-> l1.s FROM LSEG_TBL l, LINE_TBL l1;
-- Distance to line segment
SELECT l1.s, l2.s, l1.s <-> l2.s FROM LSEG_TBL l1, LSEG_TBL l2;
-- Distance to box
SELECT l.s, b.f1, l.s <-> b.f1 FROM LSEG_TBL l, BOX_TBL b;
-- Intersect with line segment
SELECT l.s, l1.s FROM LSEG_TBL l, LINE_TBL l1 WHERE l.s ?# l1.s;
-- Intersect with box
SELECT l.s, b.f1 FROM LSEG_TBL l, BOX_TBL b WHERE l.s ?# b.f1;
-- Intersection point with line segment
SELECT l1.s, l2.s, l1.s # l2.s FROM LSEG_TBL l1, LSEG_TBL l2;
-- Closest point to line
SELECT l.s, l1.s, l.s ## l1.s FROM LSEG_TBL l, LINE_TBL l1;
-- Closest point to line segment
SELECT l1.s, l2.s, l1.s ## l2.s FROM LSEG_TBL l1, LSEG_TBL l2;
-- Closest point to box
SELECT l.s, b.f1, l.s ## b.f1 FROM LSEG_TBL l, BOX_TBL b;
-- On line
SELECT l.s, l1.s FROM LSEG_TBL l, LINE_TBL l1 WHERE l.s <@ l1.s;
-- On box
SELECT l.s, b.f1 FROM LSEG_TBL l, BOX_TBL b WHERE l.s <@ b.f1;
--
-- Boxes
......@@ -71,35 +236,94 @@ SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
FROM BOX_TBL b, POINT_TBL p;
-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p;
-- Multiply with point
SELECT b.f1, p.f1, b.f1 * p.f1 FROM BOX_TBL b, POINT_TBL p WHERE p.f1[0] BETWEEN 1 AND 1000;
-- Overflow error
SELECT b.f1, p.f1, b.f1 * p.f1 FROM BOX_TBL b, POINT_TBL p WHERE p.f1[0] > 1000;
SELECT '' AS twenty, b.f1 / p.f1 AS rotation
FROM BOX_TBL b, POINT_TBL p
WHERE (p.f1 <-> point '(0,0)') >= 1;
-- Divide by point
SELECT b.f1, p.f1, b.f1 / p.f1 FROM BOX_TBL b, POINT_TBL p WHERE p.f1[0] BETWEEN 1 AND 1000;
-- To box
SELECT f1::box
FROM POINT_TBL;
SELECT bound_box(a.f1, b.f1)
FROM BOX_TBL a, BOX_TBL b;
-- Below box
SELECT b1.f1, b2.f1, b1.f1 <^ b2.f1 FROM BOX_TBL b1, BOX_TBL b2;
-- Above box
SELECT b1.f1, b2.f1, b1.f1 >^ b2.f1 FROM BOX_TBL b1, BOX_TBL b2;
-- Intersection point with box
SELECT b1.f1, b2.f1, b1.f1 # b2.f1 FROM BOX_TBL b1, BOX_TBL b2;
-- Diagonal
SELECT f1, diagonal(f1) FROM BOX_TBL;
-- Distance to box
SELECT b1.f1, b2.f1, b1.f1 <-> b2.f1 FROM BOX_TBL b1, BOX_TBL b2;
--
-- Paths
--
SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
-- Points
SELECT f1, npoints(f1) FROM PATH_TBL;
-- Area
SELECT f1, area(f1) FROM PATH_TBL;
SELECT '' AS four, path(f1) FROM POLYGON_TBL;
-- Length
SELECT f1, @-@ f1 FROM PATH_TBL;
-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
FROM PATH_TBL p1;
-- Center
SELECT f1, @@ f1 FROM PATH_TBL;
-- To polygon
SELECT f1, f1::polygon FROM PATH_TBL WHERE isclosed(f1);
-- Open path cannot be converted to polygon error
SELECT f1, f1::polygon FROM PATH_TBL WHERE isopen(f1);
-- Has points less than path
SELECT p1.f1, p2.f1 FROM PATH_TBL p1, PATH_TBL p2 WHERE p1.f1 < p2.f1;
-- Has points less than or equal to path
SELECT p1.f1, p2.f1 FROM PATH_TBL p1, PATH_TBL p2 WHERE p1.f1 <= p2.f1;
-- Has points equal to path
SELECT p1.f1, p2.f1 FROM PATH_TBL p1, PATH_TBL p2 WHERE p1.f1 = p2.f1;
-- Has points greater than or equal to path
SELECT p1.f1, p2.f1 FROM PATH_TBL p1, PATH_TBL p2 WHERE p1.f1 >= p2.f1;
-- Has points greater than path
SELECT p1.f1, p2.f1 FROM PATH_TBL p1, PATH_TBL p2 WHERE p1.f1 > p2.f1;
-- Add path
SELECT p1.f1, p2.f1, p1.f1 + p2.f1 FROM PATH_TBL p1, PATH_TBL p2;
-- Add point
SELECT p.f1, p1.f1, p.f1 + p1.f1 FROM PATH_TBL p, POINT_TBL p1;
-- Subtract point
SELECT p.f1, p1.f1, p.f1 - p1.f1 FROM PATH_TBL p, POINT_TBL p1;
-- Multiply with point
SELECT p.f1, p1.f1, p.f1 * p1.f1 FROM PATH_TBL p, POINT_TBL p1;
-- Divide by point
SELECT p.f1, p1.f1, p.f1 / p1.f1 FROM PATH_TBL p, POINT_TBL p1 WHERE p1.f1[0] BETWEEN 1 AND 1000;
-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
FROM PATH_TBL p1;
-- Division by 0 error
SELECT p.f1, p1.f1, p.f1 / p1.f1 FROM PATH_TBL p, POINT_TBL p1 WHERE p1.f1 ~= '(0,0)'::point;
-- Distance to path
SELECT p1.f1, p2.f1, p1.f1 <-> p2.f1 FROM PATH_TBL p1, PATH_TBL p2;
--
-- Polygons
......@@ -125,13 +349,50 @@ SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
FROM PATH_TBL
WHERE isopen(f1);
-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
FROM CIRCLE_TBL;
-- To box
SELECT f1, f1::box FROM POLYGON_TBL;
-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
FROM CIRCLE_TBL;
-- To path
SELECT f1, f1::path FROM POLYGON_TBL;
-- Same as polygon
SELECT p1.f1, p2.f1 FROM POLYGON_TBL p1, POLYGON_TBL p2 WHERE p1.f1 ~= p2.f1;
-- Contained by polygon
SELECT p1.f1, p2.f1 FROM POLYGON_TBL p1, POLYGON_TBL p2 WHERE p1.f1 <@ p2.f1;
-- Contains polygon
SELECT p1.f1, p2.f1 FROM POLYGON_TBL p1, POLYGON_TBL p2 WHERE p1.f1 @> p2.f1;
-- Overlap with polygon
SELECT p1.f1, p2.f1 FROM POLYGON_TBL p1, POLYGON_TBL p2 WHERE p1.f1 && p2.f1;
-- Left of polygon
SELECT p1.f1, p2.f1 FROM POLYGON_TBL p1, POLYGON_TBL p2 WHERE p1.f1 << p2.f1;
-- Overlap of left of polygon
SELECT p1.f1, p2.f1 FROM POLYGON_TBL p1, POLYGON_TBL p2 WHERE p1.f1 &< p2.f1;
-- Right of polygon
SELECT p1.f1, p2.f1 FROM POLYGON_TBL p1, POLYGON_TBL p2 WHERE p1.f1 >> p2.f1;
-- Overlap of right of polygon
SELECT p1.f1, p2.f1 FROM POLYGON_TBL p1, POLYGON_TBL p2 WHERE p1.f1 &> p2.f1;
-- Below polygon
SELECT p1.f1, p2.f1 FROM POLYGON_TBL p1, POLYGON_TBL p2 WHERE p1.f1 <<| p2.f1;
-- Overlap or below polygon
SELECT p1.f1, p2.f1 FROM POLYGON_TBL p1, POLYGON_TBL p2 WHERE p1.f1 &<| p2.f1;
-- Above polygon
SELECT p1.f1, p2.f1 FROM POLYGON_TBL p1, POLYGON_TBL p2 WHERE p1.f1 |>> p2.f1;
-- Overlap or above polygon
SELECT p1.f1, p2.f1 FROM POLYGON_TBL p1, POLYGON_TBL p2 WHERE p1.f1 |&> p2.f1;
-- Distance to polygon
SELECT p1.f1, p2.f1, p1.f1 <-> p2.f1 FROM POLYGON_TBL p1, POLYGON_TBL p2;
--
-- Circles
......@@ -151,3 +412,96 @@ SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS d
FROM CIRCLE_TBL c1, POINT_TBL p1
WHERE (p1.f1 <-> c1.f1) > 0
ORDER BY distance, area(c1.f1), p1.f1[0];
-- To polygon
SELECT f1, f1::polygon FROM CIRCLE_TBL WHERE f1 >= '<(0,0),1>';
-- To polygon with less points
SELECT f1, polygon(8, f1) FROM CIRCLE_TBL WHERE f1 >= '<(0,0),1>';
-- Too less points error
SELECT f1, polygon(1, f1) FROM CIRCLE_TBL WHERE f1 >= '<(0,0),1>';
-- Zero radius error
SELECT f1, polygon(10, f1) FROM CIRCLE_TBL WHERE f1 < '<(0,0),1>';
-- Same as circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 ~= c2.f1;
-- Overlap with circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 && c2.f1;
-- Overlap or left of circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 &< c2.f1;
-- Left of circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 << c2.f1;
-- Right of circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 >> c2.f1;
-- Overlap or right of circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 &> c2.f1;
-- Contained by circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 <@ c2.f1;
-- Contain by circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 @> c2.f1;
-- Below circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 <<| c2.f1;
-- Above circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 |>> c2.f1;
-- Overlap or below circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 &<| c2.f1;
-- Overlap or above circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 |&> c2.f1;
-- Area equal with circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 = c2.f1;
-- Area not equal with circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 != c2.f1;
-- Area less than circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 < c2.f1;
-- Area greater than circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 > c2.f1;
-- Area less than or equal circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 <= c2.f1;
-- Area greater than or equal circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 >= c2.f1;
-- Area less than circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 < c2.f1;
-- Area greater than circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 < c2.f1;
-- Add point
SELECT c.f1, p.f1, c.f1 + p.f1 FROM CIRCLE_TBL c, POINT_TBL p;
-- Subtract point
SELECT c.f1, p.f1, c.f1 - p.f1 FROM CIRCLE_TBL c, POINT_TBL p;
-- Multiply with point
SELECT c.f1, p.f1, c.f1 * p.f1 FROM CIRCLE_TBL c, POINT_TBL p;
-- Divide by point
SELECT c.f1, p.f1, c.f1 / p.f1 FROM CIRCLE_TBL c, POINT_TBL p WHERE p.f1[0] BETWEEN 1 AND 1000;
-- Overflow error
SELECT c.f1, p.f1, c.f1 / p.f1 FROM CIRCLE_TBL c, POINT_TBL p WHERE p.f1[0] > 1000;
-- Division by 0 error
SELECT c.f1, p.f1, c.f1 / p.f1 FROM CIRCLE_TBL c, POINT_TBL p WHERE p.f1 ~= '(0,0)'::point;
-- Distance to polygon
SELECT c.f1, p.f1, c.f1 <-> p.f1 FROM CIRCLE_TBL c, POLYGON_TBL p;
......@@ -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