assert
This commit is contained in:
@@ -28,15 +28,6 @@
|
||||
|
||||
#include "picout.h"
|
||||
#include "piintrospection_containers.h"
|
||||
#ifdef PIP_DEBUG
|
||||
# ifdef NDEBUG
|
||||
# undef NDEBUG
|
||||
# endif
|
||||
# include <cassert>
|
||||
#endif
|
||||
#ifndef assert
|
||||
# define assert(x)
|
||||
#endif
|
||||
#ifdef MAC_OS
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
|
||||
@@ -234,6 +234,13 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool operator ==(const PIVector2D<T> & t) const {
|
||||
if (cols_ != t.cols_ || rows_ != t.rows_)
|
||||
return false;
|
||||
return mat == t.mat;
|
||||
}
|
||||
inline bool operator !=(const PIVector2D<T> & t) const {return !(*this == t);}
|
||||
|
||||
PIVector<PIVector<T> > toVectors() const {
|
||||
PIVector<PIVector<T> > ret;
|
||||
ret.reserve(rows_);
|
||||
|
||||
@@ -155,6 +155,16 @@
|
||||
extern char ** environ;
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
# undef NDEBUG
|
||||
#endif
|
||||
#include <cassert>
|
||||
#ifndef assert
|
||||
# define assert(x)
|
||||
# define assertm(exp, msg)
|
||||
#else
|
||||
# define assertm(exp, msg) assert(((void)msg, exp))
|
||||
#endif
|
||||
|
||||
#ifdef CC_GCC
|
||||
# undef DEPRECATED
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#endif
|
||||
#include <atomic>
|
||||
|
||||
|
||||
class PIMutex;
|
||||
class PIMutexLocker;
|
||||
class PIObject;
|
||||
|
||||
@@ -203,10 +203,7 @@ double PIGeoPosition::height() const {
|
||||
|
||||
|
||||
PIGeoPosition &PIGeoPosition::setGeodetic(double lat, double lon, double ht, PIEllipsoidModel ell) {
|
||||
if(lat > 90 || lat < -90) {
|
||||
piCout << "[PIGeoPosition]" << "Achtung! Invalid latitude in setGeodetic:" << lat;
|
||||
assert(lat <= 90 && lat >= -90);
|
||||
}
|
||||
assertm(lat <= 90 && lat >= -90, "Achtung! Invalid latitude in setGeodetic");
|
||||
(*this)[0] = lat;
|
||||
(*this)[1] = lon;
|
||||
if((*this)[1] < 0) (*this)[1] += 360 * (1 + (unsigned long)((*this)[1]/360));
|
||||
@@ -219,14 +216,8 @@ PIGeoPosition &PIGeoPosition::setGeodetic(double lat, double lon, double ht, PIE
|
||||
|
||||
|
||||
PIGeoPosition &PIGeoPosition::setGeocentric(double lat, double lon, double rad) {
|
||||
if(lat > 90 || lat < -90) {
|
||||
piCout << "[PIGeoPosition]" << "Achtung! Invalid latitude in setGeocentric:" << lat;
|
||||
assert(lat <= 90 && lat >= -90);
|
||||
}
|
||||
if(rad < 0) {
|
||||
piCout << "[PIGeoPosition]" << "Achtung! Invalid radius in setGeocentric:" << rad;
|
||||
assert(rad >= 0);
|
||||
}
|
||||
assertm(lat <= 90 && lat >= -90, "Achtung! Invalid latitude in setGeocentric");
|
||||
assertm(rad >= 0, "Achtung! Invalid radius in setGeocentric");
|
||||
(*this)[0] = lat;
|
||||
(*this)[1] = lon;
|
||||
(*this)[2] = rad;
|
||||
@@ -238,14 +229,8 @@ PIGeoPosition &PIGeoPosition::setGeocentric(double lat, double lon, double rad)
|
||||
|
||||
|
||||
PIGeoPosition &PIGeoPosition::setSpherical(double theta, double phi, double rad) {
|
||||
if(theta < 0 || theta > 180) {
|
||||
piCout << "[PIGeoPosition]" << "Achtung! Invalid theta in setSpherical:" << theta;
|
||||
assert(theta <= 180 && theta >= 0);
|
||||
}
|
||||
if(rad < 0) {
|
||||
piCout << "[PIGeoPosition]" << "Achtung! Invalid radius in setSpherical:" << rad;
|
||||
assert(rad >= 0);
|
||||
}
|
||||
assertm(theta <= 180 && theta >= 0, "Achtung! Invalid theta in setSpherical");
|
||||
assertm(rad >= 0, "Achtung! Invalid radius in setSpherical");
|
||||
(*this)[0] = theta;
|
||||
(*this)[1] = phi;
|
||||
(*this)[2] = rad;
|
||||
@@ -439,24 +424,15 @@ bool PIGeoPosition::operator==(const PIGeoPosition &right) const {
|
||||
void PIGeoPosition::initialize(PIMathVectorT3d v, PIGeoPosition::CoordinateSystem sys, PIEllipsoidModel ell) {
|
||||
double a(v[0]), b(v[1]), c(v[2]);
|
||||
if(sys == Geodetic || sys==Geocentric) {
|
||||
if(a > 90 || a < -90) {
|
||||
piCout << "[PIGeoPosition]" << "Achtung! Invalid latitude in constructor:" << a;
|
||||
assert(a <= 90 && a >= -90);
|
||||
}
|
||||
assertm(a <= 90 && a >= -90, "Achtung! Invalid latitude in constructor");
|
||||
if(b < 0) b += 360*(1+(unsigned long)(b/360));
|
||||
else if(b >= 360) b -= 360*(unsigned long)(b/360);
|
||||
}
|
||||
if(sys==Geocentric || sys==Spherical) {
|
||||
if(c < 0) {
|
||||
piCout << "[PIGeoPosition]" << "Achtung! Invalid radius in constructor:" << c;
|
||||
assert(c >= 0);
|
||||
}
|
||||
assertm(c >= 0, "Achtung! Invalid radius in constructor");
|
||||
}
|
||||
if(sys==Spherical) {
|
||||
if(a < 0 || a > 180) {
|
||||
piCout << "[PIGeoPosition]" << "Achtung! Invalid theta in constructor:" << a;
|
||||
assert(a >= 0 && a <= 180);
|
||||
}
|
||||
assertm(a >= 0 && a <= 180, "Achtung! Invalid theta in constructor");
|
||||
if(b < 0) b += 360*(1+(unsigned long)(b/360));
|
||||
else if(b >= 360) b -= 360*(unsigned long)(b/360);
|
||||
}
|
||||
@@ -493,10 +469,7 @@ double PIGeoPosition::elevationGeodetic(const PIGeoPosition &p) const {
|
||||
r.transformTo(Cartesian);
|
||||
s.transformTo(Cartesian);
|
||||
PIMathVectorT3d z = s - r;
|
||||
if (z.length() <= 1e-4) { // if the positions are within .1 millimeter
|
||||
piCout << "[PIGeoPosition]" << "Positions are within .1 millimeter" << z;
|
||||
assert(z.length() > 1e-4);
|
||||
}
|
||||
assertm(z.length() > 1e-4, "Positions are within .1 millimeter");
|
||||
PIMathVectorT3d kv; // Compute k vector in local North-East-Up (NEU) system
|
||||
kv[0] = cos(lat) * cos(lng);
|
||||
kv[1] = cos(lat) * sin(lng);
|
||||
@@ -517,10 +490,7 @@ double PIGeoPosition::azimuth(const PIGeoPosition &p) const {
|
||||
xyz = xy + r[2] * r[2];
|
||||
xy = sqrt(xy);
|
||||
xyz = sqrt(xyz);
|
||||
if (xy <= 1e-14 || xyz <=1e-14) {
|
||||
piCout << "[PIGeoPosition]" << "Divide by Zero Error";
|
||||
assert(xy > 1e-14 && xyz > 1e-14);
|
||||
}
|
||||
assertm(xy > 1e-14 && xyz > 1e-14, "Divide by Zero Error");
|
||||
cosl = r[0] / xy;
|
||||
sinl = r[1] / xy;
|
||||
sint = r[2] / xyz;
|
||||
@@ -535,10 +505,7 @@ double PIGeoPosition::azimuth(const PIGeoPosition &p) const {
|
||||
p1 = (xn1 * z1) + (xn2 * z2) + (xn3 * z3) ;
|
||||
p2 = (xe1 * z1) + (xe2 * z2) ;
|
||||
test = piAbsd(p1) + piAbsd(p2);
|
||||
if (test < 1.0e-16) {
|
||||
piCout << "[PIGeoPosition]" << "azAngle(), failed p1+p2 test" << test;
|
||||
assert(test >= 1.0e-16);
|
||||
}
|
||||
assertm(test >= 1.0e-16, "azAngle(), failed p1+p2 test");
|
||||
alpha = 90 - atan2(p1, p2) * rad2deg;
|
||||
if (alpha < 0) return alpha + 360;
|
||||
else return alpha;
|
||||
@@ -553,10 +520,7 @@ double PIGeoPosition::azimuthGeodetic(const PIGeoPosition &p) const {
|
||||
s.transformTo(Cartesian);
|
||||
PIMathVectorT3d z;
|
||||
z = s - r;
|
||||
if (z.length() <= 1e-4) { // if the positions are within .1 millimeter
|
||||
piCout << "[PIGeoPosition]" << "Positions are within 0.1 millimeter" << z.length();
|
||||
assert(z.length() > 1e-4);
|
||||
}
|
||||
assertm(z.length() > 1e-4, "Positions are within 0.1 millimeter");
|
||||
PIMathVectorT3d iv; // Compute i vector in local North-East-Up (NEU) system
|
||||
iv[0] = -sin(lat) * cos(lng);
|
||||
iv[1] = -sin(lat) * sin(lng);
|
||||
|
||||
@@ -177,17 +177,13 @@ void PIFFT_double::ftbasegeneratecomplexfftplan(uint n, ftplan * plan) {
|
||||
curplan.plan.resize(planarraysize);
|
||||
int ftbase_ftbasecffttask = 0;
|
||||
ftbase_ftbasegenerateplanrec(n, ftbase_ftbasecffttask, plan, &plansize, &precomputedsize, &planarraysize, &tmpmemsize, &stackmemsize, stackptr);
|
||||
if (stackptr != 0) {
|
||||
return;//ae_assert(stackptr==0, "Internal error in FTBaseGenerateComplexFFTPlan: stack ptr!");
|
||||
}
|
||||
assert(stackptr==0);
|
||||
curplan.stackbuf.resize(piMax<int>(stackmemsize, 1)); //ae_vector_set_length(&curplan.stackbuf, ae_maxint(stackmemsize, 1));
|
||||
curplan.tmpbuf.resize(piMax<int>(tmpmemsize, 1)); //ae_vector_set_length(&(curplan.tmpbuf), ae_maxint(tmpmemsize, 1));
|
||||
curplan.precomputed.resize(piMax<int>(precomputedsize, 1)); //ae_vector_set_length(&curplan.precomputed, ae_maxint(precomputedsize, 1));
|
||||
stackptr = 0;
|
||||
ftbase_ftbaseprecomputeplanrec(plan, 0, stackptr);
|
||||
if (stackptr != 0) {
|
||||
return;//ae_assert(stackptr==0, "Internal error in FTBaseGenerateComplexFFTPlan: stack ptr!");
|
||||
}
|
||||
assert(stackptr==0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1117,17 +1113,13 @@ void PIFFT_float::ftbasegeneratecomplexfftplan(uint n, ftplan * plan) {
|
||||
curplan.plan.resize(planarraysize);
|
||||
int ftbase_ftbasecffttask = 0;
|
||||
ftbase_ftbasegenerateplanrec(n, ftbase_ftbasecffttask, plan, &plansize, &precomputedsize, &planarraysize, &tmpmemsize, &stackmemsize, stackptr);
|
||||
if (stackptr != 0) {
|
||||
return;//ae_assert(stackptr==0, "Internal error in FTBaseGenerateComplexFFTPlan: stack ptr!");
|
||||
}
|
||||
assertm(stackptr==0, "Internal error in FTBaseGenerateComplexFFTPlan");
|
||||
curplan.stackbuf.resize(piMax<int>(stackmemsize, 1)); //ae_vector_set_length(&curplan.stackbuf, ae_maxint(stackmemsize, 1));
|
||||
curplan.tmpbuf.resize(piMax<int>(tmpmemsize, 1)); //ae_vector_set_length(&(curplan.tmpbuf), ae_maxint(tmpmemsize, 1));
|
||||
curplan.precomputed.resize(piMax<int>(precomputedsize, 1)); //ae_vector_set_length(&curplan.precomputed, ae_maxint(precomputedsize, 1));
|
||||
stackptr = 0;
|
||||
ftbase_ftbaseprecomputeplanrec(plan, 0, stackptr);
|
||||
if (stackptr != 0) {
|
||||
return;//ae_assert(stackptr==0, "Internal error in FTBaseGenerateComplexFFTPlan: stack ptr!");
|
||||
}
|
||||
assertm(stackptr==0, "Internal error in FTBaseGenerateComplexFFTPlan");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -890,6 +890,11 @@ public:
|
||||
return tm;
|
||||
}
|
||||
|
||||
static _CMatrix zero(const uint cols, const uint rows) {
|
||||
_V2D::resize(rows, cols);
|
||||
fill(Type(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates a row matrix of every element that is equal to every element of the vector
|
||||
*
|
||||
@@ -1002,49 +1007,27 @@ public:
|
||||
*/
|
||||
bool isValid() const { return !PIVector2D<Type>::isEmpty(); }
|
||||
|
||||
/**
|
||||
* @brief Matrix assignment to matrix "v"
|
||||
*
|
||||
* @param v matrix for the assigment
|
||||
* @return matrix equal with v
|
||||
*/
|
||||
_CMatrix &operator=(const PIVector<PIVector<Type> > &v) {
|
||||
*this = _CMatrix(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compare with matrix "sm"
|
||||
*
|
||||
* @param sm matrix for the compare
|
||||
* @return if matrices are equal true, else false
|
||||
*/
|
||||
bool operator==(const _CMatrix &sm) const {
|
||||
PIMM_FOR_A(i) if (_V2D::mat[i] != sm.mat[i]) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compare with matrix "sm"
|
||||
*
|
||||
* @param sm matrix for the compare
|
||||
* @return if matrices are not equal true, else false
|
||||
*/
|
||||
bool operator!=(const _CMatrix &sm) const { return !(*this == sm); }
|
||||
|
||||
/**
|
||||
* @brief Addition assignment with matrix "sm"
|
||||
*
|
||||
* @param sm matrix for the addition assigment
|
||||
*/
|
||||
void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; }
|
||||
void operator+=(const _CMatrix &sm) {
|
||||
assert(_V2D::rows() == sm.rows());
|
||||
assert(_V2D::cols() == sm.cols());
|
||||
PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Subtraction assignment with matrix "sm"
|
||||
*
|
||||
* @param sm matrix for the subtraction assigment
|
||||
*/
|
||||
void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; }
|
||||
void operator-=(const _CMatrix &sm) {
|
||||
assert(_V2D::rows() == sm.rows());
|
||||
assert(_V2D::cols() == sm.cols());
|
||||
PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Multiplication assignment with value "v"
|
||||
@@ -1079,6 +1062,8 @@ public:
|
||||
*/
|
||||
_CMatrix operator+(const _CMatrix &sm) const {
|
||||
_CMatrix tm(*this);
|
||||
assert(tm.rows() == sm.rows());
|
||||
assert(tm.cols() == sm.cols());
|
||||
PIMM_FOR_A(i) tm.mat[i] += sm.mat[i];
|
||||
return tm;
|
||||
}
|
||||
@@ -1091,6 +1076,8 @@ public:
|
||||
*/
|
||||
_CMatrix operator-(const _CMatrix &sm) const {
|
||||
_CMatrix tm(*this);
|
||||
assert(tm.rows() == sm.rows());
|
||||
assert(tm.cols() == sm.cols());
|
||||
PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i];
|
||||
return tm;
|
||||
}
|
||||
|
||||
27
main.cpp
27
main.cpp
@@ -40,25 +40,12 @@ inline PIByteArray & operator >>(PIByteArray & ba, MM & v) {piCout << ">>"
|
||||
|
||||
|
||||
int main() {
|
||||
PIByteArray ba;
|
||||
MM m;
|
||||
m.e = 2;
|
||||
m.y = 0.1;
|
||||
PIVector<MM> v;
|
||||
//v.resize(1,2,m);
|
||||
v << m << m;
|
||||
|
||||
piCout << "m:";
|
||||
ba << m;
|
||||
piCout << ba;
|
||||
ba >> m;
|
||||
piCout << ba;
|
||||
|
||||
ba.clear();
|
||||
piCout << "v:";
|
||||
ba << v;
|
||||
piCout << ba;
|
||||
ba >> v;
|
||||
piCout << ba;
|
||||
PIMathMatrixd m = PIMathMatrixd::identity(3,3);
|
||||
m.fill(0);
|
||||
PIMathMatrixd m2 = PIMathMatrixd::identity(3,4);
|
||||
piCout << m;
|
||||
piCout << m2;
|
||||
piCout << m * m2;
|
||||
piCout << m2 * m;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user