-
Notifications
You must be signed in to change notification settings - Fork 477
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
c: fix "a", revert to 2-iter exact #55
base: master
Are you sure you want to change the base?
Conversation
Commits cd7a6a4 killed the 2-iter exact algo. This commit brings it back.
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.
Changes are all non-breaking. and should provide a significant improvement in performance.
c/transform.c
Outdated
@@ -24,26 +24,26 @@ INLINE static int outOfChina(double lat, double lng) { | |||
return 0; | |||
} | |||
|
|||
#define EARTH_R 6378137.0 | |||
#define EARTH_R 6371000 | |||
|
|||
void transform(double x, double y, double *lat, double *lng) { | |||
double xy = x * y; | |||
double absX = sqrt(fabs(x)); |
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.
better name for this should be sqrtX not absX
c/transform.c
Outdated
pLng = gcjLng + dLng; | ||
double dLat, dLng; | ||
// n_iter=2: centimeter precision, n_iter=5: double precision | ||
const int n_iter = 2; |
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.
If your going to drop the threshold check I suggest 3 or 4 iterations not just 2 as my tests showed that to get to the right precision most times, I iterated 3 times.
for (i = 0; i < n_iter; i++) { | ||
delta(*wgsLat, *wgsLng, &dLat, &dLng); | ||
*wgsLat = gcjLat - dLat; | ||
*wgsLng = gcjLng - dLng; | ||
} |
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 I'm glad to see this method changed as it's so much faster.
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.
Side note... It would be really nice to see consistency between versions and variable names. X_Pi,xPi,yPi,MPi.....
and consistent definitions across implementations mPi = 3000Pi/180; xPi = xmPi for example..
exact transform implemented via cajun method everywhere... or left as half distance method, and mars2wgs as cajin. Just so long as it's all consistent.
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 C impl is actually the first instance where a caijun-esque method is introduced to eviltransform. Like I said in the PR, it's ditched in an "optimize" commit, the only productive part of which is fixing a "fabs" declaraction.
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.
And yeah the whole varname thing is crazy. We probably don't even need all those, as many of them like x*pi
and sqrt(fabs(x))
are really subexpression optimizations that can be done automatically by the compiler as long as you allow it to do associative math on floats.
Yeah, right, good call -- let me think really hard about putting some pragmas to tell the compilers…
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 like defining subexpressions or constants that otherwise would be recalculated multiple times later , to limit the clock cycles needed for repetitive calculations. I just like to see consistent naming.
Quite frankly I would like to see these all dealt with in some -fassociative-math pragma
Commits cd7a6a4 killed the 2-iter exact algo. This commit brings it back.