Skip to content

Add spoly_is_convex #43

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

Merged
merged 1 commit into from
Aug 12, 2023
Merged

Add spoly_is_convex #43

merged 1 commit into from
Aug 12, 2023

Conversation

ggnmstr
Copy link
Contributor

@ggnmstr ggnmstr commented Aug 2, 2023

Adds function to determine whether the spoly is convex.
Algorithm based on
https://mathoverflow.net/questions/193569/determining-orientation-of-spherical-polygons

@ggnmstr ggnmstr force-pushed the poly_convex branch 2 times, most recently from d89edcf to a0be9d3 Compare August 3, 2023 09:40
Copy link
Contributor

@vitcpp vitcpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general everything is ok except of some trivial issues.

@vitcpp
Copy link
Contributor

vitcpp commented Aug 3, 2023

@ggnmstr thank you for the PR. I think everything is ok except of some trivial issues. The tests should be fixed - could you please try to run tests without healpix:

  • gmake USE_HEALPIX=0 install
  • gmake USE_HEALPIX=0 test

I would also ask to start the commit comment from capital lettet as it was done for other commits.

@ggnmstr ggnmstr force-pushed the poly_convex branch 3 times, most recently from b61c748 to 5d264e6 Compare August 4, 2023 03:59
@dura0ok
Copy link

dura0ok commented Aug 4, 2023

fix_tests.patch
Please @ggnmstr rename it to .patch extension and apply it! This fix your tests!!

@ggnmstr
Copy link
Contributor Author

ggnmstr commented Aug 4, 2023

@stepan-neretin7 Thank you, it works, seems like there's a problem with healpix on my computer.

@ggnmstr ggnmstr requested a review from vitcpp August 4, 2023 05:49
@dura0ok
Copy link

dura0ok commented Aug 4, 2023

@ggnmstr please, start commit with capital letter

@esabol
Copy link
Contributor

esabol commented Aug 4, 2023

@stepan-neretin7 wrote:

@ggnmstr please, start commit with capital letter

Do you mean the title of the pull request, @stepan-neretin7 ? The one commit message at https://github.com/postgrespro/pgsphere/pull/43/commits does start with a capital letter.

@dura0ok
Copy link

dura0ok commented Aug 4, 2023

@stepan-neretin7 wrote:

@ggnmstr please, start commit with capital letter

Do you mean the title of the pull request, @stepan-neretin7 ? The one commit message at https://github.com/postgrespro/pgsphere/pull/43/commits does start with a capital letter.

Yes, I think it's a good idea. I also suggest that you also specify the issue number in the comment, so that he automatically linked it to the desired issue even before the merge.

@ggnmstr ggnmstr changed the title add spoly_is_convex Add spoly_is_convex Aug 5, 2023
@vitcpp
Copy link
Contributor

vitcpp commented Aug 5, 2023

@ggnmstr There are some conflicts. Could you please do rebase on the newest version and fix the conflicts?

@esabol
Copy link
Contributor

esabol commented Aug 5, 2023

@ggnmstr: CI failures. Please check and fix "make test" results.

https://app.travis-ci.com/github/postgrespro/pgsphere/jobs/607409643

@ggnmstr ggnmstr force-pushed the poly_convex branch 3 times, most recently from 544f4f6 to 4570340 Compare August 6, 2023 04:32
psql:pg_sphere.test.sql:8594: NOTICE: argument type pointkey is only a shell
psql:pg_sphere.test.sql:8600: NOTICE: argument type pointkey is only a shell
psql:pg_sphere.test.sql:9167: NOTICE: return type smoc is only a shell
psql:pg_sphere.test.sql:9173: NOTICE: argument type smoc is only a shell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add linefeed to the end of this file.

psql:pg_sphere.test.sql:9181: NOTICE: return type smoc is only a shell
psql:pg_sphere.test.sql:9187: NOTICE: argument type smoc is only a shell
psql:pg_sphere.test.sql:9167: NOTICE: return type smoc is only a shell
psql:pg_sphere.test.sql:9173: NOTICE: argument type smoc is only a shell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a linefeed to the end of this file.

@ggnmstr ggnmstr force-pushed the poly_convex branch 5 times, most recently from 2620fa7 to a35e842 Compare August 6, 2023 07:22
psql:pg_sphere.test.sql:9181: NOTICE: return type smoc is only a shell
psql:pg_sphere.test.sql:9187: NOTICE: argument type smoc is only a shell
psql:pg_sphere.test.sql:9167: NOTICE: return type smoc is only a shell
psql:pg_sphere.test.sql:9173: NOTICE: argument type smoc is only a shell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are almost there! Change "9167" to "9195" on line 1. Change "9173" to "9201" on line 2.

esabol

This comment was marked as outdated.

@vitcpp
Copy link
Contributor

vitcpp commented Aug 7, 2023

To finalize PR the following changes are required:

  • Update pg_sphere--1.2.3--1.3.0.sql. Add command to create the implemented function.
  • Add new function description into Functions -> spoly functions section of the User Manual (gmake pdf).

@ggnmstr
Copy link
Contributor Author

ggnmstr commented Aug 8, 2023

@stepan-neretin7, this "return null" behavior is common among all functions, I don't think it is possible to change something just in place.

