[Proj] Code style in Proj
Kurt Schwehr
schwehr at gmail.com
Sat Apr 21 15:46:22 PDT 2018
Hi all,
I've been thinking about what is possible with the Proj code base with an
assumption that the code must be C89/C90 compatible. I played around for a
few in godbolt with PJ_august.c (because it's small) and ended up with
this. I tried to be aggressive as I could. I think my modified version is
likely to be more static analyzer friendly. What do you all think? For
each of the change, is it better or worse for Proj as a whole? My brain is
set to C++14/17, so I have a hard time evaluating this in context of what's
best for Proj in the long run.
Original: https://godbolt.org/g/ci5Wfo
Modified: https://godbolt.org/g/mz6NjD
Things I did:
- Combine definition and declaration
- Add const
- For double literals, have at least one digit before and after decimal
point. e.g. .1 -> 0.1 and 3. -> 3.0
- Don't have assignments hidden inside expressions
- Convert #defines to typed const values
- IWYU - Include what you use... here math.h
Cheers,
-kurt
#include <math.h>
typedef struct { double x, y; } XY;
typedef struct { double lam, phi; } LP;
typedef struct PJconsts PJ;
XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
(void) P;
const double t = tan(0.5 * lp.phi);
const double c1 = sqrt(1.0 - t * t);
const double c = 1.0 + c1 * cos(lp.lam *= .5);
const double x1 = sin(lp.lam) * c1 / c;
const double y1 = t / c;
const double x12 = x1 * x1;
const double y12 = y1 * y1;
const double M = 1.333333333333333;
const XY xy = {
M * x1 * (3.0 + x12 - 3.0 * y12),
M * y1 * (3.0 + 3.0 * x12 - y12)};
return xy;
}
Screenshot: https://www.flickr.com/photos/schwehr/39802222790
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/proj/attachments/20180421/e697f619/attachment.html>
More information about the Proj
mailing list