Skip to content

Commit

Permalink
Fix found problems after review
Browse files Browse the repository at this point in the history
  • Loading branch information
vitcpp committed Nov 3, 2023
1 parent 9d5fa49 commit ce73075
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
10 changes: 5 additions & 5 deletions expected/poly.out
Original file line number Diff line number Diff line change
Expand Up @@ -350,18 +350,18 @@ SELECT spoly(NULL::spoint[]);
(1 row)

SELECT spoly(ARRAY[]::spoint[]);
ERROR: spoly_deg: invalid number of arguments (must be >= 3)
ERROR: spherepoly_from_point_array: invalid number of arguments (must be >= 3)
SELECT spoly(ARRAY[spoint_deg(0, 0)]);
ERROR: spoly_deg: invalid number of arguments (must be >= 3)
ERROR: spherepoly_from_point_array: invalid number of arguments (must be >= 3)
SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0)]);
ERROR: spoly_deg: invalid number of arguments (must be >= 3)
SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0), spoint_deg(10,10)]);
ERROR: spherepoly_from_point_array: invalid number of arguments (must be >= 3)
SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0), spoint_deg(10, 10)]);
spoly
------------------------------------
{(0d , 0d),(10d , 0d),(10d , 10d)}
(1 row)

SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0), spoint_deg(10,10), spoint_deg(0, 10)]);
SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0), spoint_deg(10, 10), spoint_deg(0, 10)]);
spoly
-----------------------------------------------
{(0d , 0d),(10d , 0d),(10d , 10d),(0d , 10d)}
Expand Down
4 changes: 2 additions & 2 deletions sql/poly.sql
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ SELECT spoly(ARRAY[spoint_deg(0, 0)]);

SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0)]);

SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0), spoint_deg(10,10)]);
SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0), spoint_deg(10, 10)]);

SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0), spoint_deg(10,10), spoint_deg(0, 10)]);
SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0), spoint_deg(10, 10), spoint_deg(0, 10)]);

--- incorrect input -----

Expand Down
12 changes: 6 additions & 6 deletions src/polygon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,21 +1010,21 @@ spherepoly_deg(PG_FUNCTION_ARGS)
Datum
spherepoly_from_point_array(PG_FUNCTION_ARGS)
{
int np;
ArrayType *inarr = PG_GETARG_ARRAYTYPE_P(0);
SPoint *points;

np = ArrayGetNItems(ARR_NDIM(inarr), ARR_DIMS(inarr));
ArrayType *inarr = PG_GETARG_ARRAYTYPE_P(0);
const int np = ArrayGetNItems(ARR_NDIM(inarr), ARR_DIMS(inarr));

if (np < 3)
{
elog(ERROR, "spoly_deg: invalid number of arguments (must be >= 3)");
elog(ERROR, "spherepoly_from_point_array: "
"invalid number of arguments (must be >= 3)");
PG_RETURN_NULL();
}

if (ARR_HASNULL(inarr))
{
elog(ERROR, "spoly_deg: input array is invalid because if has null values");
elog(ERROR, "spherepoly_from_point_array: "
"input array is invalid because it has null values");
PG_RETURN_NULL();
}

Expand Down
11 changes: 9 additions & 2 deletions src/polygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,22 @@ Datum spherepoly_get_point(PG_FUNCTION_ARGS);
int8 poly_line_pos(const SPOLY *poly, const SLine *line);

/*
* Input of a spherical from array of pair-consecutive numbers (lng, lat), in radians.
* Create a spherical polygon (spoly) from an array of pair-consecutive
* numbers (lng, lat), in radians.
*/
Datum spherepoly_rad(PG_FUNCTION_ARGS);

/*
* Input of a spherical from array of pair-consecutive numbers (lng, lat), in degrees.
* Create a spherical polygon (spoly) from an array of pair-consecutive
* numbers (lng, lat), in degrees.
*/
Datum spherepoly_deg(PG_FUNCTION_ARGS);

/*
* Create a spherical polygon (spoly) from an array of spoint elements.
*/
Datum spherepoly_from_point_array(PG_FUNCTION_ARGS);

/*
* Input of a spherical polygon.
*/
Expand Down

0 comments on commit ce73075

Please sign in to comment.