-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add spoly(spoint[]) constructor function #99
Add spoly(spoint[]) constructor function #99
Conversation
After merge of #96, I will update the docs. |
pgs_polygon.sql.in
Outdated
IMMUTABLE STRICT PARALLEL SAFE; | ||
|
||
COMMENT ON FUNCTION spoly(spoint[]) IS | ||
'Create spoly from an array of points.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment should be creates spoly from an array of points
(no capitalization, no period, and "creates" not "create") in order to match the other comments on the other functions.
pgs_polygon.sql.in
Outdated
'Create spoly from array of points. | ||
Two consecutive numbers among those present | ||
refer to the same occurrence and cover its | ||
latitude and longitude, respectively.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/polygon.c
Outdated
ArrayType *inarr = PG_GETARG_ARRAYTYPE_P(0); | ||
SPoint *points; | ||
|
||
np = ArrayGetNItems(ARR_NDIM(inarr), ARR_DIMS(inarr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose combining this line with line 957 and just making it
int np = ArrayGetNItems(ARR_NDIM(inarr), ARR_DIMS(inarr));
@@ -60,7 +60,7 @@ PG_FUNCTION_INFO_V1(spheretrans_poly_inverse); | |||
PG_FUNCTION_INFO_V1(spherepoly_add_point); | |||
PG_FUNCTION_INFO_V1(spherepoly_add_points_finalize); | |||
PG_FUNCTION_INFO_V1(spherepoly_is_convex); | |||
|
|||
PG_FUNCTION_INFO_V1(spherepoly_from_point_array); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering why you didn't add this new function to polygon.h? I did in PR #96 and am wondering if I shouldn't have?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@esabol Function declaration in a header is needed when you use this function in another translation unit (.c file). You just include this header with function declarations to be able to use these functions without any compiler warnings. The spherepoly_from_point_array function is an interface function that is searched (ldsym) and called by postgresql. It is not used in other .c sources. Once, some other functions are defined in .h file, I will add the declaration.
Furthermore, pgindent requires "extern" modificator for functions declarations. I have some plans to use pgindent to reformat .h files to satisfy the postgresql coding style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vitcpp wrote:
Function declaration in a header is needed when you use this function in another translation unit (.c file).
Uh, yeah. I've been a professional C developer for over 28 years. I know what .h
files are used for.
In my C projects, I put the prototype for every function in its corresponding .h
file. The only times I don't are when I'm working on an API library and I need to be concerned about which functions are in the public API and which are meant only to be used internally. And even then I'd probably create a separate internal-only .h
file for the prototypes of internal functions. Anyway, that's just my development philosophy, I guess. Apparently, you have a different philosophy, and that's fine.
Basically, I just want to know if I should remove the prototype for spherepoly_deg
that I added to src/polygon.h
in PR #96. It sounds like I should!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@esabol I'm sorry, I have no any intentions to teach anyone. I just wanted to clearly describe my position. My bad, a bucket with apples from me! :)
I agree with you to put the function declaration into .h file in pgsphere to follow the pgsphere code style. All other API functions are declared in .h files. I would also propose to add extern, but not in this PR. Pgindent will properly apply formatting to function declarations if it sees the extern keyword.
I will rebase and update my PR in according with your comments after the merge of #96.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, cool.
IMMUTABLE STRICT PARALLEL SAFE; | ||
|
||
COMMENT ON FUNCTION spoly(spoint[]) IS | ||
'Create spoly from an array of points.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change comment to creates spoly from an array of points
(no capitalization, no period, and "creates" not "create") in order to match the other comments on the other functions.
sql/poly.sql
Outdated
|
||
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)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Change "10,10" to "10, 10".
sql/poly.sql
Outdated
|
||
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)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Change "10,10" to "10, 10".
src/polygon.c
Outdated
|
||
if (np < 3) | ||
{ | ||
elog(ERROR, "spoly_deg: invalid number of arguments (must be >= 3)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change "spoly_deg" to "spoly" (or "spherepoly_from_point_array"?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would propose to use the SQL function name but I'm not sure how to get the name from function arguments. Furthermore, such change should be done for other functions as well.
I would propose to use the func (C99) or FUNCTION macro but not sure that MSVC supports it. Lets keep the old approach now.
src/polygon.c
Outdated
|
||
if (ARR_HASNULL(inarr)) | ||
{ | ||
elog(ERROR, "spoly_deg: input array is invalid because if has null values"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change "spoly_deg" to "spoly" (or "spherepoly_from_point_array"?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please change "because if" to "because it" in this error message.
34132d3
to
ce73075
Compare
Rebased, fixed problems after the review. The second commit will be squashed after completing the review. |
ce73075
to
595ecc9
Compare
I updated the doc with the simple description of spoly and spoly_deg function. I used another approach to describe the functions to demonstrate some other approaches to describe functions. I didn't use funcsynopsis which is not suitable for describing SQL functions (funcsynopsis is for languages like C). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! Thank you so much for this contribution, @vitcpp !
No description provided.