-
Notifications
You must be signed in to change notification settings - Fork 15
Add gravity center function #29
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
Conversation
src/point.c
Outdated
spoint_check(p); | ||
|
||
PG_RETURN_POINTER(p); | ||
} |
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.
An EOL character is needed at the end of this file.
src/point.c
Outdated
|
||
for (int i = 0; i < num_elements; i++) { | ||
current_point = array_data[i]; | ||
//elog(LOG, "%lf\n", current_point.lat); |
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 remove this line of code that has been commented out.
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 also propose to move 'int i' declaration to the function beginning. Standard C doesn't allow to declare types such the way.
src/point.c
Outdated
elog(LOG, "%lf\n", v.x); | ||
res.x+=v.x; | ||
res.y+=v.y; | ||
res.z+=v.z; |
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.
Add a space on both sides of the +=
operator on lines 289, 290, and 291.
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, I think res.x
, res.y
, and res.z
need to be initialized to zeroes before the for
loop? This might explain the test failures seen on some PostgreSQL versions.
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.
What happens if num_elements
is zero, i.e. if the ARRAY passed to the function is empty? I think it should give an error or return NULL perhaps?
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 think that the gravity center point (centroid) should be on the sphere in 2D space because pgsphere is about 2D space on the sphere. I'm not sure that the average point in 3d space will be on the sphere. May be to to average long/lat coordinates.
src/point.h
Outdated
/* | ||
* Return gravity center from array of spherical points | ||
*/ | ||
Datum get_gravity_center(PG_FUNCTION_ARGS); |
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 whitespace after Datum
probably should be the same as on lines 91 and 86.
pgs_point.sql.in
Outdated
@@ -167,3 +167,8 @@ CREATE OPERATOR <-> ( | |||
COMMENT ON OPERATOR <-> (spoint, spoint) IS | |||
'distance between spherical points'; | |||
|
|||
CREATE FUNCTION get_gravity_center(dots_vector SPoint[]) |
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.
My initial reaction is that the function should be called gravity_center
instead of get_gravity_center
. I could be wrong about that though. Is there a convention or precedent for how functions should be named?
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 to name it 'centroid'. For example, BOOST.Geometry names such function as centroid.
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.
|
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. |
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. |
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? |
* some little fixes * some little fixes * fix tests * tests * tests * reset * .. * .. * fix tests * fix tests * curr * logs * logs * logs * logs * logs * logs * logs * logs * logs * logs * logs * logs * logs * logs * logs * logs * logs * logs * logs * logs * tryings * tryings * tryings * tryings * tryings * tryings * tryings * tryings * tryings * tryings * tryings * tryings * tryings * tryings * try to make unit test * current state * tryings * tryings * current state * current state * current state * current state * tryings
@@ -86,7 +86,7 @@ | |||
the <literal>y</literal>-axis. | |||
</simpara> | |||
<programlisting> | |||
<![CDATA[sql> SELECT strans ( 20.0*pi()/180.0, -270.0*pi()/180.0, 70.5*pi()/180.0, 'XZY');]]> |
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.
pi() call was removed from the formula. I guess it is a typo in the doc.
Closed until it will be polished in the author's original branch. |
No description provided.