PIString and PIChar fixes 4

This commit is contained in:
Andrey
2022-03-25 15:10:29 +03:00
parent 7dee8f6313
commit 4c7df57e66
3 changed files with 27 additions and 28 deletions

View File

@@ -339,7 +339,7 @@ PIChar PIChar::toUpper() const {
UChar c(0);
UErrorCode e((UErrorCode)0);
u_strToUpper(&c, 1, (const UChar*)(&ch), 1, 0, &e);
return PIChar(c);
return PIChar((ushort)c);
#else
# ifdef WINDOWS
ushort wc = 0;
@@ -357,7 +357,7 @@ PIChar PIChar::toLower() const {
UChar c(0);
UErrorCode e((UErrorCode)0);
u_strToLower(&c, 1, (const UChar*)(&ch), 1, 0, &e);
return PIChar(c);
return PIChar((ushort)c);
#else
# ifdef WINDOWS
ushort wc = 0;

View File

@@ -263,12 +263,12 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
UChar * ucs = new UChar[s];
memset(ucs, 0, s * sizeof(UChar));
e = (UErrorCode)0;
int sz = ucnv_toUChars(cc, ucs, s, c, s, &e);
sz = ucnv_toUChars(cc, ucs, s, c, s, &e);
//printf("appendFromChars %d -> %d\n", s, sz);
//printf("PIString %d -> %d\n", c[0], ucs[0]);
reserve(size_s() + sz);
for (int i = 0; i < sz; ++i) {
push_back(PIChar(ucs[i]));
push_back(PIChar((ushort)ucs[i]));
}
delete[] ucs;
ucnv_close(cc);

View File

@@ -251,10 +251,10 @@ PIGeoPosition &PIGeoPosition::setECEF(double x, double y, double z) {
void PIGeoPosition::convertSphericalToCartesian(const PIMathVectorT3d &tpr, PIMathVectorT3d &xyz) {
double st = sin(tpr[0] * deg2rad);
xyz[0] = tpr[2] * st * cos(tpr[1] * deg2rad);
xyz[1] = tpr[2] * st * sin(tpr[1] * deg2rad);
xyz[2] = tpr[2] * cos(tpr[0] * deg2rad);
double st = sin(toRad(tpr[0]));
xyz[0] = tpr[2] * st * cos(toRad(tpr[1]));
xyz[1] = tpr[2] * st * sin(toRad(tpr[1]));
xyz[2] = tpr[2] * cos(toRad(tpr[0]));
}
@@ -303,11 +303,11 @@ void PIGeoPosition::convertCartesianToGeodetic(const PIMathVectorT3d &xyz, PIMat
void PIGeoPosition::convertGeodeticToCartesian(const PIMathVectorT3d &llh, PIMathVectorT3d &xyz, PIEllipsoidModel ell) {
double slat = sin(llh[0] * deg2rad);
double clat = cos(llh[0] * deg2rad);
double slat = sin(toRad(llh[0]));
double clat = cos(toRad(llh[0]));
double nn = ell.a / sqrt(1.0 - ell.eccSquared() * slat * slat);
xyz[0] = (nn + llh[2]) * clat * cos(llh[1] * deg2rad);
xyz[1] = (nn + llh[2]) * clat * sin(llh[1] * deg2rad);
xyz[0] = (nn + llh[2]) * clat * cos(toRad(llh[1]));
xyz[1] = (nn + llh[2]) * clat * sin(toRad(llh[1]));
xyz[2] = (nn * (1.0 - ell.eccSquared()) + llh[2]) * slat;
}
@@ -328,8 +328,8 @@ void PIGeoPosition::convertGeocentricToCartesian(const PIMathVectorT3d &llr, PIM
void PIGeoPosition::convertGeocentricToGeodetic(const PIMathVectorT3d &llr, PIMathVectorT3d &llh, PIEllipsoidModel ell) {
double cl, p, sl, slat, nn, htold, latold;
llh[1] = llr[1]; // longitude is unchanged
cl = sin((90.0 - llr[0]) * deg2rad);
sl = cos((90.0 - llr[0]) * deg2rad);
cl = sin(toRad(90.0 - llr[0]));
sl = cos(toRad(90.0 - llr[0]));
if(llr[2] <= PIGeoPosition::position_tolerance / 5) { // radius is below tolerance, hence assign zero-length, arbitrarily set latitude = longitude = 0
llh[0] = llh[1] = 0.0;
llh[2] = -ell.a;
@@ -358,7 +358,7 @@ void PIGeoPosition::convertGeocentricToGeodetic(const PIMathVectorT3d &llr, PIMa
void PIGeoPosition::convertGeodeticToGeocentric(const PIMathVectorT3d &llh, PIMathVectorT3d &llr, PIEllipsoidModel ell) {
double slat = sin(llh[0] * deg2rad);
double slat = sin(toRad(llh[0]));
double nn = ell.a / sqrt(1.0 - ell.eccSquared() * slat * slat);
llr[1] = llh[1]; // longitude is unchanged
llr[2] = sqrt((nn+llh[2])*(nn+llh[2]) + nn*ell.eccSquared()*(nn*ell.eccSquared()-2*(nn+llh[2]))*slat*slat); // radius
@@ -379,7 +379,7 @@ void PIGeoPosition::convertGeodeticToGeocentric(const PIMathVectorT3d &llh, PIMa
double PIGeoPosition::radiusEarth(double geolat, PIEllipsoidModel ell) {
double slat = sin(geolat * deg2rad);
double slat = sin(toRad(geolat));
double e = (1.0 - ell.eccSquared());
double f = (1.0 + (e * e - 1.0) * slat * slat) / (1.0 - ell.eccSquared() * slat * slat);
return (ell.a * sqrt(f));
@@ -462,8 +462,8 @@ double PIGeoPosition::elevation(const PIGeoPosition &p) const {
double PIGeoPosition::elevationGeodetic(const PIGeoPosition &p) const {
PIGeoPosition r(*this), s(p);
double lat = r.latitudeGeodetic() * deg2rad;
double lng = r.longitude() * deg2rad;
double lat = toRad(r.latitudeGeodetic());
double lng = toRad(r.longitude());
double local_up;
double cos_up;
r.transformTo(Cartesian);
@@ -476,7 +476,7 @@ double PIGeoPosition::elevationGeodetic(const PIGeoPosition &p) const {
kv[2] = sin(lat);
local_up = z.dot(kv); // Take advantage of dot method to get Up coordinate in local NEU system
cos_up = local_up / z.length(); // Let's get cos(z), being z the angle with respect to local vertical (Up);
return 90.0 - ((acos(cos_up)) * rad2deg);
return 90.0 - toDeg(acos(cos_up));
}
@@ -485,7 +485,7 @@ double PIGeoPosition::azimuth(const PIGeoPosition &p) const {
r.transformTo(Cartesian);
s.transformTo(Cartesian);
double xy, xyz, cosl, sinl, sint, xn1, xn2, xn3, xe1, xe2;
double z1, z2, z3, p1, p2, test, alpha;
double z1, z2, z3, p1, p2, alpha;
xy = r[0] * r[0] + r[1] * r[1];
xyz = xy + r[2] * r[2];
xy = sqrt(xy);
@@ -504,9 +504,8 @@ double PIGeoPosition::azimuth(const PIGeoPosition &p) const {
z3 = s[2] - r[2];
p1 = (xn1 * z1) + (xn2 * z2) + (xn3 * z3) ;
p2 = (xe1 * z1) + (xe2 * z2) ;
test = piAbsd(p1) + piAbsd(p2);
assertm(test >= 1.0e-16, "azAngle(), failed p1+p2 test");
alpha = 90 - atan2(p1, p2) * rad2deg;
assertm((piAbsd(p1) + piAbsd(p2)) >= 1.0e-16, "azAngle(), failed p1+p2 test");
alpha = 90 - toDeg(atan2(p1, p2));
if (alpha < 0) return alpha + 360;
else return alpha;
}
@@ -514,8 +513,8 @@ double PIGeoPosition::azimuth(const PIGeoPosition &p) const {
double PIGeoPosition::azimuthGeodetic(const PIGeoPosition &p) const {
PIGeoPosition r(*this), s(p);
double lat = r.latitudeGeodetic() * deg2rad;
double lng = r.longitude() * deg2rad;
double lat = toRad(r.latitudeGeodetic());
double lng = toRad(r.longitude());
r.transformTo(Cartesian);
s.transformTo(Cartesian);
PIMathVectorT3d z;
@@ -533,20 +532,20 @@ double PIGeoPosition::azimuthGeodetic(const PIGeoPosition &p) const {
double local_e = z.dot(jv) / z.length(); // Now, let's use dot product to get localE unitary vector
double test = piAbsd(local_n) + piAbsd(local_e); // Let's test if computing azimuth has any sense
if (test < 1.0e-16) return 0.0; // Warning: If elevation is very close to 90 degrees, we will return azimuth = 0.0
double alpha = atan2(local_e, local_n) * rad2deg;
double alpha = toDeg(atan2(local_e, local_n));
if (alpha < 0.0) return alpha + 360.0;
else return alpha;
}
double PIGeoPosition::getCurvMeridian() const {
double slat = sin(latitudeGeodetic() * deg2rad);
double slat = sin(toRad(latitudeGeodetic()));
double w = 1.0 / sqrt(1.0 - el.eccSquared() * slat * slat);
return el.a * (1.0 - el.eccSquared()) * w * w * w;
}
double PIGeoPosition::getCurvPrimeVertical() const {
double slat = sin(latitudeGeodetic() * deg2rad);
double slat = sin(toRad(latitudeGeodetic()));
return el.a / sqrt(1.0 - el.eccSquared() * slat * slat);
}