@dura0ok
Copy link

dura0ok commented Aug 8, 2023

@stepan-neretin7, this "return null" behavior is common among all functions, I don't think it is possible to change something just in place.

but in your code you return false.. Very strange for me..

Copy link
Contributor

@esabol esabol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more minor tweaks, please, @ggnmstr. Thank you!

src/polygon.c Outdated
wsv,
crs;
float8 cur = 0,
prev = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the variables on lines 1487-1493 line up vertically for you? They don't line up vertically in the diff output here on GitHub.com.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default tab size on github is 8. It can be changes to 4 in Profile -> Settings -> Appearance -> Tab size... Not sure, how to change it for a specific repository and specific file type.

I changed it. For me it looks like this:

image

src/polygon.h Outdated
/*
* Checks whether a polygon is convex
*/
Datum spherepoly_is_convex(PG_FUNCTION_ARGS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces after Datum so that spherepoly_is_convex lines up vertically with the names of the functions above this.

Spoly is convex
</title>
<para>
Returns true if the specified spherical polygon is convex. Returns false otherwise.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line longer than 79 characters? I can't tell looking at it in the web browser here. If it is, please word-wrap it.

@ggnmstr ggnmstr force-pushed the poly_convex branch 3 times, most recently from ff10fe4 to e740d2c Compare August 8, 2023 06:04
@vitcpp
Copy link
Contributor

vitcpp commented Aug 8, 2023

SELECT spoly_is_convex(NULL);

spoly_is_convex
(1 row)

why you return null? is this correct for interface?

I agree, it should return false. The third value is unnecessary. To fix it STRICT keyword should be removed in CREATE FUNCTION command. I also propose to update the tests by adding this case.

@ggnmstr
Copy link
Contributor Author

ggnmstr commented Aug 8, 2023

@vitcpp. I fixed it and added a test, thanks for the information.

@dura0ok
Copy link

dura0ok commented Aug 8, 2023

for (int i = 0; i < poly->npts; i++)
please move the variable initialization to the top of the function
@ggnmstr

Copy link
Contributor

@vitcpp vitcpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spherepoly_is_convex() functions seems to be ok as the first working version, but the code is not optimized. There are duplicate calculations in the for loop that can slowdown the performance.

@vitcpp
Copy link
Contributor

vitcpp commented Aug 9, 2023

There are some conflicts that should be resolved. @ggnmstr Could you please rebase your branch to the latest postgrespro/pgsphere version and fix conflicts?

@ggnmstr
Copy link
Contributor Author

ggnmstr commented Aug 9, 2023

spherepoly_is_convex() functions seems to be ok as the first working version, but the code is not optimized. There are duplicate calculations in the for loop that can slowdown the performance.

Yes, I agree with that. I think I'll optimize it a bit later.

@@ -28,6 +28,7 @@ COMMENT ON FUNCTION spoly_deg(float8[]) IS
refer to the same occurrence and cover its
latitude and longitude, respectively.';

<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the line

Copy link
Contributor

@esabol esabol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to get make test working.

@@ -33,3 +33,4 @@ psql:pg_sphere.test.sql:8622: NOTICE: argument type pointkey is only a shell
psql:pg_sphere.test.sql:8628: NOTICE: argument type pointkey is only a shell
psql:pg_sphere.test.sql:8634: NOTICE: argument type pointkey is only a shell
psql:pg_sphere.test.sql:8640: NOTICE: argument type pointkey is only a shell

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add this blank line? I think it should be removed.

Take a look at the diff output at the bottom of the log here:
https://app.travis-ci.com/github/postgrespro/pgsphere/jobs/607714835

You need to change the line numbers in this file to match the results so that there are no differences.

@@ -1,2 +1,3 @@
psql:pg_sphere.test.sql:9207: NOTICE: return type smoc is only a shell
psql:pg_sphere.test.sql:9213: NOTICE: argument type smoc is only a shell

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this blank line. In this file, change "9207" to "9221" and change "9213" to "9227".

@ggnmstr ggnmstr force-pushed the poly_convex branch 2 times, most recently from 006ad50 to e642169 Compare August 11, 2023 15:35
Copy link
Contributor

@esabol esabol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thank you for your contribution and perseverance, @ggnmstr!

@vitcpp
Copy link
Contributor

vitcpp commented Aug 11, 2023

@ggnmstr Thank you for your contribution. I plan to merge PR #40 first, your PR will be the next. I guess, new differences may appear - one more iteration may be required to fix the tests. It seems to be a problem of init_test that should be redesigned in the future.

@vitcpp
Copy link
Contributor

vitcpp commented Aug 11, 2023

@ggnmstr Could you please do one more iteration - re-sync your branch with this repo, resolve conflicts and force-push your changes? Your PR will be the next. Thank you in advance!

@ggnmstr
Copy link
Contributor Author

ggnmstr commented Aug 12, 2023

@vitcpp, Ok, I did it. The tests are OK, I guess, I just realized that I was typing "HEAPLIX" all the time and then wondering why is it not working on my PC

@vitcpp
Copy link
Contributor

vitcpp commented Aug 12, 2023

@ggnmstr Thank you very much!

@vitcpp vitcpp merged commit 6720f3a into postgrespro:master Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants