Skip to content
Snippets Groups Projects
Commit 13b8c712 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Deal with +-inf values in 2D plot

parent 929cfb96
No related branches found
No related tags found
No related merge requests found
......@@ -555,8 +555,8 @@ namespace {
plot->X.set_limits(xinf, xsup);
if (!plot->Z.finite())
plot->Z.set_limits(zlim.front(), zlim.back());
if (plot->Y.logflag && !(std::isfinite(yinf) && std::isfinite(ysup)))
throw "No nonzero y values";
if (!(std::isfinite(yinf) && std::isfinite(ysup)))
throw "No valid y values";
if (!plot->Y.finite())
plot->Y.set_limits(yinf-1e-4*std::abs(yinf), ysup+1e-4*std::abs(ysup));
// plot
......
......@@ -11,6 +11,7 @@
#include <iomanip>
#include <iostream>
#include <vector>
#include <boost/format.hpp>
#include "../readplus/macro.hpp"
#include "../trivia/math.hpp"
......@@ -21,6 +22,7 @@
using std::string;
using std::vector;
using std::cout;
using boost::format;
#define S(a) triv::strg((a))
......@@ -62,7 +64,7 @@ void CAxis::ask_and_set(const string& quest)
{
for (;;) {
double inf_in, sup_in;
string resp1 = NMacro::readwd(quest + " [" + str() + "] ? ");
string resp1 = NMacro::readwd(quest + " [" + to_s() + "] ? ");
if (resp1 == "\\q") {
throw S("user escape to main menu");
} else if (resp1 == "") {
......@@ -82,7 +84,7 @@ void CAxis::ask_and_set(const string& quest)
" 0.1 \\ let upper bound unchanged\n"
" * redetermine bounds from data\n"
"just press ENTER to let present range unchanged ["
<< str() << "]\n";
<< to_s() << "]\n";
continue;
}
if (logflag && inf_in <= 0) {
......@@ -277,7 +279,7 @@ void CAxis::set_xgrid(vector<double>& x, int n) const
//! Returns string representation of plot range.
string CAxis::str() const
string CAxis::to_s() const
{
if (inf == -INFINITY || sup == +INFINITY)
return "*";
......@@ -369,7 +371,8 @@ void CAxis::calc_lintacks(vector<double>& Tacks, int& ntpt, double& dtack) const
double drange = dhig-dlow;
int nTacks = drange/dtack + 1.5;
if (nTacks<2)
throw "BUG: calc_lintacks -> nTacks<2";
throw str(format("BUG in calc_lintacks: nTacks<2 for inf=%g sup=%g dtack=%g low=%g hig=%g")
% inf % sup % dtack % dlow % dhig);
for (int i=0; i<nTacks; ++i) {
double d = (i*dhig + (nTacks-1-i)*dlow)/(nTacks-1);
if (std::abs(d)<1e-15*drange)
......
......@@ -33,7 +33,7 @@ public:
void set_rounded_limits(double _inf, double _sup);
void ask_and_set(const std::string& quest);
std::string str() const;
std::string to_s() const;
std::string info() const;
bool finite() const;
bool contains(double val) const;
......
......@@ -205,7 +205,7 @@ namespace {
{
string ret = "% " + A->name + " axis:\n";
if (A->logflag && A->inf <= 0)
throw "BUG: log incompatible with limits " + A->str();
throw "BUG: log incompatible with limits " + A->to_s();
ret += ps_ticktack(A);
return ret;
}
......
......@@ -168,14 +168,32 @@ std::string triv::indices_to_s(const vector<int>& v)
return ret;
}
//! Determines minimal and maximal value in vector v.
//! Results must be tested for finiteness.
void triv::getMinMax(const std::vector<double>& v, double& minval, double&maxval)
{
if (v.size()==0)
throw "BUG: attempt to determine min and max of empty vector";
minval = +INFINITY;
maxval = -INFINITY;
for (auto t = v.begin(); t<v.end(); ++t) {
if (!std::isfinite(*t))
continue;
minval = std::min(minval, *t);
maxval = std::max(maxval, *t);
}
}
//! Determines minimal positive value and maximal value in vector v.
//! Results must be tested for finiteness.
void triv::getPosminMax(const std::vector<double>& v, double& minval, double&maxval)
{
if (v.size()==0)
throw "BUG: attempt to determine min and max of empty vector";
minval = +INFINITY;
maxval = -INFINITY;
for (auto t = v.begin(); t<v.end(); ++t) {
if (*t<=0)
if (!std::isfinite(*t) || *t<=0)
continue;
minval = std::min(minval, *t);
maxval = std::max(maxval, *t);
......
......@@ -25,7 +25,7 @@ namespace triv
void increment_indices(std::vector<int>& v, int incr, int siz);
std::string indices_to_s(const std::vector<int>& v);
template <class T> void getMinMax(const std::vector<T>& v, T& minval, T&maxval);
void getMinMax(const std::vector<double>& v, double& minval, double&maxval);
void getPosminMax(const std::vector<double>& v, double& minval, double&maxval);
template <class T> bool contains(const std::vector<T>& v, const T e);
template <class T, class Pred> std::vector<T> merge_sorted(
......@@ -35,19 +35,6 @@ namespace triv
// Template implementation
//**************************************************************************************************
template <class T>
void getMinMax(const std::vector<T>& v, T& minval, T&maxval)
{
if (v.size()==0)
throw "BUG: attempt to determine min and max of empty vector";
minval = v.front();
maxval = v.front();
for (auto t = v.begin()+1; t<v.end(); ++t) {
minval = std::min(minval, *t);
maxval = std::max(maxval, *t);
}
}
template <class T>
bool contains(const std::vector<T>& v, const T e)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment