diff -Nru pgsphere-1.4.2/Makefile pgsphere-1.5.1/Makefile --- pgsphere-1.4.2/Makefile 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/Makefile 2024-04-22 06:22:05.000000000 +0000 @@ -34,12 +34,15 @@ pg_sphere--1.3.0--1.3.1.sql \ pg_sphere--1.3.1--1.4.0.sql \ pg_sphere--1.4.0--1.4.1.sql \ - pg_sphere--1.4.1--1.4.2.sql + pg_sphere--1.4.1--1.4.2.sql \ + pg_sphere--1.4.2--1.5.0.sql \ + pg_sphere--1.5.0--1.5.1.sql DOCS = README.pg_sphere COPYRIGHT.pg_sphere TESTS = version tables points euler circle line ellipse poly path box \ index contains_ops contains_ops_compat bounding_box_gist gnomo \ - epochprop contains overlaps spoint_brin sbox_brin selectivity + epochprop contains overlaps spoint_brin sbox_brin selectivity \ + knn output_precision REGRESS = init $(TESTS) PG_CFLAGS += -DPGSPHERE_VERSION=$(PGSPHERE_VERSION) @@ -209,6 +212,12 @@ pg_sphere--1.4.0--1.4.1.sql pg_sphere--1.4.1--1.4.2.sql: @echo "-- Nothing to upgrade in the schema" > $@ +pg_sphere--1.4.2--1.5.0.sql: + cat upgrade_scripts/$@.in $^ > $@ + +pg_sphere--1.5.0--1.5.1.sql: + cat upgrade_scripts/$@.in $^ > $@ + # end of local stuff src/sscan.o : src/sparse.c @@ -254,3 +263,10 @@ --excludes=pgindent-excludes.list \ --indent=${PGBSDINDENT} \ src + +pgindent-headers: + $(PGINDENT) \ + --typedefs=pgindent-typedefs.list \ + --excludes=pgindent-excludes.list \ + --indent=${PGBSDINDENT} \ + src/*.h diff -Nru pgsphere-1.4.2/Makefile.common.mk pgsphere-1.5.1/Makefile.common.mk --- pgsphere-1.4.2/Makefile.common.mk 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/Makefile.common.mk 2024-04-22 06:22:05.000000000 +0000 @@ -5,4 +5,4 @@ #---------------------------------------------------------------------------- EXTENSION := pg_sphere -PGSPHERE_VERSION := 1.4.2 +PGSPHERE_VERSION := 1.5.1 diff -Nru pgsphere-1.4.2/debian/changelog pgsphere-1.5.1/debian/changelog --- pgsphere-1.4.2/debian/changelog 2023-12-20 10:52:33.000000000 +0000 +++ pgsphere-1.5.1/debian/changelog 2024-05-01 09:31:49.000000000 +0000 @@ -1,3 +1,15 @@ +pgsphere (1.5.1-1) unstable; urgency=medium + + * New upstream version 1.5.1. + + -- Christoph Berg Wed, 01 May 2024 11:31:49 +0200 + +pgsphere (1.5.1~rc1-1) unstable; urgency=medium + + * New upstream version 1.5.1~rc1. + + -- Christoph Berg Mon, 29 Apr 2024 14:08:34 +0200 + pgsphere (1.4.2-1) unstable; urgency=medium * New upstream version 1.4.2. diff -Nru pgsphere-1.4.2/debian/watch pgsphere-1.5.1/debian/watch --- pgsphere-1.4.2/debian/watch 2023-07-31 15:12:32.000000000 +0000 +++ pgsphere-1.5.1/debian/watch 2024-04-29 12:08:08.000000000 +0000 @@ -1,2 +1,3 @@ version=4 +opts=uversionmangle=s/-rc/~rc/; \ https://github.com/postgrespro/pgsphere/tags .*/(.*).tar.gz diff -Nru pgsphere-1.4.2/doc/indices.sgm pgsphere-1.5.1/doc/indices.sgm --- pgsphere-1.4.2/doc/indices.sgm 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/doc/indices.sgm 2024-04-22 06:22:05.000000000 +0000 @@ -69,6 +69,11 @@ + A GiST index can be also used for quickly finding the points closest to the given one + when ordering by an expression with the <-> operator, + as shown in an example below. + + BRIN indexing supports just spherical points (spoint) and spherical coordinates range (sbox) at the moment. @@ -83,6 +88,13 @@ + To find the points closest to a given spherical position, use the <-> operator: + + + spoint (0.2, 0.3) LIMIT 10 ]]> + + + BRIN index can be created through the following syntax: diff -Nru pgsphere-1.4.2/expected/bounding_box_gist.out pgsphere-1.5.1/expected/bounding_box_gist.out --- pgsphere-1.4.2/expected/bounding_box_gist.out 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/expected/bounding_box_gist.out 2024-04-22 06:22:05.000000000 +0000 @@ -1,3 +1,4 @@ +SET extra_float_digits = 2; SET enable_seqscan=true; CREATE TABLE bbox_ellipse (e sellipse not null); INSERT INTO bbox_ellipse VALUES ('<{10d, 0.1d}, (0d,0d), 0d>'); @@ -20,19 +21,19 @@ (1 row) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_ellipse WHERE spoint '(5d, 0d)' @ e; - QUERY PLAN ----------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------ Aggregate -> Seq Scan on bbox_ellipse - Filter: ('(0.0872664625997165 , 0)'::spoint @ e) + Filter: ('(0.087266462599716474 , 0)'::spoint @ e) (3 rows) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_ellipse WHERE spoint '(5d, 0d)' <@ e; - QUERY PLAN ------------------------------------------------------------ + QUERY PLAN +------------------------------------------------------------- Aggregate -> Seq Scan on bbox_ellipse - Filter: ('(0.0872664625997165 , 0)'::spoint <@ e) + Filter: ('(0.087266462599716474 , 0)'::spoint <@ e) (3 rows) -- The ellipse has semi-major axis length of 10 degrees along the equator, @@ -53,19 +54,19 @@ (1 row) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_ellipse WHERE spoint '(5d, 0d)' @ e; - QUERY PLAN --------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------- Aggregate -> Index Scan using idx_bbox_ellipse on bbox_ellipse - Index Cond: ('(0.0872664625997165 , 0)'::spoint @ e) + Index Cond: ('(0.087266462599716474 , 0)'::spoint @ e) (3 rows) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_ellipse WHERE spoint '(5d, 0d)' <@ e; - QUERY PLAN ---------------------------------------------------------------- + QUERY PLAN +----------------------------------------------------------------- Aggregate -> Index Scan using idx_bbox_ellipse on bbox_ellipse - Index Cond: ('(0.0872664625997165 , 0)'::spoint <@ e) + Index Cond: ('(0.087266462599716474 , 0)'::spoint <@ e) (3 rows) SET enable_seqscan=true; @@ -170,11 +171,11 @@ (1 row) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_path WHERE sline(spoint '(0d, -10d)', spoint '(0d, 10d)') && p; - QUERY PLAN --------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------------------- Aggregate -> Seq Scan on bbox_path - Filter: ('( 6.10865238198015, 1.5707963267949, 0, ZXZ ), 0.349065850398866'::sline && p) + Filter: ('( 6.1086523819801535, 1.5707963267948966, 0, ZXZ ), 0.34906585039886584'::sline && p) (3 rows) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_path WHERE spoint '(0d, 0d)' @ p; @@ -215,11 +216,11 @@ (1 row) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_path WHERE sline(spoint '(0d, -10d)', spoint '(0d, 10d)') && p; - QUERY PLAN ------------------------------------------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------------------------------- Aggregate -> Index Scan using idx_bbox_path on bbox_path - Index Cond: ('( 6.10865238198015, 1.5707963267949, 0, ZXZ ), 0.349065850398866'::sline && p) + Index Cond: ('( 6.1086523819801535, 1.5707963267948966, 0, ZXZ ), 0.34906585039886584'::sline && p) (3 rows) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_path WHERE spoint '(0d, 0d)' @ p; diff -Nru pgsphere-1.4.2/expected/bounding_box_gist_1.out pgsphere-1.5.1/expected/bounding_box_gist_1.out --- pgsphere-1.4.2/expected/bounding_box_gist_1.out 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/expected/bounding_box_gist_1.out 2024-04-22 06:22:05.000000000 +0000 @@ -1,3 +1,4 @@ +SET extra_float_digits = 2; SET enable_seqscan=true; CREATE TABLE bbox_ellipse (e sellipse not null); INSERT INTO bbox_ellipse VALUES ('<{10d, 0.1d}, (0d,0d), 0d>'); @@ -20,19 +21,19 @@ (1 row) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_ellipse WHERE spoint '(5d, 0d)' @ e; - QUERY PLAN ----------------------------------------------------------- + QUERY PLAN +----------------------------------------------------------- Aggregate -> Seq Scan on bbox_ellipse - Filter: ('(0.0872664625997165 , 0)'::spoint @ e) + Filter: ('(0.08726646259971647 , 0)'::spoint @ e) (3 rows) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_ellipse WHERE spoint '(5d, 0d)' <@ e; - QUERY PLAN ------------------------------------------------------------ + QUERY PLAN +------------------------------------------------------------ Aggregate -> Seq Scan on bbox_ellipse - Filter: ('(0.0872664625997165 , 0)'::spoint <@ e) + Filter: ('(0.08726646259971647 , 0)'::spoint <@ e) (3 rows) -- The ellipse has semi-major axis length of 10 degrees along the equator, @@ -53,19 +54,19 @@ (1 row) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_ellipse WHERE spoint '(5d, 0d)' @ e; - QUERY PLAN --------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------- Aggregate -> Index Scan using idx_bbox_ellipse on bbox_ellipse - Index Cond: (e ~ '(0.0872664625997165 , 0)'::spoint) + Index Cond: (e ~ '(0.08726646259971647 , 0)'::spoint) (3 rows) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_ellipse WHERE spoint '(5d, 0d)' <@ e; - QUERY PLAN ---------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------- Aggregate -> Index Scan using idx_bbox_ellipse on bbox_ellipse - Index Cond: (e @> '(0.0872664625997165 , 0)'::spoint) + Index Cond: (e @> '(0.08726646259971647 , 0)'::spoint) (3 rows) SET enable_seqscan=true; @@ -170,11 +171,11 @@ (1 row) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_path WHERE sline(spoint '(0d, -10d)', spoint '(0d, 10d)') && p; - QUERY PLAN --------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------------------- Aggregate -> Seq Scan on bbox_path - Filter: ('( 6.10865238198015, 1.5707963267949, 0, ZXZ ), 0.349065850398866'::sline && p) + Filter: ('( 6.1086523819801535, 1.5707963267948966, 0, ZXZ ), 0.34906585039886584'::sline && p) (3 rows) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_path WHERE spoint '(0d, 0d)' @ p; @@ -215,11 +216,11 @@ (1 row) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_path WHERE sline(spoint '(0d, -10d)', spoint '(0d, 10d)') && p; - QUERY PLAN ------------------------------------------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------------------------------- Aggregate -> Index Scan using idx_bbox_path on bbox_path - Index Cond: (p && '( 6.10865238198015, 1.5707963267949, 0, ZXZ ), 0.349065850398866'::sline) + Index Cond: (p && '( 6.1086523819801535, 1.5707963267948966, 0, ZXZ ), 0.34906585039886584'::sline) (3 rows) EXPLAIN (COSTS OFF) SELECT COUNT(*) FROM bbox_path WHERE spoint '(0d, 0d)' @ p; diff -Nru pgsphere-1.4.2/expected/epochprop.out pgsphere-1.5.1/expected/epochprop.out --- pgsphere-1.4.2/expected/epochprop.out 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/expected/epochprop.out 2024-04-22 06:22:05.000000000 +0000 @@ -1,3 +1,4 @@ +SET extra_float_digits = 2; SELECT to_char(DEGREES(tp[1]), '999D9999999999'), to_char(DEGREES(tp[2]), '999D9999999999'), @@ -92,16 +93,16 @@ 23, RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), -110, 20) AS tp; - tp ------------------------------------------ - (4.70274792658313 , 0.0829194509345993) + tp +--------------------------------------------- + (4.7027479265831289 , 0.082919450934599334) (1 row) SELECT epoch_prop_pos(spoint(radians(269.45207695), radians(4.693364966)), RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), 20) AS tp; - tp ------------------------------------------ - (4.70274793061952 , 0.0829193989380876) + tp +--------------------------------------------- + (4.7027479306195161 , 0.082919398938087627) (1 row) diff -Nru pgsphere-1.4.2/expected/epochprop_1.out pgsphere-1.5.1/expected/epochprop_1.out --- pgsphere-1.4.2/expected/epochprop_1.out 1970-01-01 00:00:00.000000000 +0000 +++ pgsphere-1.5.1/expected/epochprop_1.out 2024-04-22 06:22:05.000000000 +0000 @@ -0,0 +1,108 @@ +SET extra_float_digits = 2; +SELECT + to_char(DEGREES(tp[1]), '999D9999999999'), + to_char(DEGREES(tp[2]), '999D9999999999'), + to_char(tp[3], '999D999'), + to_char(DEGREES(tp[4])*3.6e6, '999D999'), + to_char(DEGREES(tp[5])*3.6e6, '99999D999'), + to_char(tp[6], '999D999') +FROM ( + SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)), + 546.9759, + RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), -110, + -100) AS tp) AS q; + to_char | to_char | to_char | to_char | to_char | to_char +-----------------+-----------------+----------+----------+------------+---------- + 269.4742714391 | 4.4072939987 | 543.624 | -791.442 | 10235.412 | -110.450 +(1 row) + +SELECT + to_char(DEGREES(tp[1]), '999D9999999999'), + to_char(DEGREES(tp[2]), '999D9999999999'), + to_char(tp[3], '999D999'), + to_char(DEGREES(tp[4])*3.6e6, '999D999'), + to_char(DEGREES(tp[5])*3.6e6, '99999D999'), + to_char(tp[6], '999D999') +FROM ( + SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)), + 0, + RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), -110, + -100) AS tp) AS q; + to_char | to_char | to_char | to_char | to_char | to_char +-----------------+-----------------+---------+----------+------------+--------- + 269.4744079540 | 4.4055337210 | | -801.210 | 10361.762 | +(1 row) + +SELECT + to_char(DEGREES(tp[1]), '999D9999999999'), + to_char(DEGREES(tp[2]), '999D9999999999'), + to_char(tp[3], '999D999'), + to_char(DEGREES(tp[4])*3.6e6, '999D999'), + to_char(DEGREES(tp[5])*3.6e6, '99999D999'), + to_char(tp[6], '999D999') +FROM ( + SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)), + NULL, + RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), -110, + -100) AS tp) AS q; + to_char | to_char | to_char | to_char | to_char | to_char +-----------------+-----------------+---------+----------+------------+--------- + 269.4744079540 | 4.4055337210 | | -801.210 | 10361.762 | +(1 row) + +SELECT + to_char(DEGREES(tp[1]), '999D9999999999'), + to_char(DEGREES(tp[2]), '999D9999999999'), + to_char(tp[3], '999D999'), + to_char(DEGREES(tp[4])*3.6e6, '999D999'), + to_char(DEGREES(tp[5])*3.6e6, '99999D999'), + to_char(tp[6], '999D999') +FROM ( + SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)), + 23, + RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), NULL, + 20) AS tp) AS q; + to_char | to_char | to_char | to_char | to_char | to_char +-----------------+-----------------+----------+----------+------------+---------- + 269.4476085384 | 4.7509315989 | 23.000 | -801.617 | 10361.984 | 2.159 +(1 row) + +SELECT + to_char(DEGREES(tp[1]), '999D9999999999'), + to_char(DEGREES(tp[2]), '999D9999999999'), + to_char(tp[3], '999D999'), + to_char(DEGREES(tp[4])*3.6e6, '999D999'), + to_char(DEGREES(tp[5])*3.6e6, '99999D999'), + to_char(tp[6], '999D999') +FROM ( + SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)), + 23, + NULL, RADIANS(10362/3.6e6), -110, + 120) AS tp) AS q; + to_char | to_char | to_char | to_char | to_char | to_char +-----------------+-----------------+----------+----------+------------+---------- + 269.4520769500 | 5.0388680565 | 23.007 | -.000 | 10368.061 | -97.120 +(1 row) + +SELECT epoch_prop(NULL, + 23, + 0.01 , RADIANS(10362/3.6e6), -110, + 120); +ERROR: NULL position not supported in epoch propagation +SELECT epoch_prop_pos(spoint(radians(269.45207695), radians(4.693364966)), + 23, + RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), -110, + 20) AS tp; + tp +------------------------------------------- + (4.702747926583129 , 0.08291945093459933) +(1 row) + +SELECT epoch_prop_pos(spoint(radians(269.45207695), radians(4.693364966)), + RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), + 20) AS tp; + tp +------------------------------------------- + (4.702747930619516 , 0.08291939893808763) +(1 row) + diff -Nru pgsphere-1.4.2/expected/knn.out pgsphere-1.5.1/expected/knn.out --- pgsphere-1.4.2/expected/knn.out 1970-01-01 00:00:00.000000000 +0000 +++ pgsphere-1.5.1/expected/knn.out 2024-04-22 06:22:05.000000000 +0000 @@ -0,0 +1,122 @@ +CREATE TABLE points (id int, p spoint, pos int); +INSERT INTO points (id, p) SELECT x, spoint(random()*6.28, (2*random()-1)*1.57) FROM generate_series(1,314159) x; +CREATE INDEX i ON points USING gist (p); +SET enable_indexscan = true; +EXPLAIN (costs off) SELECT p <-> spoint (0.2, 0.3) FROM points ORDER BY 1 LIMIT 100; + QUERY PLAN +------------------------------------------------- + Limit + -> Index Scan using i on points + Order By: (p <-> '(0.2 , 0.3)'::spoint) +(3 rows) + +UPDATE points SET pos = n FROM + (SELECT id, row_number() OVER (ORDER BY p <-> spoint (0.2, 0.3)) n FROM points ORDER BY p <-> spoint (0.2, 0.3) LIMIT 100) sel + WHERE points.id = sel.id; +SET enable_indexscan = false; +SELECT pos, row_number() OVER (ORDER BY p <-> spoint (0.2, 0.3)) n FROM points ORDER BY p <-> spoint (0.2, 0.3) LIMIT 100; + pos | n +-----+----- + 1 | 1 + 2 | 2 + 3 | 3 + 4 | 4 + 5 | 5 + 6 | 6 + 7 | 7 + 8 | 8 + 9 | 9 + 10 | 10 + 11 | 11 + 12 | 12 + 13 | 13 + 14 | 14 + 15 | 15 + 16 | 16 + 17 | 17 + 18 | 18 + 19 | 19 + 20 | 20 + 21 | 21 + 22 | 22 + 23 | 23 + 24 | 24 + 25 | 25 + 26 | 26 + 27 | 27 + 28 | 28 + 29 | 29 + 30 | 30 + 31 | 31 + 32 | 32 + 33 | 33 + 34 | 34 + 35 | 35 + 36 | 36 + 37 | 37 + 38 | 38 + 39 | 39 + 40 | 40 + 41 | 41 + 42 | 42 + 43 | 43 + 44 | 44 + 45 | 45 + 46 | 46 + 47 | 47 + 48 | 48 + 49 | 49 + 50 | 50 + 51 | 51 + 52 | 52 + 53 | 53 + 54 | 54 + 55 | 55 + 56 | 56 + 57 | 57 + 58 | 58 + 59 | 59 + 60 | 60 + 61 | 61 + 62 | 62 + 63 | 63 + 64 | 64 + 65 | 65 + 66 | 66 + 67 | 67 + 68 | 68 + 69 | 69 + 70 | 70 + 71 | 71 + 72 | 72 + 73 | 73 + 74 | 74 + 75 | 75 + 76 | 76 + 77 | 77 + 78 | 78 + 79 | 79 + 80 | 80 + 81 | 81 + 82 | 82 + 83 | 83 + 84 | 84 + 85 | 85 + 86 | 86 + 87 | 87 + 88 | 88 + 89 | 89 + 90 | 90 + 91 | 91 + 92 | 92 + 93 | 93 + 94 | 94 + 95 | 95 + 96 | 96 + 97 | 97 + 98 | 98 + 99 | 99 + 100 | 100 +(100 rows) + +DROP TABLE points; diff -Nru pgsphere-1.4.2/expected/output_precision.out pgsphere-1.5.1/expected/output_precision.out --- pgsphere-1.4.2/expected/output_precision.out 1970-01-01 00:00:00.000000000 +0000 +++ pgsphere-1.5.1/expected/output_precision.out 2024-04-22 06:22:05.000000000 +0000 @@ -0,0 +1,212 @@ +-- +-- Test default and custom output precisions for double values. +-- +SELECT set_sphere_output( 'RAD' ); + set_sphere_output +------------------- + SET RAD +(1 row) + +-- +-- Check default precision +-- +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +-- +-- Check option extra_float_digits +-- +SET extra_float_digits TO -6; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +----------------------------- + (0.272707696 , 0.018180513) +(1 row) + +SET extra_float_digits TO -2; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +-------------------------------------- + (0.2727076956241 , 0.01818051304161) +(1 row) + +SET extra_float_digits TO 0; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SET extra_float_digits TO 1; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SET extra_float_digits TO 2; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +---------------------------------------------- + (0.27270769562411401 , 0.018180513041607602) +(1 row) + +SET extra_float_digits TO 3; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +----------------------------------------------- + (0.27270769562411401 , 0.0181805130416076016) +(1 row) + +SET extra_float_digits TO 6; +ERROR: 6 is outside the valid range for parameter "extra_float_digits" (-15 .. 3) +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +----------------------------------------------- + (0.27270769562411401 , 0.0181805130416076016) +(1 row) + +-- +-- Check compatibility behaviour +-- +SELECT set_sphere_output_precision(10); + set_sphere_output_precision +----------------------------- + SET 10 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +-------------------------------- + (0.2727076956 , 0.01818051304) +(1 row) + +SELECT set_sphere_output_precision(12); + set_sphere_output_precision +----------------------------- + SET 12 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------ + (0.272707695624 , 0.0181805130416) +(1 row) + +SELECT set_sphere_output_precision(15); + set_sphere_output_precision +----------------------------- + SET 15 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SELECT set_sphere_output_precision(17); + set_sphere_output_precision +----------------------------- + SET 15 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SELECT set_sphere_output_precision(20); + set_sphere_output_precision +----------------------------- + SET 15 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SELECT set_sphere_output_precision(0); + set_sphere_output_precision +----------------------------- + SET 15 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SELECT set_sphere_output_precision(-3); + set_sphere_output_precision +----------------------------- + SET 15 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +-- +-- Check extra_float_digits after set_sphere_output_precision. +-- The change of extra_float_digits should not affect the precision of pgsphere +-- output because set_sphere_output_precision enables compatibility mode. +-- +SELECT set_sphere_output_precision(10); + set_sphere_output_precision +----------------------------- + SET 10 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +-------------------------------- + (0.2727076956 , 0.01818051304) +(1 row) + +SET extra_float_digits TO -6; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +-------------------------------- + (0.2727076956 , 0.01818051304) +(1 row) + +SET extra_float_digits TO -10; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +-------------------------------- + (0.2727076956 , 0.01818051304) +(1 row) + +-- +-- Check reset_sphere_output_precision. +-- It should disable compatibility mode - extra_float_digits should work. +-- +SELECT reset_sphere_output_precision(); + reset_sphere_output_precision +------------------------------- + RESET +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +---------------------- + (0.27271 , 0.018181) +(1 row) + +SET extra_float_digits TO -6; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +----------------------------- + (0.272707696 , 0.018180513) +(1 row) + diff -Nru pgsphere-1.4.2/expected/output_precision_1.out pgsphere-1.5.1/expected/output_precision_1.out --- pgsphere-1.4.2/expected/output_precision_1.out 1970-01-01 00:00:00.000000000 +0000 +++ pgsphere-1.5.1/expected/output_precision_1.out 2024-04-22 06:22:05.000000000 +0000 @@ -0,0 +1,212 @@ +-- +-- Test default and custom output precisions for double values. +-- +SELECT set_sphere_output( 'RAD' ); + set_sphere_output +------------------- + SET RAD +(1 row) + +-- +-- Check default precision +-- +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +-- +-- Check option extra_float_digits +-- +SET extra_float_digits TO -6; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +----------------------------- + (0.272707696 , 0.018180513) +(1 row) + +SET extra_float_digits TO -2; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +-------------------------------------- + (0.2727076956241 , 0.01818051304161) +(1 row) + +SET extra_float_digits TO 0; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SET extra_float_digits TO 1; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SET extra_float_digits TO 2; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SET extra_float_digits TO 3; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SET extra_float_digits TO 6; +ERROR: 6 is outside the valid range for parameter "extra_float_digits" (-15 .. 3) +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +-- +-- Check compatibility behaviour +-- +SELECT set_sphere_output_precision(10); + set_sphere_output_precision +----------------------------- + SET 10 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +-------------------------------- + (0.2727076956 , 0.01818051304) +(1 row) + +SELECT set_sphere_output_precision(12); + set_sphere_output_precision +----------------------------- + SET 12 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------ + (0.272707695624 , 0.0181805130416) +(1 row) + +SELECT set_sphere_output_precision(15); + set_sphere_output_precision +----------------------------- + SET 15 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SELECT set_sphere_output_precision(17); + set_sphere_output_precision +----------------------------- + SET 15 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SELECT set_sphere_output_precision(20); + set_sphere_output_precision +----------------------------- + SET 15 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SELECT set_sphere_output_precision(0); + set_sphere_output_precision +----------------------------- + SET 15 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +SELECT set_sphere_output_precision(-3); + set_sphere_output_precision +----------------------------- + SET 15 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +------------------------------------------ + (0.272707695624114 , 0.0181805130416076) +(1 row) + +-- +-- Check extra_float_digits after set_sphere_output_precision. +-- The change of extra_float_digits should not affect the precision of pgsphere +-- output because set_sphere_output_precision enables compatibility mode. +-- +SELECT set_sphere_output_precision(10); + set_sphere_output_precision +----------------------------- + SET 10 +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +-------------------------------- + (0.2727076956 , 0.01818051304) +(1 row) + +SET extra_float_digits TO -6; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +-------------------------------- + (0.2727076956 , 0.01818051304) +(1 row) + +SET extra_float_digits TO -10; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +-------------------------------- + (0.2727076956 , 0.01818051304) +(1 row) + +-- +-- Check reset_sphere_output_precision. +-- It should disable compatibility mode - extra_float_digits should work. +-- +SELECT reset_sphere_output_precision(); + reset_sphere_output_precision +------------------------------- + RESET +(1 row) + +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +---------------------- + (0.27271 , 0.018181) +(1 row) + +SET extra_float_digits TO -6; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + spoint +----------------------------- + (0.272707696 , 0.018180513) +(1 row) + diff -Nru pgsphere-1.4.2/expected/version.out pgsphere-1.5.1/expected/version.out --- pgsphere-1.4.2/expected/version.out 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/expected/version.out 2024-04-22 06:22:05.000000000 +0000 @@ -2,6 +2,6 @@ SELECT pg_sphere_version(); pg_sphere_version ------------------- - 1.4.2 + 1.5.1 (1 row) diff -Nru pgsphere-1.4.2/pg_sphere.control pgsphere-1.5.1/pg_sphere.control --- pgsphere-1.4.2/pg_sphere.control 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/pg_sphere.control 2024-04-22 06:22:05.000000000 +0000 @@ -1,5 +1,5 @@ # pg_sphere extension comment = 'spherical objects with useful functions, operators and index support' -default_version = '1.4.2' +default_version = '1.5.1' module_pathname = '$libdir/pg_sphere' relocatable = true diff -Nru pgsphere-1.4.2/pgindent-excludes.list pgsphere-1.5.1/pgindent-excludes.list --- pgsphere-1.4.2/pgindent-excludes.list 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/pgindent-excludes.list 2024-04-22 06:22:05.000000000 +0000 @@ -1 +1,3 @@ pgs_process_moc.h +pgs_healpix.h +pgs_moc.h diff -Nru pgsphere-1.4.2/pgs_gist.sql.in pgsphere-1.5.1/pgs_gist.sql.in --- pgsphere-1.4.2/pgs_gist.sql.in 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/pgs_gist.sql.in 2024-04-22 06:22:05.000000000 +0000 @@ -98,12 +98,15 @@ AS 'MODULE_PATHNAME', 'g_spoint_compress' LANGUAGE 'c'; - CREATE FUNCTION g_spoint_consistent(internal, internal, int4, oid, internal) RETURNS internal AS 'MODULE_PATHNAME', 'g_spoint_consistent' LANGUAGE 'c'; +CREATE FUNCTION g_spoint_distance(internal, spoint, smallint, oid, internal) + RETURNS internal + AS 'MODULE_PATHNAME', 'g_spoint_distance' + LANGUAGE 'c'; CREATE OPERATOR CLASS spoint DEFAULT FOR TYPE spoint USING gist AS @@ -114,6 +117,7 @@ OPERATOR 14 @ (spoint, spoly), OPERATOR 15 @ (spoint, sellipse), OPERATOR 16 @ (spoint, sbox), + OPERATOR 17 <-> (spoint, spoint) FOR ORDER BY float_ops, OPERATOR 37 <@ (spoint, scircle), OPERATOR 38 <@ (spoint, sline), OPERATOR 39 <@ (spoint, spath), @@ -127,6 +131,7 @@ FUNCTION 5 g_spherekey_penalty (internal, internal, internal), FUNCTION 6 g_spherekey_picksplit (internal, internal), FUNCTION 7 g_spherekey_same (spherekey, spherekey, internal), + FUNCTION 8 g_spoint_distance (internal, spoint, smallint, oid, internal), STORAGE spherekey; diff -Nru pgsphere-1.4.2/pgs_point.sql.in pgsphere-1.5.1/pgs_point.sql.in --- pgsphere-1.4.2/pgs_point.sql.in 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/pgs_point.sql.in 2024-04-22 06:22:05.000000000 +0000 @@ -26,6 +26,11 @@ AS 'MODULE_PATHNAME', 'set_sphere_output_precision' LANGUAGE 'c'; +CREATE FUNCTION reset_sphere_output_precision() + RETURNS CSTRING + AS 'MODULE_PATHNAME', 'reset_sphere_output_precision' + LANGUAGE 'c'; + CREATE FUNCTION set_sphere_output(CSTRING) RETURNS CSTRING AS 'MODULE_PATHNAME', 'set_sphere_output' @@ -175,4 +180,3 @@ COMMENT ON OPERATOR <-> (spoint, spoint) IS 'distance between spherical points'; - diff -Nru pgsphere-1.4.2/sql/bounding_box_gist.sql pgsphere-1.5.1/sql/bounding_box_gist.sql --- pgsphere-1.4.2/sql/bounding_box_gist.sql 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/sql/bounding_box_gist.sql 2024-04-22 06:22:05.000000000 +0000 @@ -1,3 +1,4 @@ +SET extra_float_digits = 2; SET enable_seqscan=true; CREATE TABLE bbox_ellipse (e sellipse not null); INSERT INTO bbox_ellipse VALUES ('<{10d, 0.1d}, (0d,0d), 0d>'); diff -Nru pgsphere-1.4.2/sql/epochprop.sql pgsphere-1.5.1/sql/epochprop.sql --- pgsphere-1.4.2/sql/epochprop.sql 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/sql/epochprop.sql 2024-04-22 06:22:05.000000000 +0000 @@ -1,3 +1,5 @@ +SET extra_float_digits = 2; + SELECT to_char(DEGREES(tp[1]), '999D9999999999'), to_char(DEGREES(tp[2]), '999D9999999999'), diff -Nru pgsphere-1.4.2/sql/knn.sql pgsphere-1.5.1/sql/knn.sql --- pgsphere-1.4.2/sql/knn.sql 1970-01-01 00:00:00.000000000 +0000 +++ pgsphere-1.5.1/sql/knn.sql 2024-04-22 06:22:05.000000000 +0000 @@ -0,0 +1,12 @@ +CREATE TABLE points (id int, p spoint, pos int); +INSERT INTO points (id, p) SELECT x, spoint(random()*6.28, (2*random()-1)*1.57) FROM generate_series(1,314159) x; +CREATE INDEX i ON points USING gist (p); +SET enable_indexscan = true; +EXPLAIN (costs off) SELECT p <-> spoint (0.2, 0.3) FROM points ORDER BY 1 LIMIT 100; +UPDATE points SET pos = n FROM + (SELECT id, row_number() OVER (ORDER BY p <-> spoint (0.2, 0.3)) n FROM points ORDER BY p <-> spoint (0.2, 0.3) LIMIT 100) sel + WHERE points.id = sel.id; +SET enable_indexscan = false; +SELECT pos, row_number() OVER (ORDER BY p <-> spoint (0.2, 0.3)) n FROM points ORDER BY p <-> spoint (0.2, 0.3) LIMIT 100; +DROP TABLE points; + diff -Nru pgsphere-1.4.2/sql/output_precision.sql pgsphere-1.5.1/sql/output_precision.sql --- pgsphere-1.4.2/sql/output_precision.sql 1970-01-01 00:00:00.000000000 +0000 +++ pgsphere-1.5.1/sql/output_precision.sql 2024-04-22 06:22:05.000000000 +0000 @@ -0,0 +1,82 @@ +-- +-- Test default and custom output precisions for double values. +-- + +SELECT set_sphere_output( 'RAD' ); + +-- +-- Check default precision +-- +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +-- +-- Check option extra_float_digits +-- +SET extra_float_digits TO -6; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SET extra_float_digits TO -2; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SET extra_float_digits TO 0; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SET extra_float_digits TO 1; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SET extra_float_digits TO 2; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SET extra_float_digits TO 3; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SET extra_float_digits TO 6; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +-- +-- Check compatibility behaviour +-- +SELECT set_sphere_output_precision(10); +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SELECT set_sphere_output_precision(12); +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SELECT set_sphere_output_precision(15); +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SELECT set_sphere_output_precision(17); +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SELECT set_sphere_output_precision(20); +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SELECT set_sphere_output_precision(0); +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SELECT set_sphere_output_precision(-3); +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +-- +-- Check extra_float_digits after set_sphere_output_precision. +-- The change of extra_float_digits should not affect the precision of pgsphere +-- output because set_sphere_output_precision enables compatibility mode. +-- +SELECT set_sphere_output_precision(10); +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SET extra_float_digits TO -6; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SET extra_float_digits TO -10; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +-- +-- Check reset_sphere_output_precision. +-- It should disable compatibility mode - extra_float_digits should work. +-- +SELECT reset_sphere_output_precision(); +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; + +SET extra_float_digits TO -6; +SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint; diff -Nru pgsphere-1.4.2/src/box.h pgsphere-1.5.1/src/box.h --- pgsphere-1.4.2/src/box.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/box.h 2024-04-22 06:22:05.000000000 +0000 @@ -11,8 +11,8 @@ */ typedef struct { - SPoint sw; /* South-west value of a box */ - SPoint ne; /* North-east value of a box */ + SPoint sw; /* South-west value of a box */ + SPoint ne; /* North-east value of a box */ } SBOX; @@ -56,373 +56,373 @@ /* * Checks whether two boxes are equal. */ -bool sbox_eq(SBOX *b1, SBOX *b2); +extern bool sbox_eq(SBOX *b1, SBOX *b2); /* * Checks whether a point is contained by a box. */ -bool sbox_cont_point(const SBOX *b, const SPoint *p); +extern bool sbox_cont_point(const SBOX *b, const SPoint *p); /* * Input function of a box. */ -Datum spherebox_in(PG_FUNCTION_ARGS); +extern Datum spherebox_in(PG_FUNCTION_ARGS); /* * Input function of a box from two points. The first point * is the south-west position, the second the north-east position. */ -Datum spherebox_in_from_points(PG_FUNCTION_ARGS); +extern Datum spherebox_in_from_points(PG_FUNCTION_ARGS); /* * Returns the south-west edge of a box. */ -Datum spherebox_sw(PG_FUNCTION_ARGS); +extern Datum spherebox_sw(PG_FUNCTION_ARGS); /* * Returns the north-east edge of a box. */ -Datum spherebox_ne(PG_FUNCTION_ARGS); +extern Datum spherebox_ne(PG_FUNCTION_ARGS); /* * Returns the south-east edge of a box. */ -Datum spherebox_se(PG_FUNCTION_ARGS); +extern Datum spherebox_se(PG_FUNCTION_ARGS); /* * Returns the north-west edge of a box. */ -Datum spherebox_nw(PG_FUNCTION_ARGS); +extern Datum spherebox_nw(PG_FUNCTION_ARGS); /* * Returns the area of a box. */ -Datum spherebox_area(PG_FUNCTION_ARGS); +extern Datum spherebox_area(PG_FUNCTION_ARGS); /* * Returns the circumference of a box. */ -Datum spherebox_circ(PG_FUNCTION_ARGS); +extern Datum spherebox_circ(PG_FUNCTION_ARGS); /* * Checks whether two boxes are equal. */ -Datum spherebox_equal(PG_FUNCTION_ARGS); +extern Datum spherebox_equal(PG_FUNCTION_ARGS); /* * Checks whether two boxes are not equal. */ -Datum spherebox_equal_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_equal_neg(PG_FUNCTION_ARGS); /* * Checks whether a point is contained by a box. */ -Datum spherebox_cont_point(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_point(PG_FUNCTION_ARGS); /* * Checks whether a point isn't contained by a box. */ -Datum spherebox_cont_point_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_point_neg(PG_FUNCTION_ARGS); /* * Checks whether a point is contained by a box. */ -Datum spherebox_cont_point_com(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_point_com(PG_FUNCTION_ARGS); /* * Checks whether a point isn't contained by a box. */ -Datum spherebox_cont_point_com_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_point_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a circle. */ -Datum spherebox_cont_circle(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_circle(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a circle. */ -Datum spherebox_cont_circle_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a circle. */ -Datum spherebox_cont_circle_com(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_circle_com(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a circle. */ -Datum spherebox_cont_circle_com_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a box. */ -Datum spherecircle_cont_box(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_box(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a box. */ -Datum spherecircle_cont_box_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_box_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a box. */ -Datum spherecircle_cont_box_com(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_box_com(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a box. */ -Datum spherecircle_cont_box_com_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_box_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and a box overlap. */ -Datum spherebox_overlap_circle(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_circle(PG_FUNCTION_ARGS); /* * Checks whether a circle and a box don't overlap. */ -Datum spherebox_overlap_circle_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and a box overlap. */ -Datum spherebox_overlap_circle_com(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_circle_com(PG_FUNCTION_ARGS); /* * Checks whether a circle and a box don't overlap. */ -Datum spherebox_overlap_circle_com_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a line. */ -Datum spherebox_cont_line(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_line(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a line. */ -Datum spherebox_cont_line_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_line_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a line. */ -Datum spherebox_cont_line_com(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_line_com(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a line. */ -Datum spherebox_cont_line_com_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box and a line overlap. */ -Datum spherebox_overlap_line(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_line(PG_FUNCTION_ARGS); /* * Checks whether a box and a line don't overlap. */ -Datum spherebox_overlap_line_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_line_neg(PG_FUNCTION_ARGS); /* * Checks whether a box and a line overlap. */ -Datum spherebox_overlap_line_com(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_line_com(PG_FUNCTION_ARGS); /* * Checks whether a box and a line don't overlap. */ -Datum spherebox_overlap_line_com_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a path. */ -Datum spherebox_cont_path(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_path(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a path. */ -Datum spherebox_cont_path_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_path_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a path. */ -Datum spherebox_cont_path_com(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_path_com(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a path. */ -Datum spherebox_cont_path_com_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box and a path overlap. */ -Datum spherebox_overlap_path(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_path(PG_FUNCTION_ARGS); /* * Checks whether a box and a path don't overlap. */ -Datum spherebox_overlap_path_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_path_neg(PG_FUNCTION_ARGS); /* * Checks whether a box and a path overlap. */ -Datum spherebox_overlap_path_com(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_path_com(PG_FUNCTION_ARGS); /* * Checks whether a box and a path don't overlap. */ -Datum spherebox_overlap_path_com_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a polygon. */ -Datum spherebox_cont_poly(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_poly(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a polygon. */ -Datum spherebox_cont_poly_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_poly_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains a polygon. */ -Datum spherebox_cont_poly_com(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_poly_com(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain a polygon. */ -Datum spherebox_cont_poly_com_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_poly_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a box. */ -Datum spherepoly_cont_box(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_box(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a box. */ -Datum spherepoly_cont_box_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_box_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a box. */ -Datum spherepoly_cont_box_com(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_box_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a box. */ -Datum spherepoly_cont_box_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_box_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a box overlap. */ -Datum spherebox_overlap_poly(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_poly(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a box don't overlap. */ -Datum spherebox_overlap_poly_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_poly_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a box overlap. */ -Datum spherebox_overlap_poly_com(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_poly_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a box don't overlap. */ -Datum spherebox_overlap_poly_com_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_poly_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains an ellipse. */ -Datum spherebox_cont_ellipse(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_ellipse(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain an ellipse. */ -Datum spherebox_cont_ellipse_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_ellipse_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains an ellipse. */ -Datum spherebox_cont_ellipse_com(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_ellipse_com(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain an ellipse. */ -Datum spherebox_cont_ellipse_com_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_ellipse_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a box. */ -Datum sphereellipse_cont_box(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_box(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a box. */ -Datum sphereellipse_cont_box_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_box_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a box. */ -Datum sphereellipse_cont_box_com(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_box_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a box. */ -Datum sphereellipse_cont_box_com_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_box_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a box overlap. */ -Datum spherebox_overlap_ellipse(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_ellipse(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a box don't overlap. */ -Datum spherebox_overlap_ellipse_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_ellipse_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a box overlap. */ -Datum spherebox_overlap_ellipse_com(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_ellipse_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a box don't overlap. */ -Datum spherebox_overlap_ellipse_com_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_ellipse_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains another box. */ -Datum spherebox_cont_box(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_box(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain another box. */ -Datum spherebox_cont_box_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_box_neg(PG_FUNCTION_ARGS); /* * Checks whether a box contains another box. */ -Datum spherebox_cont_box_com(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_box_com(PG_FUNCTION_ARGS); /* * Checks whether a box doesn't contain another box. */ -Datum spherebox_cont_box_com_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_cont_box_com_neg(PG_FUNCTION_ARGS); /* * Checks whether two boxes overlap. */ -Datum spherebox_overlap_box(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_box(PG_FUNCTION_ARGS); /* * Checks whether two boxes don't overlap. */ -Datum spherebox_overlap_box_neg(PG_FUNCTION_ARGS); +extern Datum spherebox_overlap_box_neg(PG_FUNCTION_ARGS); #endif diff -Nru pgsphere-1.4.2/src/circle.h pgsphere-1.5.1/src/circle.h --- pgsphere-1.4.2/src/circle.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/circle.h 2024-04-22 06:22:05.000000000 +0000 @@ -10,151 +10,151 @@ */ typedef struct { - SPoint center; /* the center of circle */ - float8 radius; /* the circle radius in radians */ + SPoint center; /* the center of circle */ + float8 radius; /* the circle radius in radians */ } SCIRCLE; /* * Checks whether two circles are equal. */ -bool scircle_eq(const SCIRCLE *c1, const SCIRCLE *c2); +extern bool scircle_eq(const SCIRCLE *c1, const SCIRCLE *c2); /* * Checks whether a circle contains a point. */ -bool spoint_in_circle(const SPoint *p, const SCIRCLE *c); +extern bool spoint_in_circle(const SPoint *p, const SCIRCLE *c); /* * Transforms a circle using an Euler transformation. */ -void euler_scircle_trans(SCIRCLE *out, const SCIRCLE *in, const SEuler *se); +extern void euler_scircle_trans(SCIRCLE *out, const SCIRCLE *in, const SEuler *se); /* * Takes the input and stores it as a spherical circle. */ -Datum spherecircle_in(PG_FUNCTION_ARGS); +extern Datum spherecircle_in(PG_FUNCTION_ARGS); /* * Checks whether two circles are equal. */ -Datum spherecircle_equal(PG_FUNCTION_ARGS); +extern Datum spherecircle_equal(PG_FUNCTION_ARGS); /* * Checks whether two circles are not equal. */ -Datum spherecircle_equal_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_equal_neg(PG_FUNCTION_ARGS); /* * Calculate the distance of two circles. If they overlap, this function * returns 0.0. */ -Datum spherecircle_distance(PG_FUNCTION_ARGS); +extern Datum spherecircle_distance(PG_FUNCTION_ARGS); /* * Calculate the distance of a circle and a point. If a circle contains a point, * this function returns 0.0. */ -Datum spherecircle_point_distance(PG_FUNCTION_ARGS); +extern Datum spherecircle_point_distance(PG_FUNCTION_ARGS); /* * Calculate the distance of a point and a circle. If a circle contains a point, * this function returns 0.0. */ -Datum spherecircle_point_distance_com(PG_FUNCTION_ARGS); +extern Datum spherecircle_point_distance_com(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a point. */ -Datum spherepoint_in_circle(PG_FUNCTION_ARGS); +extern Datum spherepoint_in_circle(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a point. */ -Datum spherepoint_in_circle_neg(PG_FUNCTION_ARGS); +extern Datum spherepoint_in_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a point. */ -Datum spherepoint_in_circle_com(PG_FUNCTION_ARGS); +extern Datum spherepoint_in_circle_com(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a point. */ -Datum spherepoint_in_circle_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepoint_in_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle is contained by other circle. */ -Datum spherecircle_in_circle(PG_FUNCTION_ARGS); +extern Datum spherecircle_in_circle(PG_FUNCTION_ARGS); /* * Checks whether a circle is not contained by other circle. */ -Datum spherecircle_in_circle_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_in_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains other circle. */ -Datum spherecircle_in_circle_com(PG_FUNCTION_ARGS); +extern Datum spherecircle_in_circle_com(PG_FUNCTION_ARGS); /* * Checks whether circle does not contain other circle. */ -Datum spherecircle_in_circle_com_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_in_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether two circles overlap. */ -Datum spherecircle_overlap(PG_FUNCTION_ARGS); +extern Datum spherecircle_overlap(PG_FUNCTION_ARGS); /* * Checks whether two circles overlap. */ -Datum spherecircle_overlap_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_overlap_neg(PG_FUNCTION_ARGS); /* * Returns the center of a circle. */ -Datum spherecircle_center(PG_FUNCTION_ARGS); +extern Datum spherecircle_center(PG_FUNCTION_ARGS); /* * Returns the radius of a circle. */ -Datum spherecircle_radius(PG_FUNCTION_ARGS); +extern Datum spherecircle_radius(PG_FUNCTION_ARGS); /* * Converts a point to a circle. */ -Datum spherepoint_to_circle(PG_FUNCTION_ARGS); +extern Datum spherepoint_to_circle(PG_FUNCTION_ARGS); /* * Creates a circle from center and radius. */ -Datum spherecircle_by_center(PG_FUNCTION_ARGS); +extern Datum spherecircle_by_center(PG_FUNCTION_ARGS); /* * Creates a circle from center and radius(in degrees). */ -Datum spherecircle_by_center_deg(PG_FUNCTION_ARGS); +extern Datum spherecircle_by_center_deg(PG_FUNCTION_ARGS); /* * Calculates the area of a circle in square radians. */ -Datum spherecircle_area(PG_FUNCTION_ARGS); +extern Datum spherecircle_area(PG_FUNCTION_ARGS); /* * Calculates the circumference of a circle in radians. */ -Datum spherecircle_circ(PG_FUNCTION_ARGS); +extern Datum spherecircle_circ(PG_FUNCTION_ARGS); /* * Transforms a circle using an Euler transformation. */ -Datum spheretrans_circle(PG_FUNCTION_ARGS); +extern Datum spheretrans_circle(PG_FUNCTION_ARGS); /* * Inverse transformation of a circle using an Euler transformation. */ -Datum spheretrans_circle_inverse(PG_FUNCTION_ARGS); +extern Datum spheretrans_circle_inverse(PG_FUNCTION_ARGS); #endif diff -Nru pgsphere-1.4.2/src/ellipse.h pgsphere-1.5.1/src/ellipse.h --- pgsphere-1.4.2/src/ellipse.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/ellipse.h 2024-04-22 06:22:05.000000000 +0000 @@ -18,9 +18,9 @@ */ float8 rad[2]; - float8 phi, /* the first rotation angle around z axis */ - theta, /* the second rotation angle around x axis */ - psi; /* the last rotation angle around z axis */ + float8 phi, /* the first rotation angle around z axis */ + theta, /* the second rotation angle around x axis */ + psi; /* the last rotation angle around z axis */ } SELLIPSE; /* @@ -47,258 +47,258 @@ /* * Checks whether two ellipses are equal . */ -bool sellipse_eq(const SELLIPSE *e1, const SELLIPSE *e2); +extern bool sellipse_eq(const SELLIPSE *e1, const SELLIPSE *e2); /* * Returns the center of an ellipse. */ -void sellipse_center(SPoint *sp, const SELLIPSE *e); +extern void sellipse_center(SPoint *sp, const SELLIPSE *e); /* * Checks whether a ellipse contains point. */ -bool sellipse_cont_point(const SELLIPSE *se, const SPoint *sp); +extern bool sellipse_cont_point(const SELLIPSE *se, const SPoint *sp); /* * Returns the large axis of an ellipse as line. */ -bool sellipse_line(SLine *sl, const SELLIPSE *e); +extern bool sellipse_line(SLine *sl, const SELLIPSE *e); /* * Relationship between a line and an ellipse as PGS_ELLIPSE_LINE_REL int8 value. */ -int8 sellipse_line_pos(const SELLIPSE *se, const SLine *sl); +extern int8 sellipse_line_pos(const SELLIPSE *se, const SLine *sl); /* * Relationship between a circle and an ellipse as PGS_ELLIPSE_CIRCLE_REL int8 value. */ -int8 sellipse_circle_pos(const SELLIPSE *se, const SCIRCLE *sc); +extern int8 sellipse_circle_pos(const SELLIPSE *se, const SCIRCLE *sc); /* * Returns the Euler transformation of an ellipse. */ -void sellipse_trans(SEuler *se, const SELLIPSE *e); +extern void sellipse_trans(SEuler *se, const SELLIPSE *e); /* * Input of the spherical ellipse. */ -Datum sphereellipse_in(PG_FUNCTION_ARGS); +extern Datum sphereellipse_in(PG_FUNCTION_ARGS); /* * Input of the spherical ellipse from center, axes and inclination. */ -Datum sphereellipse_infunc(PG_FUNCTION_ARGS); +extern Datum sphereellipse_infunc(PG_FUNCTION_ARGS); /* * Returns the inclination of an ellipse. */ -Datum sphereellipse_incl(PG_FUNCTION_ARGS); +extern Datum sphereellipse_incl(PG_FUNCTION_ARGS); /* * Returns the length of the major axis of an ellipse. */ -Datum sphereellipse_rad1(PG_FUNCTION_ARGS); +extern Datum sphereellipse_rad1(PG_FUNCTION_ARGS); /* * Returns the length of the minor axis of an ellipse. */ -Datum sphereellipse_rad2(PG_FUNCTION_ARGS); +extern Datum sphereellipse_rad2(PG_FUNCTION_ARGS); /* * Returns the center of an ellipse. */ -Datum sphereellipse_center(PG_FUNCTION_ARGS); +extern Datum sphereellipse_center(PG_FUNCTION_ARGS); /* * Returns the Euler transformation of an ellipse. */ -Datum sphereellipse_trans(PG_FUNCTION_ARGS); +extern Datum sphereellipse_trans(PG_FUNCTION_ARGS); /* * Casts a spherical ellipse as circle. The created circle is the boundary * circle of ellipse. The diameter of returned circle is equal to length of * major axis of ellipse. */ -Datum sphereellipse_circle(PG_FUNCTION_ARGS); +extern Datum sphereellipse_circle(PG_FUNCTION_ARGS); /* * Casts a spherical point to an ellipse. */ -Datum spherepoint_ellipse(PG_FUNCTION_ARGS); +extern Datum spherepoint_ellipse(PG_FUNCTION_ARGS); /* * Casts a spherical circle to an ellipse. */ -Datum spherecircle_ellipse(PG_FUNCTION_ARGS); +extern Datum spherecircle_ellipse(PG_FUNCTION_ARGS); /* * Checks whether two ellipses are equal. */ -Datum sphereellipse_equal(PG_FUNCTION_ARGS); +extern Datum sphereellipse_equal(PG_FUNCTION_ARGS); /* * Checks whether two ellipses are not equal. */ -Datum sphereellipse_equal_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_equal_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a point. */ -Datum sphereellipse_cont_point(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_point(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a point. */ -Datum sphereellipse_cont_point_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_point_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a point. */ -Datum sphereellipse_cont_point_com(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_point_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a point. */ -Datum sphereellipse_cont_point_com_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_point_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a line. */ -Datum sphereellipse_cont_line(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_line(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a line. */ -Datum sphereellipse_cont_line_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_line_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a line. */ -Datum sphereellipse_cont_line_com(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_line_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a line. */ -Datum sphereellipse_cont_line_com_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a line overlap. */ -Datum sphereellipse_overlap_line(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_line(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a line don't overlap. */ -Datum sphereellipse_overlap_line_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_line_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a line overlap. */ -Datum sphereellipse_overlap_line_com(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_line_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a line don't overlap. */ -Datum sphereellipse_overlap_line_com_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a circle. */ -Datum sphereellipse_cont_circle(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_circle(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a circle. */ -Datum sphereellipse_cont_circle_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a circle. */ -Datum sphereellipse_cont_circle_com(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_circle_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a circle. */ -Datum sphereellipse_cont_circle_com_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains an ellipse. */ -Datum spherecircle_cont_ellipse(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_ellipse(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain an ellipse. */ -Datum spherecircle_cont_ellipse_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_ellipse_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains an ellipse. */ -Datum spherecircle_cont_ellipse_com(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_ellipse_com(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain an ellipse. */ -Datum spherecircle_cont_ellipse_com_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_ellipse_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and an ellipse overlap. */ -Datum sphereellipse_overlap_circle(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_circle(PG_FUNCTION_ARGS); /* * Checks whether a circle and an ellipse don't overlap. */ -Datum sphereellipse_overlap_circle_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and an ellipse overlap. */ -Datum sphereellipse_overlap_circle_com(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_circle_com(PG_FUNCTION_ARGS); /* * Checks whether a circle and an ellipse don't overlap. */ -Datum sphereellipse_overlap_circle_com_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains other ellipse. */ -Datum sphereellipse_cont_ellipse(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_ellipse(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain other ellipse. */ -Datum sphereellipse_cont_ellipse_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_ellipse_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse is contained by other ellipse. */ -Datum sphereellipse_cont_ellipse_com(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_ellipse_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse isn't contained by other ellipse. */ -Datum sphereellipse_cont_ellipse_com_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_ellipse_com_neg(PG_FUNCTION_ARGS); /* * Checks whether two ellipses overlap. */ -Datum sphereellipse_overlap_ellipse(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_ellipse(PG_FUNCTION_ARGS); /* * Checks whether two ellipses don't overlap. */ -Datum sphereellipse_overlap_ellipse_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_ellipse_neg(PG_FUNCTION_ARGS); /* * Transforms an ellipse using an Euler transformation. */ -Datum spheretrans_ellipse(PG_FUNCTION_ARGS); +extern Datum spheretrans_ellipse(PG_FUNCTION_ARGS); /* * Transforms an ellipse using an Euler transformation. */ -Datum spheretrans_ellipse_inv(PG_FUNCTION_ARGS); +extern Datum spheretrans_ellipse_inv(PG_FUNCTION_ARGS); #endif diff -Nru pgsphere-1.4.2/src/epochprop.h pgsphere-1.5.1/src/epochprop.h --- pgsphere-1.4.2/src/epochprop.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/epochprop.h 2024-04-22 06:22:05.000000000 +0000 @@ -3,24 +3,24 @@ #include -Datum epoch_prop(PG_FUNCTION_ARGS); +extern Datum epoch_prop(PG_FUNCTION_ARGS); /* a cartesian point; this is like geo_decl's point, but you can't have both geo_decls and pg_sphere right now (both define a type Point, not to mention they have different ideas on EPSILON */ -typedef struct s_cpoint { - double x, y; +typedef struct s_cpoint +{ + double x, + y; } CPoint; -typedef struct s_phasevec { - SPoint pos; /* Position as an SPoint */ - double pm[2]; /* Proper motion long/lat in rad/year, - PM in longitude has cos(lat) applied */ - double parallax; /* in rad */ - double rv; /* radial velocity in km/s */ - int parallax_valid; /* 1 if the parallax really is a NULL */ +typedef struct s_phasevec +{ + SPoint pos; /* Position as an SPoint */ + double pm[2]; /* Proper motion long/lat in rad/year, PM in + * longitude has cos(lat) applied */ + double parallax; /* in rad */ + double rv; /* radial velocity in km/s */ + int parallax_valid; /* 1 if the parallax really is a NULL */ } phasevec; - - - diff -Nru pgsphere-1.4.2/src/euler.c pgsphere-1.5.1/src/euler.c --- pgsphere-1.4.2/src/euler.c 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/euler.c 2024-04-22 06:22:05.000000000 +0000 @@ -109,8 +109,8 @@ d[1] = PG_GETARG_DATUM(1); d[2] = PG_GETARG_DATUM(2); se = (SEuler *) DatumGetPointer( - DirectFunctionCall3(spheretrans_from_float8, - d[0], d[1], d[2])); + DirectFunctionCall3(spheretrans_from_float8, + d[0], d[1], d[2])); for (i = 0; i < 3; i++) { @@ -165,7 +165,8 @@ bool strans_eq(const SEuler *e1, const SEuler *e2) { - SPoint in[2], p[4]; + SPoint in[2], + p[4]; in[0].lng = 0.0; in[0].lat = 0.0; @@ -210,6 +211,7 @@ spheretrans_theta(PG_FUNCTION_ARGS) { SEuler *se = (SEuler *) PG_GETARG_POINTER(0); + PG_RETURN_FLOAT8(se->theta); } @@ -267,8 +269,8 @@ void spheretrans_inv(SEuler *se) { - float8 lng[3]; - const unsigned char c = se->phi_a; + float8 lng[3]; + const unsigned char c = se->phi_a; lng[2] = -se->phi; lng[1] = -se->theta; @@ -298,7 +300,7 @@ } else { - SEuler tmp; + SEuler tmp; tmp.psi = 0.0; tmp.theta = 0.0; @@ -339,7 +341,7 @@ void seuler_trans_zxz(SEuler *out, const SEuler *in, const SEuler *se) { - SPoint sp[4]; + SPoint sp[4]; sp[0].lng = 0.0; sp[0].lat = 0.0; @@ -380,7 +382,8 @@ void euler_spoint_trans(SPoint *out, const SPoint *in, const SEuler *se) { - Vector3D v, o; + Vector3D v, + o; spoint_vector3d(&v, in); euler_vector_trans(&o, &v, se); @@ -425,7 +428,9 @@ } else { - Vector3D vbeg, vend, vtmp; + Vector3D vbeg, + vend, + vtmp; SPoint spt[2]; SEuler set; @@ -448,7 +453,7 @@ bool spherevector_to_euler(SEuler *se, const SPoint *spb, const SPoint *spe) { - bool ret; + bool ret; ret = spherevector_to_euler_inv(se, spb, spe); if (ret) @@ -461,10 +466,13 @@ void euler_vector_trans(Vector3D *out, const Vector3D *in, const SEuler *se) { - int i; - unsigned char t; - const double *a; - double u[3], vr[3], sa, ca; + int i; + unsigned char t; + const double *a; + double u[3], + vr[3], + sa, + ca; t = 0; a = NULL; diff -Nru pgsphere-1.4.2/src/euler.h pgsphere-1.5.1/src/euler.h --- pgsphere-1.4.2/src/euler.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/euler.h 2024-04-22 06:22:05.000000000 +0000 @@ -12,12 +12,12 @@ */ typedef struct { - unsigned char phi_a:2, /* first axis */ - theta_a:2, /* second axis */ - psi_a:2; /* third axis */ - float8 phi, /* first rotation angle */ - theta, /* second rotation angle */ - psi; /* third rotation angle */ + unsigned char phi_a:2, /* first axis */ + theta_a:2, /* second axis */ + psi_a:2; /* third axis */ + float8 phi, /* first rotation angle */ + theta, /* second rotation angle */ + psi; /* third rotation angle */ } SEuler; @@ -25,137 +25,137 @@ * Transforms a spherical point and returns the pointer to a transformed spherical * point. */ -void euler_spoint_trans(SPoint *out, const SPoint *in, const SEuler *se); +extern void euler_spoint_trans(SPoint *out, const SPoint *in, const SEuler *se); /* * Transforms a spherical vector from 'spb' to 'spe' into an Euler transformation. * Returns true if the transformation was successful. */ -bool spherevector_to_euler(SEuler *se, const SPoint *spb, const SPoint *spe); +extern bool spherevector_to_euler(SEuler *se, const SPoint *spb, const SPoint *spe); /* * Sets the axes of transformation to ZXZ. */ -void seuler_set_zxz(SEuler *se); +extern void seuler_set_zxz(SEuler *se); /* * Checks equality of two transformations. */ -bool strans_eq(const SEuler *e1, const SEuler *e2); +extern bool strans_eq(const SEuler *e1, const SEuler *e2); /* * Transforms a vector using an Euler transformation. Returns the pointer to * the result vector. */ -void euler_vector_trans(Vector3D *out, const Vector3D *in, const SEuler *se); +extern void euler_vector_trans(Vector3D *out, const Vector3D *in, const SEuler *se); /* * Inverts an Euler transformation. Returns the pointer to the * inverted transformation. */ -void spheretrans_inverse(SEuler *se_out, const SEuler *se_in); +extern void spheretrans_inverse(SEuler *se_out, const SEuler *se_in); /* * Inverts an Euler transformation replacing the original Euler transformation. * Returns the pointer to the inverted transformation. */ -void spheretrans_inv(SEuler *se); +extern void spheretrans_inv(SEuler *se); /* * Converts an Euler transformation to a ZXZ-axis transformation. Returns * the pointer to the converted transformation. */ -void strans_zxz(SEuler *ret, const SEuler *se); +extern void strans_zxz(SEuler *ret, const SEuler *se); /* * Transforms an Euler transformation 'in' into 'out' using 'se'. The result * is always a ZXZ-axis transformation. Returns the pointer to the transformed * transformation. */ -void seuler_trans_zxz(SEuler *out, const SEuler *in, const SEuler *se); +extern void seuler_trans_zxz(SEuler *out, const SEuler *in, const SEuler *se); /* * Input of an Euler transformation. */ -Datum spheretrans_in(PG_FUNCTION_ARGS); +extern Datum spheretrans_in(PG_FUNCTION_ARGS); /* * Input of an Euler transformation with axis Z,X,Z from three angles * (phi, theta, psi) in radians. */ -Datum spheretrans_from_float8(PG_FUNCTION_ARGS); +extern Datum spheretrans_from_float8(PG_FUNCTION_ARGS); /* * Returns the first angle of an Euler transformation in radians. */ -Datum spheretrans_phi(PG_FUNCTION_ARGS); +extern Datum spheretrans_phi(PG_FUNCTION_ARGS); /* * Returns the second angle of an Euler transformation in radians. */ -Datum spheretrans_theta(PG_FUNCTION_ARGS); +extern Datum spheretrans_theta(PG_FUNCTION_ARGS); /* * Returns the third angle of an Euler transformation in radians. */ -Datum spheretrans_psi(PG_FUNCTION_ARGS); +extern Datum spheretrans_psi(PG_FUNCTION_ARGS); /* * Returns the axis of an Euler transformation as three letter code. */ -Datum spheretrans_type(PG_FUNCTION_ARGS); +extern Datum spheretrans_type(PG_FUNCTION_ARGS); /* * Returns the Euler transformation (does nothing). This function is needed * for +strans operator. */ -Datum spheretrans(PG_FUNCTION_ARGS); +extern Datum spheretrans(PG_FUNCTION_ARGS); /* * Returns the inverse Euler transformation. */ -Datum spheretrans_invert(PG_FUNCTION_ARGS); +extern Datum spheretrans_invert(PG_FUNCTION_ARGS); /* * Convert an Euler transformation to a ZXZ-axis transformation. */ -Datum spheretrans_zxz(PG_FUNCTION_ARGS); +extern Datum spheretrans_zxz(PG_FUNCTION_ARGS); /* * This function creates an Euler transformation from 3 angle values in * radians and three letter code used for axes. A letter can be X, Y or Z * (case-insensitive). */ -Datum spheretrans_from_float8_and_type(PG_FUNCTION_ARGS); +extern Datum spheretrans_from_float8_and_type(PG_FUNCTION_ARGS); /* * Checks equality of two Euler transformations. */ -Datum spheretrans_equal(PG_FUNCTION_ARGS); +extern Datum spheretrans_equal(PG_FUNCTION_ARGS); /* * Checks inequality of two Euler transformations. */ -Datum spheretrans_not_equal(PG_FUNCTION_ARGS); +extern Datum spheretrans_not_equal(PG_FUNCTION_ARGS); /* * Transforms an Euler transformation. */ -Datum spheretrans_trans(PG_FUNCTION_ARGS); +extern Datum spheretrans_trans(PG_FUNCTION_ARGS); /* * Transforms inverse an Euler transformations. */ -Datum spheretrans_trans_inv(PG_FUNCTION_ARGS); +extern Datum spheretrans_trans_inv(PG_FUNCTION_ARGS); /* * Transforms a spherical point. */ -Datum spheretrans_point(PG_FUNCTION_ARGS); +extern Datum spheretrans_point(PG_FUNCTION_ARGS); /* * Perform inverse transformation of a spherical point. */ -Datum spheretrans_point_inverse(PG_FUNCTION_ARGS); +extern Datum spheretrans_point_inverse(PG_FUNCTION_ARGS); #endif diff -Nru pgsphere-1.4.2/src/gist.c pgsphere-1.5.1/src/gist.c --- pgsphere-1.4.2/src/gist.c 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/gist.c 2024-04-22 06:22:05.000000000 +0000 @@ -36,6 +36,7 @@ PG_FUNCTION_INFO_V1(g_spherekey_picksplit); PG_FUNCTION_INFO_V1(g_spoint3_penalty); PG_FUNCTION_INFO_V1(g_spoint3_picksplit); +PG_FUNCTION_INFO_V1(g_spoint_distance); PG_FUNCTION_INFO_V1(g_spoint3_distance); PG_FUNCTION_INFO_V1(g_spoint3_fetch); @@ -510,7 +511,7 @@ SCK_INTERLEAVE(SELLIPSE, sphereellipse_gen_key, 0); break; case 42: - SCK_INTERLEAVE(SBOX, spherebox_gen_key , 0); + SCK_INTERLEAVE(SBOX, spherebox_gen_key, 0); break; } @@ -681,6 +682,13 @@ PG_RETURN_BOOL(false); } +static double +distance_vector_point_3d(Vector3D *v, double x, double y, double z) +{ + /* as v has length = 1 by design */ + return acos((v->x * x + v->y * y + v->z * z) / sqrt(x * x + y * y + z * z)); +} + Datum g_spoint3_distance(PG_FUNCTION_ARGS) { @@ -1672,6 +1680,224 @@ v->spl_ldatum_exists = v->spl_rdatum_exists = false; } + +Datum +g_spoint_distance(PG_FUNCTION_ARGS) +{ + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); + StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); + Box3D *box = (Box3D *) DatumGetPointer(entry->key); + double retval; + SPoint *point = (SPoint *) PG_GETARG_POINTER(1); + Vector3D v_point, + v_low, + v_high; + + switch (strategy) + { + case 17: + /* Prepare data for calculation */ + spoint_vector3d(&v_point, point); + v_low.x = (double) box->low.coord[0] / MAXCVALUE; + v_low.y = (double) box->low.coord[1] / MAXCVALUE; + v_low.z = (double) box->low.coord[2] / MAXCVALUE; + v_high.x = (double) box->high.coord[0] / MAXCVALUE; + v_high.y = (double) box->high.coord[1] / MAXCVALUE; + v_high.z = (double) box->high.coord[2] / MAXCVALUE; + + /* + * a box splits space into 27 subspaces (6+12+8+1) with different + * distance calculation + */ + if (v_point.x < v_low.x) + { + if (v_point.y < v_low.y) + { + if (v_point.z < v_low.z) + { + /* point2point distance */ + retval = distance_vector_point_3d(&v_point, v_low.x, v_low.y, v_low.z); + } + else if (v_point.z < v_high.z) + { + /* point2line distance */ + retval = distance_vector_point_3d(&v_point, v_low.x, v_low.y, v_point.z); + } + else + { + /* point2point distance */ + retval = distance_vector_point_3d(&v_point, v_low.x, v_low.y, v_high.z); + } + } + else if (v_point.y < v_high.y) + { + if (v_point.z < v_low.z) + { + /* point2line distance */ + retval = distance_vector_point_3d(&v_point, v_low.x, v_point.y, v_low.z); + } + else if (v_point.z < v_high.z) + { + /* point2plane distance */ + retval = distance_vector_point_3d(&v_point, v_low.x, v_point.y, v_point.z); + } + else + { + /* point2line distance */ + retval = distance_vector_point_3d(&v_point, v_low.x, v_point.y, v_high.z); + } + } + else + { + if (v_point.z < v_low.z) + { + /* point2point distance */ + retval = distance_vector_point_3d(&v_point, v_low.x, v_high.y, v_low.z); + } + else if (v_point.z < v_high.z) + { + /* point2line distance */ + retval = distance_vector_point_3d(&v_point, v_low.x, v_high.y, v_point.z); + } + else + { + /* point2point distance */ + retval = distance_vector_point_3d(&v_point, v_low.x, v_high.y, v_high.z); + } + } + } + else if (v_point.x < v_high.x) + { + if (v_point.y < v_low.y) + { + if (v_point.z < v_low.z) + { + /* p2line distance */ + retval = distance_vector_point_3d(&v_point, v_point.x, v_low.y, v_low.z); + } + else if (v_point.z < v_high.z) + { + /* point2plane distance */ + retval = distance_vector_point_3d(&v_point, v_point.x, v_low.y, v_point.z); + } + else + { + /* point2line distance */ + retval = distance_vector_point_3d(&v_point, v_point.x, v_low.y, v_high.z); + } + } + else if (v_point.y < v_high.y) + { + if (v_point.z < v_low.z) + { + /* point2plane distance */ + retval = distance_vector_point_3d(&v_point, v_point.x, v_point.y, v_low.z); + } + else if (v_point.z < v_high.z) + { + /* inside cube */ + retval = 0; + } + else + { + /* point2plane distance */ + retval = distance_vector_point_3d(&v_point, v_point.x, v_point.y, v_high.z); + } + } + else + { + if (v_point.z < v_low.z) + { + /* point2line distance */ + retval = distance_vector_point_3d(&v_point, v_point.x, v_high.y, v_low.z); + } + else if (v_point.z < v_high.z) + { + /* point2plane distance */ + retval = distance_vector_point_3d(&v_point, v_point.x, v_high.y, v_point.z); + } + else + { + /* point2line distance */ + retval = distance_vector_point_3d(&v_point, v_point.x, v_high.y, v_high.z); + } + } + } + else + { + if (v_point.y < v_low.y) + { + if (v_point.z < v_low.z) + { + /* p2p distance */ + retval = distance_vector_point_3d(&v_point, v_high.x, v_low.y, v_low.z); + } + else if (v_point.z < v_high.z) + { + /* point2line distance */ + retval = distance_vector_point_3d(&v_point, v_high.x, v_low.y, v_point.z); + } + else + { + /* point2point distance */ + retval = distance_vector_point_3d(&v_point, v_high.x, v_low.y, v_high.z); + } + } + else if (v_point.y < v_high.y) + { + if (v_point.z < v_low.z) + { + /* point2line distance */ + retval = distance_vector_point_3d(&v_point, v_high.x, v_point.y, v_low.z); + } + else if (v_point.z < v_high.z) + { + /* point2plane distance */ + retval = distance_vector_point_3d(&v_point, v_high.x, v_point.y, v_point.z); + } + else + { + /* point2line distance */ + retval = distance_vector_point_3d(&v_point, v_high.x, v_point.y, v_high.z); + } + } + else + { + if (v_point.z < v_low.z) + { + /* point2point distance */ + retval = distance_vector_point_3d(&v_point, v_high.x, v_high.y, v_low.z); + } + else if (v_point.z < v_high.z) + { + /* point2line distance */ + retval = distance_vector_point_3d(&v_point, v_high.x, v_high.y, v_point.z); + } + else + { + /* point2point distance */ + retval = distance_vector_point_3d(&v_point, v_high.x, v_high.y, v_high.z); + } + } + } + + elog(DEBUG1, "distance (%lg,%lg,%lg %lg,%lg,%lg) <-> (%lg,%lg) = %lg", + v_low.x, v_low.y, v_low.z, + v_high.x, v_high.y, v_high.z, + point->lng, point->lat, + retval + ); + break; + + default: + elog(ERROR, "unrecognized cube strategy number: %d", strategy); + retval = 0; /* keep compiler quiet */ + break; + } + + PG_RETURN_FLOAT8(retval); +} + /* * Represents information about an entry that can be placed to either group * without affecting overlap over selected axis ("common entry"). @@ -2203,7 +2429,7 @@ { box = &boxes[i]; commonEntries[i].delta = fabs((unionSizeBox3D(leftBox, box) - leftBoxSize) - - (unionSizeBox3D(rightBox, box) - rightBoxSize)); + (unionSizeBox3D(rightBox, box) - rightBoxSize)); } /* diff -Nru pgsphere-1.4.2/src/gist.h pgsphere-1.5.1/src/gist.h --- pgsphere-1.4.2/src/gist.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/gist.h 2024-04-22 06:22:05.000000000 +0000 @@ -11,150 +11,150 @@ typedef unsigned char uchar; /* PGS_KEY_REL Key relationships */ -#define SCKEY_DISJ 0 /* two keys are disjunct */ -#define SCKEY_OVERLAP 1 /* two keys are overlapping */ -#define SCKEY_IN 2 /* first key contains second key */ -#define SCKEY_SAME 3 /* keys are equal */ +#define SCKEY_DISJ 0 /* two keys are disjunct */ +#define SCKEY_OVERLAP 1 /* two keys are overlapping */ +#define SCKEY_IN 2 /* first key contains second key */ +#define SCKEY_SAME 3 /* keys are equal */ -uchar spherekey_interleave(const int32 *k1, const int32 *k2); +extern uchar spherekey_interleave(const int32 *k1, const int32 *k2); /* * For given "query" of "pgstype" of PGS_DATA_TYPES type, puts key of cached * query into "key" pointer. Returns true when given query is equal to * current query. */ -bool gq_cache_get_value(unsigned pgstype, const void *query, int32 **key); +extern bool gq_cache_get_value(unsigned pgstype, const void *query, int32 **key); /* * Copy current query, type and its key value to cache. */ -void gq_cache_set_value(unsigned pgstype, const void *query, const int32 *key); +extern void gq_cache_set_value(unsigned pgstype, const void *query, const int32 *key); /* * Input function of key value. Just a dummy. But PostgreSQL need this * function to create a data type. */ -Datum spherekey_in(PG_FUNCTION_ARGS); +extern Datum spherekey_in(PG_FUNCTION_ARGS); /* * Output function of key value. Just a dummy. But PostgreSQL need this * function to create a data type. */ -Datum spherekey_out(PG_FUNCTION_ARGS); +extern Datum spherekey_out(PG_FUNCTION_ARGS); /* * GIST's decompress method. This function does nothing. */ -Datum g_spherekey_decompress(PG_FUNCTION_ARGS); +extern Datum g_spherekey_decompress(PG_FUNCTION_ARGS); /* * GIST's compress method for circle. Creates the key value from a spherical * circle. */ -Datum g_scircle_compress(PG_FUNCTION_ARGS); +extern Datum g_scircle_compress(PG_FUNCTION_ARGS); /* * GIST's compress method for point. Creates the key value from a spherical point. */ -Datum g_spoint_compress(PG_FUNCTION_ARGS); +extern Datum g_spoint_compress(PG_FUNCTION_ARGS); /* * GIST's compress method for line. Creates the key value from a spherical line. */ -Datum g_sline_compress(PG_FUNCTION_ARGS); +extern Datum g_sline_compress(PG_FUNCTION_ARGS); /* * GIST's compress method for path. Creates the key value from a spherical path. */ -Datum g_spath_compress(PG_FUNCTION_ARGS); +extern Datum g_spath_compress(PG_FUNCTION_ARGS); /* * GIST's compress method for polygon. Creates the key value from a spherical * polygon. */ -Datum g_spoly_compress(PG_FUNCTION_ARGS); +extern Datum g_spoly_compress(PG_FUNCTION_ARGS); /* * GIST's compress method for ellipse. Creates the key value from a spherical * ellipse. */ -Datum g_sellipse_compress(PG_FUNCTION_ARGS); +extern Datum g_sellipse_compress(PG_FUNCTION_ARGS); /* * GIST's compress method for box. Creates the key value from a spherical box. */ -Datum g_sbox_compress(PG_FUNCTION_ARGS); +extern Datum g_sbox_compress(PG_FUNCTION_ARGS); /* * The GiST Union method for boxes. Returns the minimal bounding box that * encloses all the entries in entryvec. */ -Datum g_spherekey_union(PG_FUNCTION_ARGS); +extern Datum g_spherekey_union(PG_FUNCTION_ARGS); /* * GIST's equality method. */ -Datum g_spherekey_same(PG_FUNCTION_ARGS); +extern Datum g_spherekey_same(PG_FUNCTION_ARGS); /* * GIST's consistent method for a point. */ -Datum g_spoint_consistent(PG_FUNCTION_ARGS); +extern Datum g_spoint_consistent(PG_FUNCTION_ARGS); /* * GIST's consistent method for a circle. */ -Datum g_scircle_consistent(PG_FUNCTION_ARGS); +extern Datum g_scircle_consistent(PG_FUNCTION_ARGS); /* * GIST's consistent method for a line. */ -Datum g_sline_consistent(PG_FUNCTION_ARGS); +extern Datum g_sline_consistent(PG_FUNCTION_ARGS); /* * GIST's consistent method for a path. */ -Datum g_spath_consistent(PG_FUNCTION_ARGS); +extern Datum g_spath_consistent(PG_FUNCTION_ARGS); /* * GIST's consistent method for a polygon. */ -Datum g_spoly_consistent(PG_FUNCTION_ARGS); +extern Datum g_spoly_consistent(PG_FUNCTION_ARGS); /* * GIST's consistent method for an ellipse. */ -Datum g_sellipse_consistent(PG_FUNCTION_ARGS); +extern Datum g_sellipse_consistent(PG_FUNCTION_ARGS); /* * GIST's consistent method for a box. */ -Datum g_sbox_consistent(PG_FUNCTION_ARGS); +extern Datum g_sbox_consistent(PG_FUNCTION_ARGS); /* * GIST's penalty method. */ -Datum g_spherekey_penalty(PG_FUNCTION_ARGS); +extern Datum g_spherekey_penalty(PG_FUNCTION_ARGS); /* * GIST's picksplit method. This method is using the double sorting node * splitting algorithm for R-Trees. See "A new double sorting-based node * splitting algorithm for R-tree", A. Korotkov. */ -Datum g_spherekey_picksplit(PG_FUNCTION_ARGS); +extern Datum g_spherekey_picksplit(PG_FUNCTION_ARGS); -Datum pointkey_in(PG_FUNCTION_ARGS); -Datum pointkey_out(PG_FUNCTION_ARGS); -Datum pointkey_volume(PG_FUNCTION_ARGS); -Datum pointkey_area(PG_FUNCTION_ARGS); -Datum pointkey_perimeter(PG_FUNCTION_ARGS); -Datum g_spoint3_compress(PG_FUNCTION_ARGS); -Datum g_spoint3_union(PG_FUNCTION_ARGS); -Datum g_spoint3_same(PG_FUNCTION_ARGS); -Datum g_spoint3_consistent(PG_FUNCTION_ARGS); -Datum g_spoint3_penalty(PG_FUNCTION_ARGS); -Datum g_spoint3_picksplit(PG_FUNCTION_ARGS); -Datum g_spoint3_distance(PG_FUNCTION_ARGS); -Datum g_spoint3_fetch(PG_FUNCTION_ARGS); +extern Datum pointkey_in(PG_FUNCTION_ARGS); +extern Datum pointkey_out(PG_FUNCTION_ARGS); +extern Datum pointkey_volume(PG_FUNCTION_ARGS); +extern Datum pointkey_area(PG_FUNCTION_ARGS); +extern Datum pointkey_perimeter(PG_FUNCTION_ARGS); +extern Datum g_spoint3_compress(PG_FUNCTION_ARGS); +extern Datum g_spoint3_union(PG_FUNCTION_ARGS); +extern Datum g_spoint3_same(PG_FUNCTION_ARGS); +extern Datum g_spoint3_consistent(PG_FUNCTION_ARGS); +extern Datum g_spoint3_penalty(PG_FUNCTION_ARGS); +extern Datum g_spoint3_picksplit(PG_FUNCTION_ARGS); +extern Datum g_spoint3_distance(PG_FUNCTION_ARGS); +extern Datum g_spoint3_fetch(PG_FUNCTION_ARGS); #endif diff -Nru pgsphere-1.4.2/src/gnomo.h pgsphere-1.5.1/src/gnomo.h --- pgsphere-1.4.2/src/gnomo.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/gnomo.h 2024-04-22 06:22:05.000000000 +0000 @@ -3,7 +3,7 @@ /* function prototypes for the direct and inverse gnomonic projections */ -Datum gnomonic_proj(PG_FUNCTION_ARGS); -Datum gnomonic_inv(PG_FUNCTION_ARGS); +extern Datum gnomonic_proj(PG_FUNCTION_ARGS); +extern Datum gnomonic_inv(PG_FUNCTION_ARGS); #endif diff -Nru pgsphere-1.4.2/src/key.h pgsphere-1.5.1/src/key.h --- pgsphere-1.4.2/src/key.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/key.h 2024-04-22 06:22:05.000000000 +0000 @@ -20,30 +20,32 @@ typedef struct { - char vl_len_[4]; + char vl_len_[4]; union { - struct /* the compiler will probably insert 4 bytes of padding here */ + struct /* the compiler will probably insert 4 bytes + * of padding here */ { - float8 lat, - lng; + float8 lat, + lng; }; }; -} GiSTSPointKey_Leaf; +} GiSTSPointKey_Leaf; typedef struct { - char vl_len_[4]; + char vl_len_[4]; union { - struct /* the compiler will probably insert 4 bytes of padding here */ + struct /* the compiler will probably insert 4 bytes + * of padding here */ { - float8 lat, - lng; + float8 lat, + lng; }; struct { - int32 k[6]; + int32 k[6]; }; }; } GiSTSPointKey; @@ -51,10 +53,12 @@ #define INTERNAL_KEY_SIZE sizeof(GiSTSPointKey) #define LEAF_KEY_SIZE sizeof(GiSTSPointKey_Leaf) #define IS_LEAF(key) (VARSIZE(key) == LEAF_KEY_SIZE) + #define ALLOC_LEAF_KEY(key) do { \ key = (GiSTSPointKey *)palloc0(LEAF_KEY_SIZE); \ SET_VARSIZE(key, LEAF_KEY_SIZE); \ } while (0) ; + #define ALLOC_INTERNAL_KEY(key) do { \ key = (GiSTSPointKey *)palloc0(INTERNAL_KEY_SIZE); \ SET_VARSIZE(key, INTERNAL_KEY_SIZE); \ @@ -63,128 +67,128 @@ /* * Returns the union of two keys. Result is placed into 'kunion'. */ -void spherekey_union_two(int32 *kunion, const int32 *key); +extern void spherekey_union_two(int32 *kunion, const int32 *key); /* * Returns the intersection of two keys. Returns NULL if there is * no intersection. Result is placed into 'kinter'. */ -bool spherekey_inter_two(int32 *kinter, const int32 *key); +extern bool spherekey_inter_two(int32 *kinter, const int32 *key); /* * Generates the key of a spherical point and returns it. Result is placed * into 'k'. */ -void spherepoint_gen_key(int32 *k, const SPoint *sp); +extern void spherepoint_gen_key(int32 *k, const SPoint *sp); /* * Generates the circle's key and returns it. Result is placed into 'k'. */ -void spherecircle_gen_key(int32 *k, const SCIRCLE *c); +extern void spherecircle_gen_key(int32 *k, const SCIRCLE *c); /* * Generates the key of a spherical ellipse and returns it. Result is placed * into 'k'. */ -void sphereellipse_gen_key(int32 *k, const SELLIPSE *e); +extern void sphereellipse_gen_key(int32 *k, const SELLIPSE *e); /* * Generates the key of a spherical line and returns it. Result is placed * into 'k'. */ -void sphereline_gen_key(int32 *k, const SLine *sl); +extern void sphereline_gen_key(int32 *k, const SLine *sl); /* * Generates the key of a polygon and returns it. Result is placed into 'k'. */ -void spherepoly_gen_key(int32 *k, const SPOLY *sp); +extern void spherepoly_gen_key(int32 *k, const SPOLY *sp); /* * Generates the key of a path and returns it. Result is placed into 'k'. */ -void spherepath_gen_key(int32 *k, const SPATH *sp); +extern void spherepath_gen_key(int32 *k, const SPATH *sp); /* * Generates the key of a box and returns it. Result is placed into 'k'. */ -void spherebox_gen_key(int32 *key, const SBOX *box); +extern void spherebox_gen_key(int32 *key, const SBOX *box); /* * Returns true if the first key is less than the second key. */ -Datum spherekey_lt(PG_FUNCTION_ARGS); +extern Datum spherekey_lt(PG_FUNCTION_ARGS); /* * Returns true if the first key is less or equal than the second key. */ -Datum spherekey_le(PG_FUNCTION_ARGS); +extern Datum spherekey_le(PG_FUNCTION_ARGS); /* * Returns true if two keys are equal. */ -Datum spherekey_eq(PG_FUNCTION_ARGS); +extern Datum spherekey_eq(PG_FUNCTION_ARGS); /* * Returns true if two keys are not equal. */ -Datum spherekey_eq_neg(PG_FUNCTION_ARGS); +extern Datum spherekey_eq_neg(PG_FUNCTION_ARGS); /* * Returns true if the first key is greater or equal than the second key. */ -Datum spherekey_ge(PG_FUNCTION_ARGS); +extern Datum spherekey_ge(PG_FUNCTION_ARGS); /* * Returns true if the first key is greater than the second key. */ -Datum spherekey_gt(PG_FUNCTION_ARGS); +extern Datum spherekey_gt(PG_FUNCTION_ARGS); /* * Returns relationship between the two keys. * Calls skey_cmp(const int32 *, const int32 *) for two keys. */ -Datum spherekey_cmp(PG_FUNCTION_ARGS); +extern Datum spherekey_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical points. * Calls skey_cmp(const int32 *, const int32 *) for two points. */ -Datum spherepoint_cmp(PG_FUNCTION_ARGS); +extern Datum spherepoint_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical circles. * Calls skey_cmp(const int32 *, const int32 *) for two circles. */ -Datum spherecircle_cmp(PG_FUNCTION_ARGS); +extern Datum spherecircle_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical ellipses. * Calls skey_cmp(const int32 *, const int32 *) for two ellipses. */ -Datum sphereellipse_cmp(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical lines. * Calls skey_cmp(const int32 *, const int32 *) for two lines. */ -Datum sphereline_cmp(PG_FUNCTION_ARGS); +extern Datum sphereline_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical paths. * Calls skey_cmp(const int32 *, const int32 *) for two paths. */ -Datum spherepath_cmp(PG_FUNCTION_ARGS); +extern Datum spherepath_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical polygons. * Calls skey_cmp(const int32 *, const int32 *) for two polygons. */ -Datum spherepoly_cmp(PG_FUNCTION_ARGS); +extern Datum spherepoly_cmp(PG_FUNCTION_ARGS); /* * Returns relationship between the keys of two spherical boxes. * Calls skey_cmp(const int32 *, const int32 *) for two boxes. */ -Datum spherebox_cmp(PG_FUNCTION_ARGS); +extern Datum spherebox_cmp(PG_FUNCTION_ARGS); #endif diff -Nru pgsphere-1.4.2/src/line.h pgsphere-1.5.1/src/line.h --- pgsphere-1.4.2/src/line.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/line.h 2024-04-22 06:22:05.000000000 +0000 @@ -10,10 +10,10 @@ */ typedef struct { - float8 phi, /* the first rotation angle around z axis */ - theta, /* the second rotation angle around x axis */ - psi; /* the last rotation angle around z axis */ - float8 length; /* the length of the line */ + float8 phi, /* the first rotation angle around z axis */ + theta, /* the second rotation angle around x axis */ + psi; /* the last rotation angle around z axis */ + float8 length; /* the length of the line */ } SLine; /* PGS_RELATIONSHIPS Object relationships */ @@ -37,47 +37,47 @@ * * Returns false if the distance between the 'pbeg' and the 'pend' is 180deg. */ -bool sline_from_points(SLine *sl, const SPoint *pbeg, const SPoint *pend); +extern bool sline_from_points(SLine *sl, const SPoint *pbeg, const SPoint *pend); /* * Returns a meridian line of a given longitude in radians. The result is placed * into 'sl'. */ -void sline_meridian(SLine *sl, float8 lng); +extern void sline_meridian(SLine *sl, float8 lng); /* * Returns the starting point of a line 'l'. Result is placed into 'p'. */ -void sline_begin(SPoint *p, const SLine *l); +extern void sline_begin(SPoint *p, const SLine *l); /* * Returns the ending point of a line 'l'. Result is placed into 'p'. */ -void sline_end(SPoint *p, const SLine *l); +extern void sline_end(SPoint *p, const SLine *l); /* * Puts the minimum and the maximum latitudes of a spherical line 's1' into 'minlat' * and 'maxlat'. */ -void sline_min_max_lat(const SLine *sl, float8 *minlat, float8 *maxlat); +extern void sline_min_max_lat(const SLine *sl, float8 *minlat, float8 *maxlat); /* * Calculates spherical points with a latitude 'lat' on a spherical line. * * Returns the number of found points or <0 if undefined. */ -int32 sphereline_latitude_points(const SLine *sl, float8 lat, SPoint *p1, SPoint *p2); +extern int32 sphereline_latitude_points(const SLine *sl, float8 lat, SPoint *p1, SPoint *p2); /* * Returns true if two lines are equal. */ -bool sline_eq(const SLine *l1, const SLine *l2); +extern bool sline_eq(const SLine *l1, const SLine *l2); /* * Returns the relationship between a line and a circle as PGS_CIRCLE_LINE_REL * int8 value. */ -int8 sphereline_circle_pos(const SLine *sl, const SCIRCLE *sc); +extern int8 sphereline_circle_pos(const SLine *sl, const SCIRCLE *sc); /* * Assuming that a line and a circle overlap, this function returns true @@ -87,31 +87,31 @@ * * See sphereline_circle_pos (const SLine *, const SCIRCLE *) */ -bool sline_circle_touch(const SLine *sl, const SCIRCLE *sc); +extern bool sline_circle_touch(const SLine *sl, const SCIRCLE *sc); /* * Returns the relationship between two lines as PGS_LINE_LINE_REL int8 value. */ -int8 sline_sline_pos(const SLine *l1, const SLine *l2); +extern int8 sline_sline_pos(const SLine *l1, const SLine *l2); /* * Checks whether a point is on a line. */ -bool spoint_at_sline(const SPoint *p, const SLine *sl); +extern bool spoint_at_sline(const SPoint *p, const SLine *sl); /* * Returns the Euler transformation of a line. * * See spheretrans_from_line(PG_FUNCTION_ARGS) */ -void sphereline_to_euler(SEuler *se, const SLine *sl); +extern void sphereline_to_euler(SEuler *se, const SLine *sl); /* * Returns the inverse Euler transformation of a line. * * See spheretrans_from_line(PG_FUNCTION_ARGS) */ -void sphereline_to_euler_inv(SEuler *se, const SLine *sl); +extern void sphereline_to_euler_inv(SEuler *se, const SLine *sl); /* * Transforms a line using an Euler transformation. @@ -122,187 +122,187 @@ * * See spheretrans_line (PG_FUNCTION_ARGS) */ -void euler_sline_trans(SLine *out, const SLine *in, const SEuler *se); +extern void euler_sline_trans(SLine *out, const SLine *in, const SEuler *se); /* * Puts the center of a line 'sl' into point 'c'. */ -void sline_center(SPoint *c, const SLine *sl); +extern void sline_center(SPoint *c, const SLine *sl); /* * Calculates the distance between a line 'sl' and a point 'p' */ -float8 sline_point_dist(const SLine *sl, const SPoint *p); +float8 sline_point_dist(const SLine *sl, const SPoint *p); /* * The input function for spherical line. */ -Datum sphereline_in(PG_FUNCTION_ARGS); +extern Datum sphereline_in(PG_FUNCTION_ARGS); /* * Create a line from a spherical point. */ -Datum sphereline_from_point(PG_FUNCTION_ARGS); +extern Datum sphereline_from_point(PG_FUNCTION_ARGS); /* * This function creates a spherical line using a starting point * and an ending point. The distance between the points must not be * equal to 180deg. */ -Datum sphereline_from_points(PG_FUNCTION_ARGS); +extern Datum sphereline_from_points(PG_FUNCTION_ARGS); /* * This function creates a spherical line using a given Euler transformation * and the length of a line. If the length is less than zero, an error occurs. * If the length is larger than 360deg, it is set to 360deg. */ -Datum sphereline_from_trans(PG_FUNCTION_ARGS); +extern Datum sphereline_from_trans(PG_FUNCTION_ARGS); /* * This function creates a meridian running from south to north. * The float8 param provides the longitude in radians. */ -Datum sphereline_meridian(PG_FUNCTION_ARGS); +extern Datum sphereline_meridian(PG_FUNCTION_ARGS); /* * Swaps the starting point and the ending point of a line. */ -Datum sphereline_swap_beg_end(PG_FUNCTION_ARGS); +extern Datum sphereline_swap_beg_end(PG_FUNCTION_ARGS); /* * Turns the line while preserving the starting & ending points. */ -Datum sphereline_turn(PG_FUNCTION_ARGS); +extern Datum sphereline_turn(PG_FUNCTION_ARGS); /* * Returns the beginning of a line. */ -Datum sphereline_begin(PG_FUNCTION_ARGS); +extern Datum sphereline_begin(PG_FUNCTION_ARGS); /* * Returns the ending of a line. */ -Datum sphereline_end(PG_FUNCTION_ARGS); +extern Datum sphereline_end(PG_FUNCTION_ARGS); /* * Returns the length of a line in radians. */ -Datum sphereline_length(PG_FUNCTION_ARGS); +extern Datum sphereline_length(PG_FUNCTION_ARGS); /* * Checks whether a line contains a point. */ -Datum sphereline_cont_point(PG_FUNCTION_ARGS); +extern Datum sphereline_cont_point(PG_FUNCTION_ARGS); /* * Checks whether a line doesn't contain a point. */ -Datum sphereline_cont_point_neg(PG_FUNCTION_ARGS); +extern Datum sphereline_cont_point_neg(PG_FUNCTION_ARGS); /* * Checks whether a line contains a point. */ -Datum sphereline_cont_point_com(PG_FUNCTION_ARGS); +extern Datum sphereline_cont_point_com(PG_FUNCTION_ARGS); /* * Checks whether a line doesn't contain a point. */ -Datum sphereline_cont_point_com_neg(PG_FUNCTION_ARGS); +extern Datum sphereline_cont_point_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a line. */ -Datum spherecircle_cont_line(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_line(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a line. */ -Datum spherecircle_cont_line_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_line_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a line. */ -Datum spherecircle_cont_line_com(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_line_com(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a line. */ -Datum spherecircle_cont_line_com_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and a line overlap. */ -Datum sphereline_overlap_circle(PG_FUNCTION_ARGS); +extern Datum sphereline_overlap_circle(PG_FUNCTION_ARGS); /* * Checks whether circle and a line don't overlap. */ -Datum sphereline_overlap_circle_neg(PG_FUNCTION_ARGS); +extern Datum sphereline_overlap_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and a line overlap. */ -Datum sphereline_overlap_circle_com(PG_FUNCTION_ARGS); +extern Datum sphereline_overlap_circle_com(PG_FUNCTION_ARGS); /* * Checks whether circle and a line don't overlap. */ -Datum sphereline_overlap_circle_com_neg(PG_FUNCTION_ARGS); +extern Datum sphereline_overlap_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether two lines are equal. */ -Datum sphereline_equal(PG_FUNCTION_ARGS); +extern Datum sphereline_equal(PG_FUNCTION_ARGS); /* * Checks whether two lines are not equal. */ -Datum sphereline_equal_neg(PG_FUNCTION_ARGS); +extern Datum sphereline_equal_neg(PG_FUNCTION_ARGS); /* * Checks whether two lines cross each other. */ -Datum sphereline_crosses(PG_FUNCTION_ARGS); +extern Datum sphereline_crosses(PG_FUNCTION_ARGS); /* * Checks whether two lines don't cross each other. */ -Datum sphereline_crosses_neg(PG_FUNCTION_ARGS); +extern Datum sphereline_crosses_neg(PG_FUNCTION_ARGS); /* * Checks whether two lines overlap. */ -Datum sphereline_overlap(PG_FUNCTION_ARGS); +extern Datum sphereline_overlap(PG_FUNCTION_ARGS); /* * Checks whether two lines are overlap. */ -Datum sphereline_overlap_neg(PG_FUNCTION_ARGS); +extern Datum sphereline_overlap_neg(PG_FUNCTION_ARGS); /* * Returns an Euler transformation. An inverse transformation with it puts * the line into equator beginning at (0,0) and ending at (0,length). */ -Datum spheretrans_from_line(PG_FUNCTION_ARGS); +extern Datum spheretrans_from_line(PG_FUNCTION_ARGS); /* * Transforms a line with an Euler transformation. */ -Datum spheretrans_line(PG_FUNCTION_ARGS); +extern Datum spheretrans_line(PG_FUNCTION_ARGS); /* * Transforms a line with an inverse Euler transformation. */ -Datum spheretrans_line_inverse(PG_FUNCTION_ARGS); +extern Datum spheretrans_line_inverse(PG_FUNCTION_ARGS); /* * Returns the distance between a line and a point. */ -Datum sphereline_point_distance(PG_FUNCTION_ARGS); +extern Datum sphereline_point_distance(PG_FUNCTION_ARGS); /* * Returns the distance between a point and a line. */ -Datum sphereline_point_distance_com(PG_FUNCTION_ARGS); +extern Datum sphereline_point_distance_com(PG_FUNCTION_ARGS); #endif diff -Nru pgsphere-1.4.2/src/output.c pgsphere-1.5.1/src/output.c --- pgsphere-1.4.2/src/output.c 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/output.c 2024-04-22 06:22:05.000000000 +0000 @@ -1,5 +1,12 @@ #include "types.h" +#if PG_VERSION_NUM >= 120000 +#include "utils/float.h" +#include "common/shortest_dec.h" +#endif + +#include + #if !defined(PGSPHERE_VERSION) #error "PGSPHERE_VERSION macro is not set" #endif @@ -9,7 +16,6 @@ /* Output functions */ - /* Output modes */ #define OUTPUT_RAD 1 /* output in radians */ #define OUTPUT_DEG 2 /* output in degrees */ @@ -25,7 +31,7 @@ /* * Defines the precision of floating point values in output. */ -static int sphere_output_precision = DBL_DIG; +static int sphere_output_precision = INT_MAX; PG_FUNCTION_INFO_V1(set_sphere_output); PG_FUNCTION_INFO_V1(spherepoint_out); @@ -37,6 +43,7 @@ PG_FUNCTION_INFO_V1(sphereellipse_out); PG_FUNCTION_INFO_V1(spherebox_out); PG_FUNCTION_INFO_V1(set_sphere_output_precision); +PG_FUNCTION_INFO_V1(reset_sphere_output_precision); PG_FUNCTION_INFO_V1(pg_sphere_version); /* @@ -94,6 +101,8 @@ */ Datum pg_sphere_version(PG_FUNCTION_ARGS); +static void +spheretrans_out_buffer(StringInfo si, const SEuler *se); /* * Converts radians to DEG ( degrees, minutes, seconds ) @@ -128,6 +137,116 @@ } } +static void +pgs_strinfo_put_chr(StringInfo si, char c) +{ + appendStringInfoChar(si, c); +} + +static void +pgs_strinfo_put_str(StringInfo si, char *s) +{ + appendStringInfoString(si, s); +} + +static void +pgs_strinfo_put_d64(StringInfo si, double value) +{ + int cw, + ndig; + char buf[128]; + +#if PG_VERSION_NUM >= 120000 + + if (extra_float_digits > 0) + { + cw = double_to_shortest_decimal_buf(value, buf); + } + else + { + ndig = DBL_DIG + extra_float_digits; + if (ndig < 1) + ndig = 1; + + cw = pg_strfromd(buf, 128, ndig, value); + } + +#else + + ndig = DBL_DIG + extra_float_digits; + if (ndig < 1) + ndig = 1; + + cw = snprintf(buf, 128, "%.*g", ndig, value); + +#endif + + if (cw < 0) + { + fflush(stderr); + abort(); + } + + pgs_strinfo_put_str(si, buf); +} + +static void +pgs_strinfo_put_lng_dms(StringInfo si, double lng) +{ + unsigned int lngdeg, + lngmin; + double lngsec; + + rad_to_dms(lng, &lngdeg, &lngmin, &lngsec); + + appendStringInfo(si, "%3ud %2um ", lngdeg, lngmin); + pgs_strinfo_put_d64(si, lngsec); + pgs_strinfo_put_chr(si, 's'); +} + +static void +pgs_strinfo_put_lng_hms(StringInfo si, double lng) +{ + unsigned int lnghour, + lngmin; + double lngsec; + + rad_to_dms(lng / 15.0, &lnghour, &lngmin, &lngsec); + + appendStringInfo(si, "%3uh %2um ", lnghour, lngmin); + pgs_strinfo_put_d64(si, lngsec); + pgs_strinfo_put_chr(si, 's'); +} + +static void +pgs_strinfo_put_lat_dms(StringInfo si, double lat) +{ + unsigned int latdeg, + latmin; + double latsec; + const char latsign = lat >= 0 ? '+' : '-'; + + rad_to_dms(lat, &latdeg, &latmin, &latsec); + + appendStringInfo(si, "%c%2ud %2um ", latsign, latdeg, latmin); + pgs_strinfo_put_d64(si, latsec); + pgs_strinfo_put_chr(si, 's'); +} + +static void +pgs_strinfo_put_radius_dms(StringInfo si, double radius) +{ + unsigned int rdeg, + rmin; + double rsec; + + rad_to_dms(radius, &rdeg, &rmin, &rsec); + + appendStringInfo(si, "%2ud %2um ", rdeg, rmin); + pgs_strinfo_put_d64(si, rsec); + pgs_strinfo_put_chr(si, 's'); +} + Datum set_sphere_output_precision(PG_FUNCTION_ARGS) { @@ -145,6 +264,18 @@ } Datum +reset_sphere_output_precision(PG_FUNCTION_ARGS) +{ + char *buf = (char *) palloc(20); + + sphere_output_precision = INT_MAX; + + sprintf(buf, "RESET"); + + PG_RETURN_CSTRING(buf); +} + +Datum set_sphere_output(PG_FUNCTION_ARGS) { char *c = PG_GETARG_CSTRING(0); @@ -176,8 +307,8 @@ PG_RETURN_CSTRING(buf); } -Datum -spherepoint_out(PG_FUNCTION_ARGS) +static Datum +spherepoint_out_compat(PG_FUNCTION_ARGS) { SPoint *sp = (SPoint *) PG_GETARG_POINTER(0); char *buffer = (char *) palloc(255); @@ -227,11 +358,89 @@ } PG_RETURN_CSTRING(buffer); +} + +static void +spherepoint_out_deg(StringInfo si, const SPoint *sp) +{ + pgs_strinfo_put_chr(si, '('); + pgs_strinfo_put_d64(si, RADIANS * sp->lng); + pgs_strinfo_put_str(si, "d, "); + pgs_strinfo_put_d64(si, RADIANS * sp->lat); + pgs_strinfo_put_str(si, "d)"); +} + +static void +spherepoint_out_rad(StringInfo si, const SPoint *sp) +{ + pgs_strinfo_put_chr(si, '('); + pgs_strinfo_put_d64(si, sp->lng); + pgs_strinfo_put_str(si, " , "); + pgs_strinfo_put_d64(si, sp->lat); + pgs_strinfo_put_str(si, ")"); +} +static void +spherepoint_out_dms(StringInfo si, const SPoint *sp) +{ + pgs_strinfo_put_chr(si, '('); + pgs_strinfo_put_lng_dms(si, sp->lng); + pgs_strinfo_put_str(si, " , "); + pgs_strinfo_put_lat_dms(si, sp->lat); + pgs_strinfo_put_chr(si, ')'); +} + +static void +spherepoint_out_hms(StringInfo si, const SPoint *sp) +{ + pgs_strinfo_put_chr(si, '('); + pgs_strinfo_put_lng_hms(si, sp->lng); + pgs_strinfo_put_str(si, " , "); + pgs_strinfo_put_lat_dms(si, sp->lat); + pgs_strinfo_put_chr(si, ')'); +} + +static inline void +spherepoint_out_buffer(StringInfo si, const SPoint *sp) +{ + switch (sphere_output) + { + case OUTPUT_DEG: + spherepoint_out_deg(si, sp); + break; + case OUTPUT_DMS: + spherepoint_out_dms(si, sp); + break; + case OUTPUT_HMS: + spherepoint_out_hms(si, sp); + break; + default: + spherepoint_out_rad(si, sp); + break; + } } Datum -spherecircle_out(PG_FUNCTION_ARGS) +spherepoint_out(PG_FUNCTION_ARGS) +{ + StringInfoData si; + SPoint *sp; + + if (sphere_output_precision != INT_MAX) + return spherepoint_out_compat(fcinfo); + + sp = (SPoint *) PG_GETARG_POINTER(0); + if (!sp) + PG_RETURN_NULL(); + + initStringInfo(&si); + spherepoint_out_buffer(&si, sp); + + PG_RETURN_CSTRING(si.data); +} + +static Datum +spherecircle_out_compat(PG_FUNCTION_ARGS) { SCIRCLE *c = (SCIRCLE *) PG_GETARG_POINTER(0); char *buffer = (char *) palloc(255); @@ -272,12 +481,86 @@ } pfree(pointstr); + PG_RETURN_CSTRING(buffer); +} + +static void +spherecircle_out_deg(StringInfo si, const SCIRCLE *sc) +{ + pgs_strinfo_put_chr(si, '<'); + spherepoint_out_deg(si, &sc->center); + pgs_strinfo_put_str(si, " , "); + pgs_strinfo_put_d64(si, RADIANS * sc->radius); + pgs_strinfo_put_chr(si, '>'); +} + +static void +spherecircle_out_rad(StringInfo si, const SCIRCLE *sc) +{ + pgs_strinfo_put_chr(si, '<'); + spherepoint_out_rad(si, &sc->center); + pgs_strinfo_put_str(si, " , "); + pgs_strinfo_put_d64(si, sc->radius); + pgs_strinfo_put_chr(si, '>'); +} + +static void +spherecircle_out_dms(StringInfo si, const SCIRCLE *sc) +{ + pgs_strinfo_put_chr(si, '<'); + spherepoint_out_dms(si, &sc->center); + pgs_strinfo_put_str(si, " , "); + pgs_strinfo_put_radius_dms(si, sc->radius); + pgs_strinfo_put_chr(si, '>'); +} +static void +spherecircle_out_hms(StringInfo si, const SCIRCLE *sc) +{ + pgs_strinfo_put_chr(si, '<'); + spherepoint_out_hms(si, &sc->center); + pgs_strinfo_put_str(si, " , "); + pgs_strinfo_put_radius_dms(si, sc->radius); + pgs_strinfo_put_chr(si, '>'); } Datum -sphereellipse_out(PG_FUNCTION_ARGS) +spherecircle_out(PG_FUNCTION_ARGS) +{ + StringInfoData si; + SCIRCLE *sc; + + if (sphere_output_precision != INT_MAX) + return spherecircle_out_compat(fcinfo); + + sc = (SCIRCLE *) PG_GETARG_POINTER(0); + if (!sc) + PG_RETURN_NULL(); + + initStringInfo(&si); + + switch (sphere_output) + { + case OUTPUT_DEG: + spherecircle_out_deg(&si, sc); + break; + case OUTPUT_DMS: + spherecircle_out_dms(&si, sc); + break; + case OUTPUT_HMS: + spherecircle_out_hms(&si, sc); + break; + default: + spherecircle_out_rad(&si, sc); + break; + } + + PG_RETURN_CSTRING(si.data); +} + +static Datum +sphereellipse_out_compat(PG_FUNCTION_ARGS) { SELLIPSE *e = (SELLIPSE *) PG_GETARG_POINTER(0); char *buffer = (char *) palloc(255); @@ -333,8 +616,88 @@ PG_RETURN_CSTRING(buffer); } +static void +sphereellipse_out_deg(StringInfo si, SELLIPSE *e) +{ + const SPoint sp = { e->psi, e->theta }; + + pgs_strinfo_put_str(si, "<{ "); + pgs_strinfo_put_d64(si, RADIANS * e->rad[0]); + pgs_strinfo_put_str(si, "d , "); + pgs_strinfo_put_d64(si, RADIANS * e->rad[1]); + pgs_strinfo_put_str(si, "d },"); + spherepoint_out_buffer(si, &sp); + pgs_strinfo_put_str(si, " , "); + pgs_strinfo_put_d64(si, RADIANS * e->phi); + pgs_strinfo_put_str(si, "d>"); +} + +static void +sphereellipse_out_rad(StringInfo si, SELLIPSE *e) +{ + const SPoint sp = { e->psi, e->theta }; + + pgs_strinfo_put_str(si, "<{ "); + pgs_strinfo_put_d64(si, e->rad[0]); + pgs_strinfo_put_str(si, " , "); + pgs_strinfo_put_d64(si, e->rad[1]); + pgs_strinfo_put_str(si, " },"); + spherepoint_out_buffer(si, &sp); + pgs_strinfo_put_str(si, " , "); + pgs_strinfo_put_d64(si, e->phi); + pgs_strinfo_put_str(si, ">"); +} + +static void +sphereellipse_out_dms(StringInfo si, SELLIPSE *e) +{ + const SPoint sp = { e->psi, e->theta }; + + pgs_strinfo_put_str(si, "<{ "); + pgs_strinfo_put_lng_dms(si, e->rad[0]); + pgs_strinfo_put_str(si, " , "); + pgs_strinfo_put_lng_dms(si, e->rad[1]); + pgs_strinfo_put_str(si, " },"); + spherepoint_out_buffer(si, &sp); + pgs_strinfo_put_str(si, " , "); + pgs_strinfo_put_lng_dms(si, e->phi); + pgs_strinfo_put_str(si, ">"); +} + Datum -sphereline_out(PG_FUNCTION_ARGS) +sphereellipse_out(PG_FUNCTION_ARGS) +{ + StringInfoData si; + SELLIPSE *e; + + if (sphere_output_precision != INT_MAX) + return sphereellipse_out_compat(fcinfo); + + e = (SELLIPSE *) PG_GETARG_POINTER(0); + if (!e) + PG_RETURN_NULL(); + + initStringInfo(&si); + + switch (sphere_output) + { + case OUTPUT_DEG: + sphereellipse_out_deg(&si, e); + break; + case OUTPUT_HMS: + case OUTPUT_DMS: + sphereellipse_out_dms(&si, e); + break; + default: + sphereellipse_out_rad(&si, e); + break; + } + + PG_RETURN_CSTRING(si.data); +} + +static Datum +sphereline_out_compat(PG_FUNCTION_ARGS) { SLine *sl = (SLine *) PG_GETARG_POINTER(0); char *out = (char *) palloc(255); @@ -384,7 +747,49 @@ } Datum -spheretrans_out(PG_FUNCTION_ARGS) +sphereline_out(PG_FUNCTION_ARGS) +{ + StringInfoData si; + SLine *sl; + SEuler se; + + if (sphere_output_precision != INT_MAX) + return sphereline_out_compat(fcinfo); + + sl = (SLine *) PG_GETARG_POINTER(0); + if (!sl) + PG_RETURN_NULL(); + + seuler_set_zxz(&se); + se.phi = sl->phi; + se.theta = sl->theta; + se.psi = sl->psi; + + initStringInfo(&si); + + pgs_strinfo_put_str(&si, "( "); + spheretrans_out_buffer(&si, &se); + pgs_strinfo_put_str(&si, " ), "); + + switch (sphere_output) + { + case OUTPUT_DEG: + pgs_strinfo_put_d64(&si, RADIANS * sl->length); + break; + case OUTPUT_HMS: + case OUTPUT_DMS: + pgs_strinfo_put_lng_dms(&si, sl->length); + break; + default: + pgs_strinfo_put_d64(&si, sl->length); + break; + } + + PG_RETURN_CSTRING(si.data); +} + +static Datum +spheretrans_out_compat(PG_FUNCTION_ARGS) { SEuler *se = (SEuler *) PG_GETARG_POINTER(0); char *buffer = (char *) palloc(255); @@ -469,8 +874,117 @@ PG_RETURN_CSTRING(buffer); } +static void +spheretrans_out_deg(StringInfo si, SPoint sp[3]) +{ + int i; + + for (i = 0; i < 3; ++i) + { + pgs_strinfo_put_d64(si, RADIANS * sp[i].lng); + pgs_strinfo_put_str(si, ", "); + } +} + +static void +spheretrans_out_rad(StringInfo si, SPoint sp[3]) +{ + int i; + + for (i = 0; i < 3; ++i) + { + pgs_strinfo_put_d64(si, sp[i].lng); + pgs_strinfo_put_str(si, ", "); + } +} + +static void +spheretrans_out_dms(StringInfo si, SPoint sp[3]) +{ + int i; + + for (i = 0; i < 3; ++i) + { + pgs_strinfo_put_lng_dms(si, sp[i].lng); + pgs_strinfo_put_str(si, ", "); + } +} + +static void +spheretrans_out_buffer(StringInfo si, const SEuler *se) +{ + SPoint val[3]; + unsigned char t[3]; + int i; + + val[0].lat = val[1].lat = val[2].lat = 0.0; + val[0].lng = se->phi; + val[1].lng = se->theta; + val[2].lng = se->psi; + + t[0] = se->phi_a; + t[1] = se->theta_a; + t[2] = se->psi_a; + + spoint_check(&val[0]); + spoint_check(&val[1]); + spoint_check(&val[2]); + + switch (sphere_output) + { + case OUTPUT_DEG: + spheretrans_out_deg(si, val); + break; + case OUTPUT_HMS: + case OUTPUT_DMS: + spheretrans_out_dms(si, val); + break; + default: + spheretrans_out_rad(si, val); + break; + } + + for (i = 0; i < 3; i++) + { + switch (t[i]) + { + case EULER_AXIS_X: + pgs_strinfo_put_chr(si, 'X'); + break; + case EULER_AXIS_Y: + pgs_strinfo_put_chr(si, 'Y'); + break; + case EULER_AXIS_Z: + pgs_strinfo_put_chr(si, 'Z'); + break; + default: + Assert(false); + } + } +} + Datum -spherepath_out(PG_FUNCTION_ARGS) +spheretrans_out(PG_FUNCTION_ARGS) +{ + StringInfoData si; + SEuler *se; + + if (sphere_output_precision != INT_MAX) + return spheretrans_out_compat(fcinfo); + + se = (SEuler *) PG_GETARG_POINTER(0); + if (!se) + PG_RETURN_NULL(); + + initStringInfo(&si); + + spheretrans_out_buffer(&si, se); + + PG_RETURN_CSTRING(si.data); +} + +static Datum +spherepath_out_compat(PG_FUNCTION_ARGS) { SPATH *path = PG_GETARG_SPATH(0); int32 i; @@ -494,7 +1008,37 @@ } Datum -spherepoly_out(PG_FUNCTION_ARGS) +spherepath_out(PG_FUNCTION_ARGS) +{ + StringInfoData si; + SPATH *path; + int32 i; + + if (sphere_output_precision != INT_MAX) + return spherepath_out_compat(fcinfo); + + path = PG_GETARG_SPATH(0); + if (!path) + PG_RETURN_NULL(); + + initStringInfo(&si); + + pgs_strinfo_put_chr(&si, '{'); + + for (i = 0; i < path->npts; ++i) + { + if (i > 0) + pgs_strinfo_put_chr(&si, ','); + spherepoint_out_buffer(&si, &path->p[i]); + } + + pgs_strinfo_put_chr(&si, '}'); + + PG_RETURN_CSTRING(si.data); +} + +static Datum +spherepoly_out_compat(PG_FUNCTION_ARGS) { SPOLY *poly = PG_GETARG_SPOLY(0); int32 i; @@ -518,7 +1062,37 @@ } Datum -spherebox_out(PG_FUNCTION_ARGS) +spherepoly_out(PG_FUNCTION_ARGS) +{ + StringInfoData si; + SPOLY *poly; + int32 i; + + if (sphere_output_precision != INT_MAX) + return spherepoly_out_compat(fcinfo); + + poly = PG_GETARG_SPOLY(0); + if (!poly) + PG_RETURN_NULL(); + + initStringInfo(&si); + + pgs_strinfo_put_chr(&si, '{'); + + for (i = 0; i < poly->npts; ++i) + { + if (i > 0) + pgs_strinfo_put_chr(&si, ','); + spherepoint_out_buffer(&si, &poly->p[i]); + } + + pgs_strinfo_put_chr(&si, '}'); + + PG_RETURN_CSTRING(si.data); +} + +static Datum +spherebox_out_compat(PG_FUNCTION_ARGS) { SBOX *box = (SBOX *) PG_GETARG_POINTER(0); char *buffer = (char *) palloc(255); @@ -536,6 +1110,30 @@ } Datum +spherebox_out(PG_FUNCTION_ARGS) +{ + StringInfoData si; + SBOX *box; + + if (sphere_output_precision != INT_MAX) + return spherebox_out_compat(fcinfo); + + box = (SBOX *) PG_GETARG_POINTER(0); + if (!box) + PG_RETURN_NULL(); + + initStringInfo(&si); + + pgs_strinfo_put_chr(&si, '('); + spherepoint_out_buffer(&si, &box->sw); + pgs_strinfo_put_str(&si, ", "); + spherepoint_out_buffer(&si, &box->ne); + pgs_strinfo_put_chr(&si, ')'); + + PG_RETURN_CSTRING(si.data); +} + +Datum pg_sphere_version(PG_FUNCTION_ARGS) { const char *s = PGSPHERE_STRINGIFY(PGSPHERE_VERSION); diff -Nru pgsphere-1.4.2/src/path.h pgsphere-1.5.1/src/path.h --- pgsphere-1.4.2/src/path.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/path.h 2024-04-22 06:22:05.000000000 +0000 @@ -12,22 +12,22 @@ */ typedef struct { - char vl_len_[4]; /* total size in bytes */ - int32 npts; /* count of points */ - SPoint p[1]; /* variable length array of SPoints */ + char vl_len_[4]; /* total size in bytes */ + int32 npts; /* count of points */ + SPoint p[1]; /* variable length array of SPoints */ } SPATH; /* Path and circle */ -#define PGS_CIRCLE_PATH_AVOID 0 /* circle avoids path */ -#define PGS_CIRCLE_CONT_PATH 1 /* circle contains path */ -#define PGS_CIRCLE_PATH_OVER 2 /* circle overlaps path */ +#define PGS_CIRCLE_PATH_AVOID 0 /* circle avoids path */ +#define PGS_CIRCLE_CONT_PATH 1 /* circle contains path */ +#define PGS_CIRCLE_PATH_OVER 2 /* circle overlaps path */ /* Path and polygon */ -#define PGS_POLY_PATH_AVOID 0 /* polygon avoids path */ -#define PGS_POLY_CONT_PATH 1 /* polygon contains path */ -#define PGS_POLY_PATH_OVER 2 /* polygon and path overlap */ +#define PGS_POLY_PATH_AVOID 0 /* polygon avoids path */ +#define PGS_POLY_CONT_PATH 1 /* polygon contains path */ +#define PGS_POLY_PATH_OVER 2 /* polygon and path overlap */ /* Path and ellipse */ #define PGS_ELLIPSE_PATH_AVOID 0 /* ellipse avoids path */ @@ -41,12 +41,12 @@ /* * Checks whether two paths are equal. */ -bool spath_eq(const SPATH *p1, const SPATH *p2); +extern bool spath_eq(const SPATH *p1, const SPATH *p2); /* * Checks whether a path contains a point. */ -bool spath_cont_point(const SPATH *path, const SPoint *sp); +extern bool spath_cont_point(const SPATH *path, const SPoint *sp); /* * Returns the i-th line segment of a path. @@ -57,24 +57,24 @@ * * Returns the pointer to the line segment or NULL if fails. */ -bool spath_segment(SLine *sl, const SPATH *path, int32 i); +extern bool spath_segment(SLine *sl, const SPATH *path, int32 i); /* * Input function of path. */ -Datum spherepath_in(PG_FUNCTION_ARGS); +extern Datum spherepath_in(PG_FUNCTION_ARGS); /* * Returns the n-th point of a path. * * See spherepath_get_point(PG_FUNCTION_ARGS) */ -Datum spherepath_get_point(PG_FUNCTION_ARGS); +extern Datum spherepath_get_point(PG_FUNCTION_ARGS); /* * Returns spath as array of points */ -Datum spherepath_get_array(PG_FUNCTION_ARGS); +extern Datum spherepath_get_array(PG_FUNCTION_ARGS); /* * This function interpolates between points of path. Returns the @@ -82,212 +82,212 @@ * * See spherepath_point(PG_FUNCTION_ARGS) */ -Datum spherepath_point(PG_FUNCTION_ARGS); +extern Datum spherepath_point(PG_FUNCTION_ARGS); /* * Checks whether two paths are equal. */ -Datum spherepath_equal(PG_FUNCTION_ARGS); +extern Datum spherepath_equal(PG_FUNCTION_ARGS); /* * Checks whether two paths aren't equal. */ -Datum spherepath_equal_neg(PG_FUNCTION_ARGS); +extern Datum spherepath_equal_neg(PG_FUNCTION_ARGS); /* * Returns the length of a path. */ -Datum spherepath_length(PG_FUNCTION_ARGS); +extern Datum spherepath_length(PG_FUNCTION_ARGS); /* * Returns the number of points in a path. */ -Datum spherepath_npts(PG_FUNCTION_ARGS); +extern Datum spherepath_npts(PG_FUNCTION_ARGS); /* * Changes the direction of a path. */ -Datum spherepath_swap(PG_FUNCTION_ARGS); +extern Datum spherepath_swap(PG_FUNCTION_ARGS); /* * Checks whether a path contains a point. */ -Datum spherepath_cont_point(PG_FUNCTION_ARGS); +extern Datum spherepath_cont_point(PG_FUNCTION_ARGS); /* * Checks whether a path doesn't contain a point. */ -Datum spherepath_cont_point_neg(PG_FUNCTION_ARGS); +extern Datum spherepath_cont_point_neg(PG_FUNCTION_ARGS); /* * Checks whether a path contains a point. */ -Datum spherepath_cont_point_com(PG_FUNCTION_ARGS); +extern Datum spherepath_cont_point_com(PG_FUNCTION_ARGS); /* * Checks whether a path doesn't contain a point. */ -Datum spherepath_cont_point_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepath_cont_point_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a path and a line overlap. */ -Datum spherepath_overlap_line(PG_FUNCTION_ARGS); +extern Datum spherepath_overlap_line(PG_FUNCTION_ARGS); /* * Checks whether a path and a line don't overlap. */ -Datum spherepath_overlap_line_neg(PG_FUNCTION_ARGS); +extern Datum spherepath_overlap_line_neg(PG_FUNCTION_ARGS); /* * Checks whether path and line overlap. */ -Datum spherepath_overlap_line_com(PG_FUNCTION_ARGS); +extern Datum spherepath_overlap_line_com(PG_FUNCTION_ARGS); /* * Checks whether a path and a line don't overlap. */ -Datum spherepath_overlap_line_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepath_overlap_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a path. */ -Datum spherecircle_cont_path(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_path(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a path. */ -Datum spherecircle_cont_path_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_path_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a path. */ -Datum spherecircle_cont_path_com(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_path_com(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a path. */ -Datum spherecircle_cont_path_com_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and a path overlap. */ -Datum spherecircle_overlap_path(PG_FUNCTION_ARGS); +extern Datum spherecircle_overlap_path(PG_FUNCTION_ARGS); /* * Checks whether a circle and a path don't overlap. */ -Datum spherecircle_overlap_path_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_overlap_path_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle and a path overlap. */ -Datum spherecircle_overlap_path_com(PG_FUNCTION_ARGS); +extern Datum spherecircle_overlap_path_com(PG_FUNCTION_ARGS); /* * Checks whether a circle and a path don't overlap. */ -Datum spherecircle_overlap_path_com_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_overlap_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a path. */ -Datum spherepoly_cont_path(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_path(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a path. */ -Datum spherepoly_cont_path_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_path_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains path. */ -Datum spherepoly_cont_path_com(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_path_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a path. */ -Datum spherepoly_cont_path_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a path overlap. */ -Datum spherepoly_overlap_path(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_path(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a path don't overlap. */ -Datum spherepoly_overlap_path_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_path_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a path overlap. */ -Datum spherepoly_overlap_path_com(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_path_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a path don't overlap. */ -Datum spherepoly_overlap_path_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether two paths overlap. */ -Datum spherepath_overlap_path(PG_FUNCTION_ARGS); +extern Datum spherepath_overlap_path(PG_FUNCTION_ARGS); /* * Checks whether two paths don't overlap. */ -Datum spherepath_overlap_path_neg(PG_FUNCTION_ARGS); +extern Datum spherepath_overlap_path_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains path. */ -Datum sphereellipse_cont_path(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_path(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a path. */ -Datum sphereellipse_cont_path_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_path_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a path. */ -Datum sphereellipse_cont_path_com(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_path_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a path. */ -Datum sphereellipse_cont_path_com_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_path_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a path overlap. */ -Datum sphereellipse_overlap_path(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_path(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a path don't overlap. */ -Datum sphereellipse_overlap_path_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_path_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a path overlap. */ -Datum sphereellipse_overlap_path_com(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_path_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse and a path don't overlap. */ -Datum sphereellipse_overlap_path_com_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_overlap_path_com_neg(PG_FUNCTION_ARGS); /* * Performs an Euler transformation on a path. */ -Datum spheretrans_path(PG_FUNCTION_ARGS); +extern Datum spheretrans_path(PG_FUNCTION_ARGS); /* * Performs an inverse Euler transformation on a path. */ -Datum spheretrans_path_inverse(PG_FUNCTION_ARGS); +extern Datum spheretrans_path_inverse(PG_FUNCTION_ARGS); /* * State transition function for aggregate function spath(spoint). Never @@ -295,11 +295,11 @@ * * Adds a point to a path. */ -Datum spherepath_add_point(PG_FUNCTION_ARGS); +extern Datum spherepath_add_point(PG_FUNCTION_ARGS); /* * Finalize function for adding spoints to a path. */ -Datum spherepath_add_points_finalize(PG_FUNCTION_ARGS); +extern Datum spherepath_add_points_finalize(PG_FUNCTION_ARGS); #endif diff -Nru pgsphere-1.4.2/src/pg_sphere.h pgsphere-1.5.1/src/pg_sphere.h --- pgsphere-1.4.2/src/pg_sphere.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/pg_sphere.h 2024-04-22 06:22:05.000000000 +0000 @@ -72,7 +72,7 @@ #else #define PGSPHERE_FLOAT_STORE 0 #endif -#endif // PGSPHERE_FLOAT_STORE +#endif /* PGSPHERE_FLOAT_STORE */ #define EPSILON 1.0E-09 @@ -84,6 +84,7 @@ FPeq(double A, double B) { const volatile double AB = A - B; + return A == B || fabs(AB) <= EPSILON; } @@ -91,6 +92,7 @@ FPne(double A, double B) { const volatile double AB = A - B; + return A != B && fabs(AB) > EPSILON; } @@ -98,6 +100,7 @@ FPlt(double A, double B) { const volatile double AE = A + EPSILON; + return AE < B; } @@ -105,6 +108,7 @@ FPle(double A, double B) { const volatile double BE = B + EPSILON; + return A <= BE; } @@ -112,6 +116,7 @@ FPgt(double A, double B) { const volatile double BE = B + EPSILON; + return A > BE; } @@ -119,6 +124,7 @@ FPge(double A, double B) { const volatile double AE = A + EPSILON; + return AE >= B; } @@ -160,7 +166,7 @@ return A + EPSILON >= B; } -#endif // PGSPHERE_FLOAT_STORE +#endif /* PGSPHERE_FLOAT_STORE */ /*--------------------------------------------------------------------- * Point - (x,y) @@ -171,7 +177,6 @@ y; } Point; -void sphere_yyparse(void); +extern void sphere_yyparse(void); #endif - diff -Nru pgsphere-1.4.2/src/pgs_chealpix.h pgsphere-1.5.1/src/pgs_chealpix.h --- pgsphere-1.4.2/src/pgs_chealpix.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/pgs_chealpix.h 2024-04-22 06:22:05.000000000 +0000 @@ -2,7 +2,7 @@ #define __PGS_CHEALPIX_H__ #include -#include /* PostgreSQL type definitions */ +#include /* PostgreSQL type definitions */ /* * Actually, chealpix changed its API: thus, this file must be included first, * directly or indirectly. diff -Nru pgsphere-1.4.2/src/pgs_util.h pgsphere-1.5.1/src/pgs_util.h --- pgsphere-1.4.2/src/pgs_util.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/pgs_util.h 2024-04-22 06:22:05.000000000 +0000 @@ -1,18 +1,18 @@ #ifndef __PGS_UTIL_H__ #define __PGS_UTIL_H__ -#define PI 3.14159265358979323846 /* pi */ -#define PIH 1.57079632679489661923 /* pi/2 */ -#define PID 6.2831853071795864769 /* 2*pi */ -#define RADIANS 57.295779513082320877 /* 180/pi */ +#define PI 3.14159265358979323846 /* pi */ +#define PIH 1.57079632679489661923 /* pi/2 */ +#define PID 6.2831853071795864769 /* 2*pi */ +#define RADIANS 57.295779513082320877 /* 180/pi */ #define PI_EPS 4.4408920985006261617e-16 /* 2 ** -51 */ -#define Sqr(a) ( (a) * (a) ) /* square function as macro */ +#define Sqr(a) ( (a) * (a) ) /* square function as macro */ #ifdef EPSILON #undef EPSILON #endif -#define EPSILON 1.0E-09 /* precision of floating point values */ +#define EPSILON 1.0E-09 /* precision of floating point values */ /* spherical circle constants */ #define SPHERE_SURFACE (4 * PI) @@ -22,7 +22,8 @@ static inline double conv_theta(double x) { - double y = PIH - x; + double y = PIH - x; + if (fabs(x) < PI_EPS / 2) return PIH; if (fabs(y) < PI_EPS / 2) @@ -30,7 +31,8 @@ return y; } -static inline double deg_to_rad(double in) +static inline double +deg_to_rad(double in) { return in * PI / 180; } diff -Nru pgsphere-1.4.2/src/point.h pgsphere-1.5.1/src/point.h --- pgsphere-1.4.2/src/point.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/point.h 2024-04-22 06:22:05.000000000 +0000 @@ -11,100 +11,109 @@ */ typedef struct { - float8 lng; /* longitude value in radians */ - float8 lat; /* latitude value in radians */ + float8 lng; /* longitude value in radians */ + float8 lat; /* latitude value in radians */ } SPoint; -Oid get_spoint_type_oid(void); +extern Oid get_spoint_type_oid(void); /* * Calculate the distance between two spherical points in radians. */ -float8 spoint_dist(const SPoint *p1, const SPoint *p2); + +extern float8 spoint_dist(const SPoint *p1, const SPoint *p2); /* * Check whether two points are equal. */ -bool spoint_eq(const SPoint *p1, const SPoint *p2); + +extern bool spoint_eq(const SPoint *p1, const SPoint *p2); /* * Check the longitude and latitude values of a spherical point. */ -void spoint_check(SPoint *spoint); + +extern void spoint_check(SPoint *spoint); /* * Transforms a 3d vector into a spherical point. */ -void vector3d_spoint(SPoint *p, const Vector3D *v); + +extern void vector3d_spoint(SPoint *p, const Vector3D *v); /* * Transforms a spherical point into a 3d vector. */ -void spoint_vector3d(Vector3D *v, const SPoint *p); + +extern void spoint_vector3d(Vector3D *v, const SPoint *p); /* * Take the input and store it as a spherical point. */ -Datum spherepoint_in(PG_FUNCTION_ARGS); + +extern Datum spherepoint_in(PG_FUNCTION_ARGS); /* * Create spherical point from lat, lng and store to first argument(pointer) */ -void create_spherepoint_from_long_lat(SPoint *p, float8 lng, float8 lat); + +extern void create_spherepoint_from_long_lat(SPoint *p, float8 lng, float8 lat); /* * Create a spherical point from longitude and latitude both in radians. */ -Datum spherepoint_from_long_lat(PG_FUNCTION_ARGS); + +extern Datum spherepoint_from_long_lat(PG_FUNCTION_ARGS); /* * Create a spherical point from longitude and latitude both in degrees. */ -Datum spherepoint_from_long_lat_deg(PG_FUNCTION_ARGS); + +extern Datum spherepoint_from_long_lat_deg(PG_FUNCTION_ARGS); /* * Calculate the distance between two spherical points. */ -Datum spherepoint_distance(PG_FUNCTION_ARGS); +extern Datum spherepoint_distance(PG_FUNCTION_ARGS); /* * Longitude of a spherical point. */ -Datum spherepoint_long(PG_FUNCTION_ARGS); +extern Datum spherepoint_long(PG_FUNCTION_ARGS); /* * Latitude of a spherical point. */ -Datum spherepoint_lat(PG_FUNCTION_ARGS); +extern Datum spherepoint_lat(PG_FUNCTION_ARGS); /* * Cartesian x-value of a spherical point. */ -Datum spherepoint_x(PG_FUNCTION_ARGS); +extern Datum spherepoint_x(PG_FUNCTION_ARGS); /* * Cartesian y-value of a spherical point. */ -Datum spherepoint_y(PG_FUNCTION_ARGS); +extern Datum spherepoint_y(PG_FUNCTION_ARGS); /* * Cartesian z-value of a spherical point. */ -Datum spherepoint_z(PG_FUNCTION_ARGS); +extern Datum spherepoint_z(PG_FUNCTION_ARGS); /* * Cartesian values of a spherical point as an array. */ -Datum spherepoint_xyz(PG_FUNCTION_ARGS); +extern Datum spherepoint_xyz(PG_FUNCTION_ARGS); /* * Check whether two points are equal. */ -Datum spherepoint_equal(PG_FUNCTION_ARGS); +extern Datum spherepoint_equal(PG_FUNCTION_ARGS); /* * Compute a 32-bit hash value of a point. */ -Datum spherepoint_hash32(PG_FUNCTION_ARGS); +extern Datum spherepoint_hash32(PG_FUNCTION_ARGS); #endif diff -Nru pgsphere-1.4.2/src/polygon.h pgsphere-1.5.1/src/polygon.h --- pgsphere-1.4.2/src/polygon.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/polygon.h 2024-04-22 06:22:05.000000000 +0000 @@ -12,9 +12,9 @@ */ typedef struct { - char vl_len_[4]; /* total size in bytes */ - int32 npts; /* count of points */ - SPoint p[1]; /* variable length array of SPoints */ + char vl_len_[4]; /* total size in bytes */ + int32 npts; /* count of points */ + SPoint p[1]; /* variable length array of SPoints */ } SPOLY; #define MAX_POINTS 1024 @@ -26,20 +26,20 @@ #define PGS_ELLIPSE_POLY_OVER 3 /* ellipse overlaps polygon */ /* Polygon and circle */ -#define PGS_CIRCLE_POLY_AVOID 0 /* circle avoids polygon */ -#define PGS_POLY_CONT_CIRCLE 1 /* polygon contains circle */ -#define PGS_CIRCLE_CONT_POLY 2 /* circle contains polygon */ -#define PGS_CIRCLE_POLY_OVER 3 /* circle overlap polygon */ +#define PGS_CIRCLE_POLY_AVOID 0 /* circle avoids polygon */ +#define PGS_POLY_CONT_CIRCLE 1 /* polygon contains circle */ +#define PGS_CIRCLE_CONT_POLY 2 /* circle contains polygon */ +#define PGS_CIRCLE_POLY_OVER 3 /* circle overlap polygon */ /* Polygon and line */ -#define PGS_LINE_POLY_AVOID 0 /* line avoids polygon */ -#define PGS_POLY_CONT_LINE 1 /* polygon contains line */ -#define PGS_LINE_POLY_OVER 2 /* line overlap polygon */ +#define PGS_LINE_POLY_AVOID 0 /* line avoids polygon */ +#define PGS_POLY_CONT_LINE 1 /* polygon contains line */ +#define PGS_LINE_POLY_OVER 2 /* line overlap polygon */ /* Polygon and polygon */ -#define PGS_POLY_AVOID 0 /* polygon avoids other polygon */ -#define PGS_POLY_CONT 1 /* polygon contains other polygon */ -#define PGS_POLY_OVER 2 /* polygons overlap */ +#define PGS_POLY_AVOID 0 /* polygon avoids other polygon */ +#define PGS_POLY_CONT 1 /* polygon contains other polygon */ +#define PGS_POLY_OVER 2 /* polygons overlap */ #define PG_GETARG_SPOLY( arg ) \ @@ -53,7 +53,7 @@ * * If 'dir' is true, check with reverse polygon of 'p2'. */ -bool spoly_eq(const SPOLY *p1, const SPOLY *p2, bool dir); +extern bool spoly_eq(const SPOLY *p1, const SPOLY *p2, bool dir); /* * Returns the i-th line segment of a polygon. @@ -62,7 +62,7 @@ * poly - pointer to the polygon * i - number of the segment */ -bool spoly_segment(SLine *sl, const SPOLY *poly, int32 i); +extern bool spoly_segment(SLine *sl, const SPOLY *poly, int32 i); /* * Checks whether a polygon contains a point. @@ -70,12 +70,12 @@ * pg - pointer to the polygon * sp - pointer to the point */ -bool spoly_contains_point(const SPOLY *pg, const SPoint *sp); +extern bool spoly_contains_point(const SPOLY *pg, const SPoint *sp); /* * Returns the n-th point of a spoly. */ -Datum spherepoly_get_point(PG_FUNCTION_ARGS); +extern Datum spherepoly_get_point(PG_FUNCTION_ARGS); /* * Returns the relationship between a polygon and a line as @@ -84,295 +84,295 @@ * poly - pointer to the polygon * line - pointer to the line */ -int8 poly_line_pos(const SPOLY *poly, const SLine *line); +extern int8 poly_line_pos(const SPOLY *poly, const SLine *line); /* * Creates a spherical polygon (spoly) from an array of pair-consecutive * numbers (lng, lat), in radians. */ -Datum spherepoly_rad(PG_FUNCTION_ARGS); +extern Datum spherepoly_rad(PG_FUNCTION_ARGS); /* * Creates a spherical polygon (spoly) from an array of pair-consecutive * numbers (lng, lat), in degrees. */ -Datum spherepoly_deg(PG_FUNCTION_ARGS); +extern Datum spherepoly_deg(PG_FUNCTION_ARGS); /* * Creates a spherical polygon (spoly) from an array of spoint elements. */ -Datum spherepoly_from_point_array(PG_FUNCTION_ARGS); +extern Datum spherepoly_from_point_array(PG_FUNCTION_ARGS); /* * Input of a spherical polygon. */ -Datum spherepoly_in(PG_FUNCTION_ARGS); +extern Datum spherepoly_in(PG_FUNCTION_ARGS); /* * Checks whether two polygons are equal. */ -Datum spherepoly_equal(PG_FUNCTION_ARGS); +extern Datum spherepoly_equal(PG_FUNCTION_ARGS); /* * Checks whether two polygons are not equal. */ -Datum spherepoly_equal_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_equal_neg(PG_FUNCTION_ARGS); /* * Circumstance of a polygon. Returns circumference in radians * (float8 datum). */ -Datum spherepoly_circ(PG_FUNCTION_ARGS); +extern Datum spherepoly_circ(PG_FUNCTION_ARGS); /* * Count points (edges) of a polygon. */ -Datum spherepoly_npts(PG_FUNCTION_ARGS); +extern Datum spherepoly_npts(PG_FUNCTION_ARGS); /* * Returns area of a polygon. */ -Datum spherepoly_area(PG_FUNCTION_ARGS); +extern Datum spherepoly_area(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a point. */ -Datum spherepoly_cont_point(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_point(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a point. */ -Datum spherepoly_cont_point_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_point_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a point. */ -Datum spherepoly_cont_point_com(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_point_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a point. */ -Datum spherepoly_cont_point_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_point_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a circle. */ -Datum spherepoly_cont_circle(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_circle(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a circle. */ -Datum spherepoly_cont_circle_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a circle. */ -Datum spherepoly_cont_circle_com(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_circle_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a circle. */ -Datum spherepoly_cont_circle_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a polygon. */ -Datum spherecircle_cont_poly(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_poly(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a polygon. */ -Datum spherecircle_cont_poly_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_poly_neg(PG_FUNCTION_ARGS); /* * Checks whether a circle contains a polygon. */ -Datum spherecircle_cont_poly_com(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_poly_com(PG_FUNCTION_ARGS); /* * Checks whether a circle doesn't contain a polygon. */ -Datum spherecircle_cont_poly_com_neg(PG_FUNCTION_ARGS); +extern Datum spherecircle_cont_poly_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a circle overlap. */ -Datum spherepoly_overlap_circle(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_circle(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a circle don't overlap. */ -Datum spherepoly_overlap_circle_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_circle_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a circle overlap. */ -Datum spherepoly_overlap_circle_com(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_circle_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a circle don't overlap. */ -Datum spherepoly_overlap_circle_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_circle_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a line. */ -Datum spherepoly_cont_line(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_line(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a line. */ -Datum spherepoly_cont_line_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_line_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains a line. */ -Datum spherepoly_cont_line_com(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_line_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain a line. */ -Datum spherepoly_cont_line_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a line overlap. */ -Datum spherepoly_overlap_line(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_line(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a line don't overlap. */ -Datum spherepoly_overlap_line_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_line_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a line overlap. */ -Datum spherepoly_overlap_line_com(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_line_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon and a line don't overlap. */ -Datum spherepoly_overlap_line_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_line_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains other polygon. */ -Datum spherepoly_cont_poly(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_poly(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain other polygon. */ -Datum spherepoly_cont_poly_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_poly_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains other polygon. */ -Datum spherepoly_cont_poly_com(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_poly_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain other polygon. */ -Datum spherepoly_cont_poly_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_poly_com_neg(PG_FUNCTION_ARGS); /* * Checks whether two polygons overlap. */ -Datum spherepoly_overlap_poly(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_poly(PG_FUNCTION_ARGS); /* * Checks whether two polygons don't overlap. */ -Datum spherepoly_overlap_poly_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_poly_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains an ellipse. */ -Datum spherepoly_cont_ellipse(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_ellipse(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain an ellipse. */ -Datum spherepoly_cont_ellipse_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_ellipse_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon contains an ellipse. */ -Datum spherepoly_cont_ellipse_com(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_ellipse_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon doesn't contain an ellipse. */ -Datum spherepoly_cont_ellipse_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_cont_ellipse_com_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a polygon. */ -Datum sphereellipse_cont_poly(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_poly(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a polygon. */ -Datum sphereellipse_cont_poly_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_poly_neg(PG_FUNCTION_ARGS); /* * Checks whether an ellipse contains a polygon. */ -Datum sphereellipse_cont_poly_com(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_poly_com(PG_FUNCTION_ARGS); /* * Checks whether an ellipse doesn't contain a polygon. */ -Datum sphereellipse_cont_poly_com_neg(PG_FUNCTION_ARGS); +extern Datum sphereellipse_cont_poly_com_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and an ellipse overlap. */ -Datum spherepoly_overlap_ellipse(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_ellipse(PG_FUNCTION_ARGS); /* * Checks whether a polygon and an ellipse don't overlap. */ -Datum spherepoly_overlap_ellipse_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_ellipse_neg(PG_FUNCTION_ARGS); /* * Checks whether a polygon and an ellipse overlap. */ -Datum spherepoly_overlap_ellipse_com(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_ellipse_com(PG_FUNCTION_ARGS); /* * Checks whether a polygon and an ellipse don't overlap. */ -Datum spherepoly_overlap_ellipse_com_neg(PG_FUNCTION_ARGS); +extern Datum spherepoly_overlap_ellipse_com_neg(PG_FUNCTION_ARGS); /* * Performs inverse transform on a polygon using an Euler transformation. */ -Datum spheretrans_poly(PG_FUNCTION_ARGS); +extern Datum spheretrans_poly(PG_FUNCTION_ARGS); /* * Performs inverse transform on a polygon using an Euler transformation. */ -Datum spheretrans_poly_inverse(PG_FUNCTION_ARGS); +extern Datum spheretrans_poly_inverse(PG_FUNCTION_ARGS); /* * State transition function for the aggregate function spoly(spoint). Never * call this function outside an aggregate function! Adds a point to a polygon. */ -Datum spherepoly_add_point(PG_FUNCTION_ARGS); +extern Datum spherepoly_add_point(PG_FUNCTION_ARGS); /* * Finalize function for adding spoints to a polygon. */ -Datum spherepoly_add_points_finalize(PG_FUNCTION_ARGS); +extern Datum spherepoly_add_points_finalize(PG_FUNCTION_ARGS); /* * Returns spoly as array of points */ -Datum spherepoly_get_array(PG_FUNCTION_ARGS); +extern Datum spherepoly_get_array(PG_FUNCTION_ARGS); /* * Checks whether a polygon is convex */ -Datum spherepoly_is_convex(PG_FUNCTION_ARGS); +extern Datum spherepoly_is_convex(PG_FUNCTION_ARGS); #endif diff -Nru pgsphere-1.4.2/src/sbuffer.h pgsphere-1.5.1/src/sbuffer.h --- pgsphere-1.4.2/src/sbuffer.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/sbuffer.h 2024-04-22 06:22:05.000000000 +0000 @@ -3,89 +3,89 @@ /* Parser buffer declarations */ -#define STYPE_UNKNOWN 0 /* unknown type */ -#define STYPE_POINT 1 /* input is spherical type */ -#define STYPE_CIRCLE 2 /* input is spherical circle */ -#define STYPE_LINE 3 /* input is spherical line */ -#define STYPE_EULER 4 /* input is Euler transformation */ -#define STYPE_PATH 5 /* input is spherical path or polygon */ -#define STYPE_ELLIPSE 6 /* input is spherical ellipse */ -#define STYPE_BOX 7 /* input is spherical box */ +#define STYPE_UNKNOWN 0 /* unknown type */ +#define STYPE_POINT 1 /* input is spherical type */ +#define STYPE_CIRCLE 2 /* input is spherical circle */ +#define STYPE_LINE 3 /* input is spherical line */ +#define STYPE_EULER 4 /* input is Euler transformation */ +#define STYPE_PATH 5 /* input is spherical path or polygon */ +#define STYPE_ELLIPSE 6 /* input is spherical ellipse */ +#define STYPE_BOX 7 /* input is spherical box */ /* PGS_EULER_AXIS Euler axis */ -#define EULER_AXIS_X 1 /* x - axis for Euler transformation */ -#define EULER_AXIS_Y 2 /* y - axis for Euler transformation */ -#define EULER_AXIS_Z 3 /* z - axis for Euler transformation */ - -int sphere_yylex(); -void sphere_yyerror(const char *str); -void sphere_flush_scanner_buffer(void); +#define EULER_AXIS_X 1 /* x - axis for Euler transformation */ +#define EULER_AXIS_Y 2 /* y - axis for Euler transformation */ +#define EULER_AXIS_Z 3 /* z - axis for Euler transformation */ + +extern int sphere_yylex(); +extern void sphere_yyerror(const char *str); +extern void sphere_flush_scanner_buffer(void); /* Sets the data type */ -void set_spheretype(unsigned char st); +extern void set_spheretype(unsigned char st); /* Initialize the input buffer */ -void init_buffer(char *buffer); +extern void init_buffer(char *buffer); /* Resets the input buffer */ -void reset_buffer(void); +extern void reset_buffer(void); /* * Read the "offset" number of bytes from "buf" buffer. * Returns the number of read bytes. */ -int get_buffer(char *buf, int offset); +extern int get_buffer(char *buf, int offset); /* * Input of an angle. When is_deg > 0 then "a" is in degrees, * otherwise it's in radians. Returns the unique ID (position) of the angle. */ -int set_angle(unsigned char is_deg, double a); +extern int set_angle(unsigned char is_deg, double a); /* * Set the sign of an angle. "apos" is the angle. "s" is a sign of the angle * ( < 0 .. - , > 0 .. + ). Returns the unique ID (position) of the angle. */ -int set_angle_sign(int apos, int s); +extern int set_angle_sign(int apos, int s); /* * Creates a spherical point. "lngpos" is the ID of a longitude angle, "latpos" * is the ID of a latitude angle. Returns the unique ID (position) of the spherical * point. */ -int set_point(int lngpos, int latpos); +extern int set_point(int lngpos, int latpos); /* * Creates a spherical circle. "spos" is the ID of a spherical point, "rpos" * is the ID of a radius angle. */ -void set_circle(int spos, int rpos); +extern void set_circle(int spos, int rpos); /* * Sets the length of a spherical line. "length" is the ID of a length angle. */ -void set_line(int length); +extern void set_line(int length); /* * Creates an Euler transformation. "phi" is the ID of a first angle, * "theta" is the ID of a second angle, "psi" is the ID of a third angle, * "etype" is the three letter code of Euler transformation axes. */ -void set_euler(int phi, int theta, int psi, char *etype); +extern void set_euler(int phi, int theta, int psi, char *etype); /* * Creates a spherical ellipse. "r1" is the ID of a first radius angle, * "r2" is the ID of a second radius angle, "sp" is the ID of a spherical * point ( center ), "inc" is the ID of an inclination angle. */ -void set_ellipse(int r1, int r2, int sp, int inc); +extern void set_ellipse(int r1, int r2, int sp, int inc); /* * Returns the point parameters. "lng" is the pointer to a longitude * value, "lat" is the pointer to a latitude value. Returns 0 if user * input is a spherical point. */ -int get_point(double *lng, double *lat); +extern int get_point(double *lng, double *lat); /* * Returns the circle parameters. "lng" is pointer to a longitude @@ -93,7 +93,7 @@ * "radius" is the pointer to the radius value. Returns 0 if user input * is a spherical circle. */ -int get_circle(double *lng, double *lat, double *radius); +extern int get_circle(double *lng, double *lat, double *radius); /* * Returns the ellipse parameters. "lng" is the pointer to a longitude value @@ -102,8 +102,8 @@ * radius value, "inc" is the pointer to an inclination angle. Returns 0 if user * input is a spherical ellipse. */ -int get_ellipse(double *lng, double *lat, double *r1, - double *r2, double *inc); +extern int get_ellipse(double *lng, double *lat, double *r1, + double *r2, double *inc); /* * Returns the line parameters. "phi" is the pointer to the first angle @@ -112,8 +112,8 @@ * "etype" is the pointer to the axes value of Euler transformation, "length" is * the pointer to the length value. Returns 0 if user input is a spherical line. */ -int get_line(double *phi, double *theta, double *psi, - unsigned char *etype, double *length); +extern int get_line(double *phi, double *theta, double *psi, + unsigned char *etype, double *length); /* * Returns the Euler transformation parameters. "phi" is the pointer to the @@ -122,20 +122,20 @@ * transformation, "etype" is the pointer to the axes value of Euler transformation. * Returns 0 if user input is an Euler transformation. */ -int get_euler(double *phi, double *theta, - double *psi, unsigned char *etype); +extern int get_euler(double *phi, double *theta, + double *psi, unsigned char *etype); /* * Returns the number of path elements. */ -int get_path_count(void); +extern int get_path_count(void); /* * Returns the elements of a path. "spos" is the number of element, "lng" is * the ID of longitude angle, "lat" is the ID of a latitude angle. Returns 0 * if user input is a path or a polygon and "spos" is valid. */ -int get_path_elem(int spos, double *lng, double *lat); +extern int get_path_elem(int spos, double *lng, double *lat); /* * Returns the elements of a box. "lng1" is the ID of the first longitude @@ -143,6 +143,6 @@ * the second longitude angle, "lat2" is the ID of the second latitude angle. * Returns 0 if user input is a box. */ -int get_box(double *lng1, double *lat1, double *lng2, double *lat2); +extern int get_box(double *lng1, double *lat1, double *lng2, double *lat2); #endif diff -Nru pgsphere-1.4.2/src/vector3d.h pgsphere-1.5.1/src/vector3d.h --- pgsphere-1.4.2/src/vector3d.h 2023-12-12 05:03:24.000000000 +0000 +++ pgsphere-1.5.1/src/vector3d.h 2024-04-22 06:22:05.000000000 +0000 @@ -10,9 +10,9 @@ */ typedef struct { - float8 x; /* x (-1.0 .. 1.0) */ - float8 y; /* y (-1.0 .. 1.0) */ - float8 z; /* z (-1.0 .. 1.0) */ + float8 x; /* x (-1.0 .. 1.0) */ + float8 y; /* y (-1.0 .. 1.0) */ + float8 z; /* z (-1.0 .. 1.0) */ } Vector3D; @@ -20,27 +20,28 @@ * Calculate the cross product of two vectors. Puts * cross product of v1 and v2 into out and returns it. */ -void vector3d_cross(Vector3D *out, const Vector3D *v1, const Vector3D *v2); +extern void vector3d_cross(Vector3D *out, const Vector3D *v1, + const Vector3D *v2); /* * Checks equality of two vectors. */ -bool vector3d_eq(const Vector3D *a, const Vector3D *b); +extern bool vector3d_eq(const Vector3D *a, const Vector3D *b); /* * Calculate the scalar product of two vectors. */ -float8 vector3d_scalar(Vector3D *v1, Vector3D *v2); +extern float8 vector3d_scalar(Vector3D *v1, Vector3D *v2); /* * Calculate the length of a vector. */ -float8 vector3d_length(const Vector3D *v); +extern float8 vector3d_length(const Vector3D *v); -/* - * Calculate result + scalar*delta +/* + * Calculate result + scalar*delta */ -void vector3d_addwithscalar( - Vector3D *result, double scalar, const Vector3D *delta); +extern void vector3d_addwithscalar(Vector3D *result, double scalar, + const Vector3D *delta); #endif diff -Nru pgsphere-1.4.2/upgrade_scripts/pg_sphere--1.4.2--1.5.0.sql.in pgsphere-1.5.1/upgrade_scripts/pg_sphere--1.4.2--1.5.0.sql.in --- pgsphere-1.4.2/upgrade_scripts/pg_sphere--1.4.2--1.5.0.sql.in 1970-01-01 00:00:00.000000000 +0000 +++ pgsphere-1.5.1/upgrade_scripts/pg_sphere--1.4.2--1.5.0.sql.in 2024-04-22 06:22:05.000000000 +0000 @@ -0,0 +1,21 @@ +-- Upgrade: 1.4.2 -> 1.5.0 + +CREATE OR REPLACE FUNCTION g_spoint_distance(internal, spoint, smallint, oid, internal) + RETURNS internal + AS 'MODULE_PATHNAME', 'g_spoint_distance' + LANGUAGE 'c'; + +DO $$ +BEGIN + ALTER OPERATOR FAMILY spoint USING gist ADD + FUNCTION 8 (spoint, spoint) g_spoint_distance (internal, spoint, smallint, oid, internal); +EXCEPTION + WHEN duplicate_object THEN NULL; + WHEN OTHERS THEN RAISE; +END; +$$; + +CREATE FUNCTION reset_sphere_output_precision() + RETURNS CSTRING + AS 'MODULE_PATHNAME', 'reset_sphere_output_precision' + LANGUAGE 'c'; diff -Nru pgsphere-1.4.2/upgrade_scripts/pg_sphere--1.5.0--1.5.1.sql.in pgsphere-1.5.1/upgrade_scripts/pg_sphere--1.5.0--1.5.1.sql.in --- pgsphere-1.4.2/upgrade_scripts/pg_sphere--1.5.0--1.5.1.sql.in 1970-01-01 00:00:00.000000000 +0000 +++ pgsphere-1.5.1/upgrade_scripts/pg_sphere--1.5.0--1.5.1.sql.in 2024-04-22 06:22:05.000000000 +0000 @@ -0,0 +1,11 @@ +-- Upgrade: 1.5.0 -> 1.5.1 + +DO $$ +BEGIN + ALTER OPERATOR FAMILY spoint USING gist ADD + OPERATOR 17 <-> (spoint, spoint) FOR ORDER BY float_ops; +EXCEPTION + WHEN duplicate_object THEN NULL; + WHEN OTHERS THEN RAISE; +END; +$$;