BIG deep clean

This commit is contained in:
2020-06-10 13:14:16 +03:00
parent f579718e0b
commit c59579d5d5
222 changed files with 2392 additions and 11600 deletions

View File

@@ -1,3 +1,25 @@
/*! \file picompress.h
* \brief Compress class using zlib
*/
/*
PIP - Platform Independent Primitives
Compress class using zlib
Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PICOMPRESS_H
#define PICOMPRESS_H

View File

@@ -2,22 +2,22 @@
* \brief CRC checksum calculator
*/
/*
PIP - Platform Independent Primitives
CRC checksum calculator
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
CRC checksum calculator
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PICRC_H
@@ -159,8 +159,6 @@ private:
};
//template <uint L>
//inline std::ostream & operator <<(std::ostream & s, const uint_cl<L> & v) {std::ios::fmtflags f = s.flags(); s << std::hex; for (uint i = 0; i < v.length(); ++i) {s << int(v.data()[i]); if (v.data()[i] < 0x10) s << '0'; s << ' ';} s.flags(f); return s;}
inline uchar reverseByte(uchar b) {
uchar ret = 0;

View File

@@ -166,8 +166,6 @@ PIEvaluatorContent::PIEvaluatorContent() {
addFunction("defined", 1);
addFunction("round", 1);
clearCustomVariables();
//addVariable("n", 0.);
//addVariable("x1", 123);
}
@@ -195,19 +193,12 @@ void PIEvaluatorContent::clearCustomVariables() {
void PIEvaluatorContent::sortVariables() {
//Variable tv;
for (uint i = 0; i < variables.size(); i++) {
for (uint j = variables.size() - 1; j > i; j--) {
if (variables[j].name.length() <= variables[i].name.length()) continue;
piSwap<Variable>(variables[i], variables[j]);
}
}
/*
* qDebug() << "---";
* for (int i = 0; i < variables.size(); i++) {
* qDebug() << variables[i].name;
}
*/
}
@@ -258,6 +249,7 @@ BaseFunctions PIEvaluatorContent::getBaseFunction(const PIString & name) {
return bfUnknown;
}
const PIString & PIEvaluator::prepare(const PIString & string) {
currentString = string.trimmed();
if (currentString.isEmpty()) currentString = "0";
@@ -402,18 +394,15 @@ bool PIEvaluator::fillElements() {
elements[i].var_num = -666;
}
currentVariables.clear();
//qDebug().nospace() << "search for functions ...";
for (int i = 0; i < content.functionsCount(); i++) {
curfind = content.function(i).identifier;
cfunc = i; //(int)content.function(i).type;
cfunc = i;
flen = curfind.length();
fstart = 0;
while (fstart >= 0) {
fstart = tmps.find(curfind, fstart);
if (fstart < 0) break;
if (tmps[fstart + flen] != '(') {
//currentString.insert(fstart + flen, "(");
//return true;
fstart++;
continue;
}
@@ -425,7 +414,6 @@ bool PIEvaluator::fillElements() {
}
}
cnum = 0;
//qDebug().nospace() << "search for variables ...";
for (int i = 0; i < content.variablesCount(); i++) {
curfind = content.variable(i).name;
flen = curfind.length();
@@ -442,18 +430,11 @@ bool PIEvaluator::fillElements() {
}
curfind = "";
cnum = 1;
//qDebug().nospace() << "search for numbers ...";
for (int i = 0; i < tmps.length(); i++) {
cc = tmps[i];
/*if (cc == " " || cc == "(" || cc == ")") {
curfind = "";
cpart = 0;
numFound = false;
continue;
}*/
switch (cpart) {
case 0:
if ((cc >= '0' && cc <= '9')) {// || cc == '-' || cc == '+') {
if ((cc >= '0' && cc <= '9')) {
curfind += cc;
cpart = 1;
continue;
@@ -515,7 +496,6 @@ bool PIEvaluator::fillElements() {
break;
}
if (numFound) {
//qDebug().nospace() << "add " << cnum << ": " << curfind << " = " << curfind.toDouble();
currentVariables.push_back(Variable("tmp" + PIString::fromNumber(cnum), curfind.toDouble()));
for (int j = i - curfind.length(); j < i; j++) {
elements[j].set(etNumber, cnum, -cnum);
@@ -528,7 +508,6 @@ bool PIEvaluator::fillElements() {
}
}
if (cpart > 0) {
//qDebug().nospace() << "add " << cnum << ": " << curfind << " = " << curfind.toDouble();
currentVariables.push_back(Variable("tmp" + PIString::fromNumber(cnum), curfind.toDouble()));
for (int j = tmps.length() - curfind.length(); j < tmps.length(); j++) {
elements[j].set(etNumber, cnum, -cnum);
@@ -536,7 +515,6 @@ bool PIEvaluator::fillElements() {
}
}
cc = nc = fc;
//qDebug().nospace() << "search for signes ...";
for (int i = 0; i < tmps.length(); i++) {
cc = tmps[i];
if (i > 0) pc = tmps[i - 1];
@@ -559,7 +537,6 @@ bool PIEvaluator::fillElements() {
///cout << "found sign " << cc << " :" << cnum - 1 << endl;
if (cc == '-' && currentVariables.size_s() >= cnum)
currentVariables[cnum - 1].value = -currentVariables[cnum - 1].value;
//i++;
continue;
}
}
@@ -569,9 +546,7 @@ bool PIEvaluator::fillElements() {
continue;
}
}
/*
qDebug().nospace() << tmps;
cout << " ";
/*cout << " ";
for (int i = 0; i < elements.size(); i++) {
switch (elements[i].type) {
case etFunction: cout << "f"; break;
@@ -580,10 +555,8 @@ bool PIEvaluator::fillElements() {
case etVariable: cout << "v"; break;
}
}
cout << endl;
*/
cout << endl; */
return false;
//for (int i = 0; i < currentVariables.size(); i++) qDebug() << "var " << i << ": " << currentVariables[i].value.real();
}
@@ -598,7 +571,6 @@ bool PIEvaluator::setSignes() {
fc = tmps[i].toLower();
sc = tmps[ni].toLower();
pc = tmps[pi].toLower();
//if (elements[i].type == etOperator || elements[ni].type == etVariable) continue;
if (fc == ',' || sc == ',') continue;
if (elements[i].type == etOperator && elements[ni].type == etOperator) continue;
if (fc == ')' && (elements[ni].type == etNumber || elements[ni].type == etVariable || elements[ni].type == etFunction)) needInsert = 1;
@@ -614,32 +586,13 @@ bool PIEvaluator::setSignes() {
case 1:
currentString.insert(ni + inserted, "*");
elements.insert(ni + inserted, Element(etOperator, -1));
//inserted++;
//i++;
return true;
/*case 2:
currentString.insert(ni + inserted, ")");
currentString.insert(ni + inserted, "(");
elements.insert(ni + inserted, Element(etOperator, -1));
elements.insert(ni + inserted, Element(etOperator, -1));
inserted++;
i++;
return true;*/
case 3:
currentString.insert(ni + inserted, "1*");
elements.insert(ni + inserted, Element(etOperator, -1));
//inserted;
//i++;
return true;
}
}
/*if (elements[tmps.length() - 1].type == etFunction) {
currentString.insert(tmps.length() + inserted, ")");
currentString.insert(tmps.length() + inserted, "(");
elements.insert(tmps.length() + inserted, Element(etOperator, -1));
elements.insert(tmps.length() + inserted, Element(etOperator, -1));
return true;
}*/
return false;
}
@@ -658,7 +611,6 @@ void PIEvaluator::convert() {
}
currentString.replace(i, j - i, " ");
for (int k = i + 1; k < j; k++) elements.remove(i);
//i++;
}
for (int i = 0; i < currentString.length(); i++) {
pe = elements[i];
@@ -671,7 +623,6 @@ void PIEvaluator::convert() {
}
currentString.replace(i, j - i, " ");
for (int k = i + 1; k < j; k++) elements.remove(i);
//i++;
}
for (int i = 0; i < currentString.length(); i++) {
pe = elements[i];
@@ -684,10 +635,8 @@ void PIEvaluator::convert() {
}
currentString.replace(i, j - i, " ");
for (int k = i + 1; k < j; k++) elements.remove(i);
//i++;
}
/*qDebug().nospace() << currentString;
cout << " ";
/*cout << " ";
for (int i = 0; i < elements.size(); i++) {
switch (elements[i].type) {
case etFunction: cout << "f"; break;
@@ -696,7 +645,7 @@ void PIEvaluator::convert() {
case etVariable: cout << "v"; break;
}
}
cout << endl;*/
cout << endl; */
}
@@ -707,7 +656,6 @@ PIString PIEvaluator::preprocess(const PIString & string) {
ret = prepare(string);
convert();
instructions.clear();
//qDebug() << preproc->currentString;
variables = currentVariables;
lind = parse(currentString);
if (instructions.size() == 0) {
@@ -715,8 +663,7 @@ PIString PIEvaluator::preprocess(const PIString & string) {
instructions.push_back(Instruction(oNone, PIVector<short>(1, lind), -variables.size_s()));
}
kvars = &(content.variables);
/*
cout << endl << "variables:" << endl;
/*cout << endl << "variables:" << endl;
for (int i = 0; i < variables.size(); i++)
cout << i << " value = " << variables[i].value << endl;
@@ -729,8 +676,7 @@ PIString PIEvaluator::preprocess(const PIString & string) {
cout << instructions[i].operators[j] << "; ";
cout << endl << " function " << instructions[i].function << endl;
cout << " out " << instructions[i].out << endl;
}
*/
} */
makeOutput(ret);
return ret;
}
@@ -745,9 +691,7 @@ int PIEvaluator::parse(const PIString & string, int offset) {
PIVector<short> args, atmp;
PIVector<Operation> opers;
///qDebug() << "to parse :" + string;
///cout << " "; for (int i = 0; i < slen; i++) cout << preproc->elements[i + offset].type; cout << endl;
//cout << " "; for (int i = 0; i < slen; i++) cout << preproc->elements[i + offset].type; cout << endl;
for (int i = 0; i < slen; i++) {
ce = elements[i + offset];
cc = string[i];
@@ -761,16 +705,11 @@ int PIEvaluator::parse(const PIString & string, int offset) {
case etFunction:
i++;
cfunc = content.function(ce.var_num);
//facnt = cfunc.arguments;
atmp.clear();
bcnt = farg = 1;
///qDebug() << "function: " + cfunc.identifier;
//for (int k = 0; k < facnt; k++) {
carg = "";
k = i + 1;
//if (string.size_s() <= k || k < 0) return -666;
while (bcnt > 0) {
//if (k < facnt - 1) fcomma = string.indexOf(',', j);
cc = string[k];
switch (cc.toAscii()) {
case '(': bcnt++; break;
@@ -807,10 +746,8 @@ int PIEvaluator::parse(const PIString & string, int offset) {
instructions.push_back(Instruction(oFunction, atmp, farg, ce.var_num));
args.push_back(farg);
//for (int i = 0; i < args.size_s(); i++) cout << preproc->currentVariables[-args[i]].value << endl;
//i = j + 1;
continue;
case etOperator:
//qDebug() << "operator: " << cc;
if (cc == '(') {
sbrackets = inBrackets(string.right(slen - i));
args.push_back(parse(sbrackets, i + offset + 1));
@@ -833,12 +770,10 @@ int PIEvaluator::parse(const PIString & string, int offset) {
if (cc == '|') {opers.push_back(oOr); continue;}
}
}
/*
cout << "stack: " << endl << "args: ";
/*cout << "stack: " << endl << "args: ";
for (int i = 0; i < args.size_s(); i++) cout << args[i] << ", ";
cout << endl << "opers: ";
for (int i = 0; i < opers.size_s(); i++) cout << opers[i] << ", ";
*/
for (int i = 0; i < opers.size_s(); i++) cout << opers[i] << ", "; */
if (opers.size_s() == 0) {
if (args.size_s() > 0) return args.back();
else return -666;
@@ -846,7 +781,7 @@ int PIEvaluator::parse(const PIString & string, int offset) {
int oprior = -1;
PIVector<Operation> opv;
for (;;) {
while(1) {
operationsByPriority(++oprior, opv);
if (opv.isEmpty()) break;
for (int j = 0; j < opers.size_s(); j++) {
@@ -875,7 +810,7 @@ int PIEvaluator::parse(const PIString & string, int offset) {
}
}
return instructions.back().out;
///cout << endl;
//cout << endl;
}
@@ -898,7 +833,7 @@ bool PIEvaluator::check() {
fac = cf.arguments;
gac = ci.operators.size_s();
for (int j = 0; j < ci.operators.size_s(); j++) {
if (ci.operators[j] == -666) { //(ci.operators[j] < -variables.size_s() || ci.operators[j] >= kvars->size()) {
if (ci.operators[j] == -666) {
error = true;
gac--;
}
@@ -1013,7 +948,6 @@ inline void PIEvaluator::execFunction(const Instruction & ci) {
const Function & cfunc(content.function(ci.function));
int oi = -ci.out - 1;
complexd tmp, stmp, ttmp;
//qDebug() << "function " << (int)cfunc.type;
switch (cfunc.type) {
case bfSin:
tmpvars[oi].value = sin(value(ci.operators[0]));

View File

@@ -23,7 +23,7 @@
#ifndef PIEVALUATOR_H
#define PIEVALUATOR_H
#include "pistring.h"
#include "pistringlist.h"
#include "pimathcomplex.h"
typedef complexd (*FuncFunc)(void * , int, complexd * );
@@ -160,10 +160,7 @@ public:
void setVariable(int index, complexd value = 0.) {if (index >= 0 && index < content.variablesCount()) content.setVariableValue(index, value);}
void setCustomVariableValue(int index, complexd value = 0.) {content.variables[index + content.cv_count].value = value;}
/*
//! Add function "name" with arguments count "args_count" and handler "func". Three arguments will be passed to handler: \a data(), "args_count" and array of input values.
void addFunction(const PIString & name, int args_count, FuncFunc func) {content.addCustomFunction(name, args_count, func);}
*/
//! Evaluate last successfully checked with function \a check() expression and returns result
complexd evaluate();

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Class for FFT, IFFT and Hilbert transformations
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Andrey Bychkov work.a.b@yandex.ru, Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Class for FFT, IFFT and Hilbert transformations
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Andrey Bychkov work.a.b@yandex.ru, Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by

View File

@@ -27,14 +27,12 @@
template<int Precision = 0, typename Type = int>
class PIP_EXPORT PIFixedPoint {
// friend PICout operator <<(PICout s, const FixedPoint<> & v);
public:
typedef PIFixedPoint<Precision, Type> fp;
PIFixedPoint(const Type &v = Type()) {val = fpv(v);}
PIFixedPoint(const fp &v) {val = v.val;}
PIFixedPoint(const float &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << (Precision-1)));}
PIFixedPoint(const double &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << (Precision-1)));}
// FixedPoint(const long double &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << Precision-1));}
template<typename T>
fp & operator =(const T & v) {val = fpv(Type(v)); return *this;}
@@ -58,25 +56,13 @@ public:
fp operator *(const fp & v) {fp p; p.val = fpi(val * v.val); return p;}
fp operator /(const fp & v) {fp p; p.val = fpv(val) / v.val; return p;}
/*fp & operator =(const Type & v) {val = fpv(v); return *this;}
bool operator ==(const Type & v) const {val == fpv(v);}
bool operator !=(const Type & v) const {val != fpv(v);}
void operator +=(const Type & v) {val += fpv(v);}
void operator -=(const Type & v) {val -= fpv(v);}
void operator *=(const Type & v) {val *= fpv(v);}
void operator /=(const Type & v) {val /= fpv(v);}
fp operator +(const Type & v) {fp p = fp(*this); p.val += fpv(v); return p;}
fp operator -(const Type & v) {fp p = fp(*this); p.val -= fpv(v); return p;}
fp operator *(const Type & v) {fp p = fp(*this); p.val *= fpv(v); return p;}
fp operator /(const Type & v) {fp p = fp(*this); p.val /= fpv(v); return p;}*/
Type fpv(Type v) const {return Type(v << Precision);}
Type fpi(Type v) const {return Type(v >> Precision);}
Type fpc(Type v) const {return v - fpv(fpi(v));}
Type val;
};
/*
template<int Precision, typename Type>
inline PICout operator <<(PICout s, const PIFixedPoint<Precision, Type> & v) {
s.space(); s.setControl(0, true);
@@ -100,5 +86,5 @@ inline PICout operator <<(PICout s, const PIFixedPoint<Precision, Type> & v) {
s.restoreControl();
return s;
}
*/
#endif // PIFIXEDPOINT_H

View File

@@ -2,22 +2,22 @@
* \brief Geometry base class
*/
/*
PIP - Platform Independent Primitives
Geometry
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Geometry
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
PIP math complex
Ivan Pelipenko peri4ko@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by

View File

@@ -62,7 +62,6 @@ class PIP_EXPORT PIMathMatrixT {
public:
PIMathMatrixT() {resize(Rows, Cols);}
PIMathMatrixT(const PIVector<Type> & val) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];}
//PIMathMatrixT(const _CMatrix & o) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];}
static _CMatrix identity() {_CMatrix tm = _CMatrix(); PIMM_FOR_WB(r, c) tm.m[r][c] = (c == r ? Type(1) : Type(0)); return tm;}
static _CMatrix filled(const Type & v) {_CMatrix tm; PIMM_FOR_WB(r, c) tm.m[r][c] = v; return tm;}
@@ -185,7 +184,6 @@ public:
for (uint k = i; k < Cols; ++k) smat.m[k][j] -= mul * smat.m[k][i];
for (uint k = 0; k < Cols; ++k) mtmp.m[k][j] -= mul * mtmp.m[k][i];
}
//cout << i << endl << smat << endl;
if (i < Cols - 1) {
if (fabs(smat.m[i+1][i+1]) < Type(1E-200)) {
if (ok != 0) *ok = false;
@@ -456,7 +454,6 @@ public:
for (uint k = 0; k < _V2D::cols_; ++k) mtmp.element(k, j) -= mul * mtmp.element(k, i);
if (sv != 0) (*sv)[j] -= mul * (*sv)[i];
}
//cout << i << endl << smat << endl;
if (i < _V2D::cols_ - 1) {
if (_PIMathMatrixNullCompare(smat.element(i+1, i+1))) {
if (ok != 0) *ok = false;

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Module includes
Ivan Pelipenko peri4ko@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by

View File

@@ -117,12 +117,6 @@ void PIMathSolver::fromTF(const TransferFunction & TF) {
void PIMathSolver::solveEyler1(double u, double h) {
/*for (uint i = 0; i < size; ++i) {
* sum = 0.;
* for (uint j = 0; j < size; ++j)
* sum += A[j][i] * X[j];
* xx[i] = sum + d[i] * u;
}*/
F[0] = A * X + d * u;
X += F[0] * h;
moveF();
@@ -200,7 +194,7 @@ void PIMathSolver::solvePA(double u, double h, uint deg) {
solveEyler2(u, h);
break;
}
/// calc last piece
// calc last piece
x0 = 0.;
td = 1.;
t = times[0];
@@ -221,7 +215,7 @@ void PIMathSolver::solvePA(double u, double h, uint deg) {
lp = x0 - x1;
if (deg > 2) {
/// calc prev piece
// calc prev piece
x0 = 0.;
td = 1.;
dh = times[1] - times[2];
@@ -233,10 +227,10 @@ void PIMathSolver::solvePA(double u, double h, uint deg) {
}
x0 *= t;
ct = x1 - x0;
/// calc correction
// calc correction
ct -= pY[k];
}
/// calc final
// calc final
X[k] += lp - ct;
pY[k] = lp;
} else {

View File

@@ -27,23 +27,17 @@
template<uint Cols, uint Rows, typename Type>
class PIMathMatrixT;
//class PIMathVectorT;
//#define PIMVCONSTR(n, t, args) PIMathVectorT<uint(n), t> _PIMathVectorConstruct(args) {PIVector<t> v; for (int i=0; i<n; ++i) v << a3; return PIMathVectorT<uint(n), t>(v)}
/// Vector templated
#define PIMV_FOR(v, s) for (uint v = s; v < Size; ++v)
//#pragma pack(push, 1)
template<uint Size, typename Type = double>
class PIP_EXPORT PIMathVectorT {
typedef PIMathVectorT<Size, Type> _CVector;
public:
PIMathVectorT() {resize();}
//PIMathVectorT(Type val) {resize(Size); PIMV_FOR(i, 0) c[i] = val;}
PIMathVectorT(const PIVector<Type> & val) {resize(); PIMV_FOR(i, 0) c[i] = val[i];}
PIMathVectorT(const _CVector & st, const _CVector & fn) {resize(); set(st, fn);}
@@ -98,16 +92,9 @@ public:
return ret;
}
// operator PIMathMatrixT<1, Size, Type>() {return transposed();}
// operator PIMathMatrixT<Size, 1, Type>() {
// PIMathMatrixT<Size, 1, Type> ret;
// PIMV_FOR(i, 0) ret[i][0] = c[i];
// return ret;
// }
Type distToLine(const _CVector & lp0, const _CVector & lp1) {
_CVector a(lp0, lp1), b(lp0, *this), c(lp1, *this);
Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length();//, s = b.length() + c.length() - a.length();
Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length();
return f;}
template<uint Size1, typename Type1> /// vector {Size, Type} to vector {Size1, Type1}
@@ -121,7 +108,6 @@ private:
Type c[Size];
};
//#pragma pack(pop)
template<uint Size, typename Type>
inline PIMathVectorT<Size, Type> operator *(const Type & x, const PIMathVectorT<Size, Type> & v) {
@@ -142,10 +128,6 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIMathVectorT<Size, Type
template<uint Size, typename Type>
inline PIByteArray & operator >>(PIByteArray & s, PIMathVectorT<Size, Type> & v) {for (uint i = 0; i < Size; ++i) s >> v[i]; return s;}
//template<uint Size0, typename Type0 = double, uint Size1 = Size0, typename Type1 = Type0> /// vector {Size0, Type0} to vector {Size1, Type1}
//inline operator PIMathVectorT<Size1, Type1>(const PIMathVectorT<Size0, Type0> & v) {PIMathVectorT<Size1, Type1> tv; uint sz = piMin<uint>(Size0, Size1); for (uint i = 0; i < sz; ++i) tv[i] = v[i]; return tv;}
template<typename T>
inline PIMathVectorT<2u, T> createVectorT2(T x, T y) {return PIMathVectorT<2u, T>(PIVector<T>() << x << y);}
template<typename T>
@@ -230,10 +212,9 @@ public:
_CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;}
Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;}
//inline operator PIMathMatrix<1, Size, Type>() {return PIMathMatrix<1, Size, Type>(c);}
Type distToLine(const _CVector & lp0, const _CVector & lp1) {
_CVector a(lp0, lp1), b(lp0, *this), c(lp1, *this);
Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length();//, s = b.length() + c.length() - a.length();
Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length();
return f;
}
@@ -245,7 +226,6 @@ public:
inline const Type * data() const {return c.data();}
private:
// uint size_;
PIVector<Type> c;
};

View File

@@ -1,3 +1,22 @@
/*
PIP - Platform Independent Primitives
Class for quaternions
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piquaternion.h"
@@ -65,11 +84,6 @@ PIQuaternion PIQuaternion::rotated(const PIMathVectorT3d & u, double a) const {
void PIQuaternion::rotate(const PIMathVectorT3d & u, double a) {
PIQuaternion v(u * sin(a / 2.), cos(a / 2.));
/*PIMathMatrixT44d r = v.makeMatrix() * makeMatrix() * v.inverted().makeMatrix();
q[0] = r[0][0];
q[1] = r[1][0];
q[2] = r[2][0];
q[3] = r[3][0];*/
*this = (v * (*this) * v.conjugate());
}
@@ -140,7 +154,6 @@ PIQuaternion PIQuaternion::fromAngles(double ax, double ay, double az) {
PIQuaternion PIQuaternion::fromAngles2(double ax, double ay, double az) {
double om = createVectorT3d(ax,ay,az).length();
// az = M_PI - az;
if (om == 0.) return PIQuaternion(PIMathVectorT3d(), 1.);
PIQuaternion res;
res.q[0] = cos(om/2);

View File

@@ -58,7 +58,6 @@ protected:
};
PIQuaternion operator *(const double & a, const PIQuaternion & q);
//PIQuaternion operator *(const PIQuaternion & q, const double & a) {return a*q;}
PIQuaternion operator *(const PIQuaternion & q0, const PIQuaternion & q1);
inline PIQuaternion operator +(const PIQuaternion & q0, const PIQuaternion & q1) {return PIQuaternion(q0.vector() + q1.vector(), q0.scalar() + q1.scalar());}
inline PIQuaternion operator -(const PIQuaternion & q0, const PIQuaternion & q1) {return PIQuaternion(q0.vector() - q1.vector(), q0.scalar() - q1.scalar());}

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Class for calculacing math statistic in values array
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -46,9 +46,7 @@ public:
return false;
mean = given_mean;
variance = skewness = kurtosis = T();
/*
* Variance (using corrected two-pass algorithm)
*/
// Variance (using corrected two-pass algorithm)
for (i = 0; i < n; i++)
v1 += sqr(val[i] - mean);
for (i = 0; i < n; i++)
@@ -59,9 +57,7 @@ public:
if (var < T())
var = T();
stddev = sqrt(var);
/*
* Skewness and kurtosis
*/
// Skewness and kurtosis
if (stddev != T()) {
for (i = 0; i < n; i++) {
v = (val[i] - mean) / stddev;