postgrespro / pgsphere

PgSphere provides spherical data types, functions, operators, and indexing for PostgreSQL.
https://pgsphere.org
BSD 3-Clause "New" or "Revised" License
16 stars 15 forks source link

Add gravity center function #29

Closed dura0ok closed 11 months ago

esabol commented 11 months ago

This constitutes an API change, so the version number will need to be incremented in some fashion. I'm not sure if that's been decided in issue #9 yet. An upgrade script will also be needed.

make test failed. You'll need to update expected/init_test.out.in at least.

make installcheck also failed with most of the tested PostgreSQL versions but not version 10. That's weird. Not sure why that is.

diff -U3 /home/travis/build/postgrespro/pgsphere/expected/points.out /home/travis/build/postgrespro/pgsphere/results/points.out
--- /home/travis/build/postgrespro/pgsphere/expected/points.out 2023-07-13 05:23:20.880316866 +0000
+++ /home/travis/build/postgrespro/pgsphere/results/points.out  2023-07-13 05:24:27.069036698 +0000
@@ -393,7 +393,7 @@
 ]);
     get_gravity_center    
 --------------------------
- (3.0436698 , 0.85893807)
+ (3.0436698 , -1.5707963)
 (1 row)
esabol commented 11 months ago

I'd like to see additional tests added: a test with only one spoint in the passed ARRAY and a test with zero spoints in the passed ARRAY.

vitcpp commented 11 months ago

I would propose to name it as 'centroid'. It is more laconic name. Boost geometry names such function as centroid.

Furthermore, we may overload such function for other geometry types to make it complete.

I would also propose to put test SQL for this functionality into a new file like centroid.sql, for example. Such a file separation is reasonable, because all the stuff related to this function will be placed in the single file. If we add some other overloaded functions like centroid(spoly) we will still have the single test file. The test code will not be placed into multiple files.

vitcpp commented 11 months ago

I also would consider the case when two points are located in the same big circle in opposite directions. The 3D center mass in this case reside in the center of the sphere. There are two points may be returned. Which point to choose?

vitcpp commented 11 months ago

Closed until it will be polished in the author's original branch.