diff --git a/lib/jkqtcommon/jkqtpmathtools.h b/lib/jkqtcommon/jkqtpmathtools.h index 06b2cb369f..b2610653cc 100644 --- a/lib/jkqtcommon/jkqtpmathtools.h +++ b/lib/jkqtcommon/jkqtpmathtools.h @@ -51,6 +51,17 @@ #define JKQTPSTATISTICS_SQRT_2PI 2.50662827463 +/*! \brief \f$ \mbox{ln}(10)=2.30258509299404568402... \f$ + \ingroup jkqtptools_math_basic + +*/ +#ifdef M_LN10 +# define JKQTPSTATISTICS_LN10 M_LN10 +#else +# define JKQTPSTATISTICS_LN10 2.30258509299404568402 +#endif + + /** \brief double-value NotANumber * \ingroup jkqtptools_math_basic */ diff --git a/lib/jkqtcommon/jkqtpstringtools.cpp b/lib/jkqtcommon/jkqtpstringtools.cpp index 029f4ba71a..72a56fdb34 100644 --- a/lib/jkqtcommon/jkqtpstringtools.cpp +++ b/lib/jkqtcommon/jkqtpstringtools.cpp @@ -22,6 +22,7 @@ Copyright (c) 2008-2019 Jan W. Krieger () #include "jkqtcommon/jkqtpstringtools.h" +#include "jkqtcommon/jkqtpmathtools.h" #include #include #include @@ -216,7 +217,7 @@ std::string jkqtp_tolower(const std::string& s){ double adata=fabs(data); std::string res=jkqtp_floattostr(data, past_comma, remove_trail0); - long exp=static_cast(floor(log(adata)/log(10.0))); + long exp=static_cast(floor(log(adata)/JKQTPSTATISTICS_LN10)); if ((minNoExponent>fabs(data)) || (fabs(data)>maxNoExponent)) { std::string v=jkqtp_floattostr(data/pow(10.0, static_cast(exp)), past_comma, remove_trail0); if (v!="1" && v!="10") { @@ -242,7 +243,7 @@ std::string jkqtp_tolower(const std::string& s){ double adata=fabs(data); std::string res=jkqtp_floattostr(data, past_comma, remove_trail0); - long exp=static_cast(floor(log(adata)/log(10.0))); + long exp=static_cast(floor(log(adata)/JKQTPSTATISTICS_LN10)); if ((minNoExponent<=fabs(data)) && (fabs(data)(x)-xOffset)/(xScale)); + return exp(JKQTPSTATISTICS_LN10*(static_cast(x)-xOffset)/(xScale)); } else { return (static_cast(x)-xOffset)/(xScale); } @@ -416,8 +416,8 @@ class JKQTFASTPLOTTER_LIB_EXPORT JKQTFastPlotter : public QGLWidget { /** \brief return y-pixel coordinate from y coordinate */ inline double y2p(double y) { if (yAxisLog) { - if (y<0) return yOffset-log(yMin/10.0)/log(10.0)*yScale; - return yOffset-log(y)/log(10.0)*yScale; + if (y<0) return yOffset-log(yMin/10.0)/JKQTPSTATISTICS_LN10*yScale; + return yOffset-log(y)/JKQTPSTATISTICS_LN10*yScale; } else { return yOffset-y*yScale; } @@ -426,7 +426,7 @@ class JKQTFASTPLOTTER_LIB_EXPORT JKQTFastPlotter : public QGLWidget { /** \brief return y coordinate coordinate from y-pixel */ inline double p2y(long y) { if (yAxisLog) { - return exp(log(10.0)*(static_cast(y)-yOffset)/(-1.0*yScale)); + return exp(JKQTPSTATISTICS_LN10*(static_cast(y)-yOffset)/(-1.0*yScale)); } else { return (static_cast(y)-yOffset)/(-1.0*yScale); } diff --git a/lib/jkqtplotter/graphs/jkqtpevaluatedfunction.cpp b/lib/jkqtplotter/graphs/jkqtpevaluatedfunction.cpp index bc5aadee52..c2d1bd7eb5 100644 --- a/lib/jkqtplotter/graphs/jkqtpevaluatedfunction.cpp +++ b/lib/jkqtplotter/graphs/jkqtpevaluatedfunction.cpp @@ -479,7 +479,7 @@ void JKQTPXFunctionLineGraph::draw(JKQTPEnhancedPainter& painter) { d=d->next; } if (drawErrorPolygons) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.save(); auto __finalpainterrpoly=JKQTPFinally([&painter]() {painter.restore();}); painter.setBrush(eb); painter.setPen(np); QPolygonF poly; @@ -494,21 +494,21 @@ void JKQTPXFunctionLineGraph::draw(JKQTPEnhancedPainter& painter) { } if (fillCurve) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.save(); auto __finalpaintfillc=JKQTPFinally([&painter]() {painter.restore();}); painter.setBrush(b); painter.setPen(np); painter.drawPolygon(filledPolygon, Qt::OddEvenFill); } if (drawLine) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.save(); auto __finalpaintline=JKQTPFinally([&painter]() {painter.restore();}); painter.setPen(p); painter.drawPolyline(linePolygon); } if (drawErrorLines && (static_cast(errorPlotFunction))) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.save(); auto __finalpainterrline=JKQTPFinally([&painter]() {painter.restore();}); painter.setPen(ep); painter.drawPolyline(errorLineTop); painter.drawPolyline(errorLineBottom); @@ -521,7 +521,7 @@ void JKQTPXFunctionLineGraph::draw(JKQTPEnhancedPainter& painter) { c.setHsv(fmod(c.hue()+90, 360), c.saturation(), c.value()); d=data; if (displaySamplePoints) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.save(); auto __finalpaintsamplepoints=JKQTPFinally([&painter]() {painter.restore();}); while (d!=nullptr) { double xv=d->x; double yv=d->f; @@ -554,19 +554,43 @@ void JKQTPXFunctionLineGraph::draw(JKQTPEnhancedPainter& painter) { -JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(JKQTBasePlotter *parent):JKQTPXFunctionLineGraph(parent) {} +JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(JKQTBasePlotter *parent): + JKQTPXFunctionLineGraph(parent) +{ -JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(JKQTPlotter *parent):JKQTPYFunctionLineGraph(parent->getPlotter()) {} +} -JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(const jkqtpSimplePlotFunctionType &f, const QString &title, JKQTBasePlotter *parent):JKQTPXFunctionLineGraph(f, title, parent) {} +JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(JKQTPlotter *parent): + JKQTPYFunctionLineGraph(parent->getPlotter()) +{ -JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(const jkqtpSimplePlotFunctionType &f, const QString &title, JKQTPlotter *parent):JKQTPXFunctionLineGraph(f, title, parent) {} +} + +JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(const jkqtpSimplePlotFunctionType &f, const QString &title, JKQTBasePlotter *parent): + JKQTPXFunctionLineGraph(f, title, parent) +{ + +} + +JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(const jkqtpSimplePlotFunctionType &f, const QString &title, JKQTPlotter *parent): + JKQTPXFunctionLineGraph(f, title, parent) +{ + +} -JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(jkqtpSimplePlotFunctionType &&f, const QString &title, JKQTBasePlotter *parent):JKQTPXFunctionLineGraph(std::move(f), title, parent) {} +JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(jkqtpSimplePlotFunctionType &&f, const QString &title, JKQTBasePlotter *parent): + JKQTPXFunctionLineGraph(std::move(f), title, parent) +{ + +} -JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(jkqtpSimplePlotFunctionType &&f, const QString &title, JKQTPlotter *parent):JKQTPXFunctionLineGraph(std::move(f), title, parent) {} +JKQTPYFunctionLineGraph::JKQTPYFunctionLineGraph(jkqtpSimplePlotFunctionType &&f, const QString &title, JKQTPlotter *parent): + JKQTPXFunctionLineGraph(std::move(f), title, parent) +{ + +} void JKQTPYFunctionLineGraph::draw(JKQTPEnhancedPainter& painter) { #ifdef JKQTBP_AUTOTIMER @@ -633,7 +657,7 @@ void JKQTPYFunctionLineGraph::draw(JKQTPEnhancedPainter& painter) { double yl2=y; if (fillCurve) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.save(); auto __finalpaintfillcurve=JKQTPFinally([&painter]() {painter.restore();}); painter.setBrush(b); painter.setPen(np); QPolygonF poly; @@ -647,7 +671,7 @@ void JKQTPYFunctionLineGraph::draw(JKQTPEnhancedPainter& painter) { } if (drawErrorPolygons && (static_cast(errorPlotFunction))) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.save(); auto __finalpainterrorpoly=JKQTPFinally([&painter]() {painter.restore();}); painter.setBrush(eb); painter.setPen(np); QPolygonF poly; diff --git a/lib/jkqtplotter/graphs/jkqtpfilledcurve.cpp b/lib/jkqtplotter/graphs/jkqtpfilledcurve.cpp index 3eb20721c8..cdca16d449 100644 --- a/lib/jkqtplotter/graphs/jkqtpfilledcurve.cpp +++ b/lib/jkqtplotter/graphs/jkqtpfilledcurve.cpp @@ -246,7 +246,7 @@ void JKQTPFilledVerticalRangeGraph::draw(JKQTPEnhancedPainter &painter) if (drawLine) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.save(); auto __finalpaintline=JKQTPFinally([&painter]() {painter.restore();}); if (isHighlighted()) { diff --git a/lib/jkqtplotter/graphs/jkqtpscatter.cpp b/lib/jkqtplotter/graphs/jkqtpscatter.cpp index 04bdd30663..1d09e920f7 100644 --- a/lib/jkqtplotter/graphs/jkqtpscatter.cpp +++ b/lib/jkqtplotter/graphs/jkqtpscatter.cpp @@ -391,7 +391,7 @@ void JKQTPXYParametrizedScatterGraph::draw(JKQTPEnhancedPainter &painter) double specSymbSize=0; bool hasSpecSymbSize=false; { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.save(); auto __finalpaintinner=JKQTPFinally([&painter]() {painter.restore();}); for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); @@ -451,7 +451,7 @@ void JKQTPXYParametrizedScatterGraph::draw(JKQTPEnhancedPainter &painter) if (lines.size()>0) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.save(); auto __finalpaintinner=JKQTPFinally([&painter]() {painter.restore();}); if (isHighlighted()) { QPen pp=penSelection; if (colorColumn>=0) { diff --git a/lib/jkqtplotter/graphs/jkqtpviolinplotstylingmixins.cpp b/lib/jkqtplotter/graphs/jkqtpviolinplotstylingmixins.cpp index 06e045c2dc..2dedc75ff7 100644 --- a/lib/jkqtplotter/graphs/jkqtpviolinplotstylingmixins.cpp +++ b/lib/jkqtplotter/graphs/jkqtpviolinplotstylingmixins.cpp @@ -590,7 +590,7 @@ void JKQTPGraphViolinplotStyleMixin::plotVerticalViolinplot(JKQTBasePlotter *par const double freqFactorl=1.0/fmax*fabs(xpleft-xp); if (m_violinStyle==ViolinStyle::BoxViolin && NViol>1) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.save(); auto __finalpaintboxvio=JKQTPFinally([&painter]() {painter.restore();}); painter.setPen(getLinePen(painter, parent)); painter.setBrush(getFillBrush(painter, parent)); @@ -639,7 +639,7 @@ void JKQTPGraphViolinplotStyleMixin::plotVerticalViolinplot(JKQTBasePlotter *par pright<1) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.save(); auto __finalpaintboxvio=JKQTPFinally([&painter]() {painter.restore();}); painter.setPen(getLinePen(painter, parent)); painter.setBrush(getFillBrush(painter, parent)); @@ -822,7 +822,7 @@ void JKQTPGraphViolinplotStyleMixin::plotHorizontalViolinplot(JKQTBasePlotter *p pright<logAxis = __value; this->paramsChanged=true; if (this->isLogAxis()) { - if (axismin<0) axismin=pow(10.0, floor(log(axismax-axismin)/log(10.0)-1.0)); - if (axismax<0) axismax=pow(10.0, floor(log(axismax-axismin)/log(10.0)+1.0)); + if (axismin<0) axismin=pow(10.0, floor(log(axismax-axismin)/JKQTPSTATISTICS_LN10-1.0)); + if (axismax<0) axismax=pow(10.0, floor(log(axismax-axismin)/JKQTPSTATISTICS_LN10+1.0)); } redrawPlot(); } diff --git a/lib/jkqtplotter/jkqtpdatastorage.cpp b/lib/jkqtplotter/jkqtpdatastorage.cpp index 4e6b0a35ef..89330c6f6f 100644 --- a/lib/jkqtplotter/jkqtpdatastorage.cpp +++ b/lib/jkqtplotter/jkqtpdatastorage.cpp @@ -729,8 +729,8 @@ size_t JKQTPDatastore::addLinearColumn(size_t rows, double start, double end, co size_t JKQTPDatastore::addLogColumn(size_t rows, double start, double end, const QString &name) { JKQTPDatastoreItem* it=new JKQTPDatastoreItem(1, rows); - const double x0=log(start)/log(10.0); - const double x1=log(end)/log(10.0); + const double x0=log(start)/JKQTPSTATISTICS_LN10; + const double x1=log(end)/JKQTPSTATISTICS_LN10; for (size_t i=0; iset(0, i, pow(10.0, x0+static_cast(i)/static_cast(rows-1)*(x1-x0))); }