1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#ifndef DIMENSION_H
#define DIMENSION_H
#include <limits>
#include "xypointset.h"
class Dimension {
public:
Dimension() = default;
bool Empty() const { return n_sets_ == 0; }
void Clear() {
n_sets_ = 0;
min_ = std::numeric_limits<double>::quiet_NaN();
max_ = std::numeric_limits<double>::quiet_NaN();
positive_min_ = std::numeric_limits<double>::quiet_NaN();
positive_max_ = std::numeric_limits<double>::quiet_NaN();
}
void AdjustRanges(XYPointSet& pointSet, bool use_x) {
const double set_min = use_x ? pointSet.XRangeMin() : pointSet.YRangeMin();
const double set_max = use_x ? pointSet.XRangeMax() : pointSet.YRangeMax();
const double set_positive_min =
use_x ? pointSet.XRangePositiveMin() : pointSet.YRangePositiveMin();
const double set_positive_max =
use_x ? pointSet.XRangePositiveMax() : pointSet.YRangePositiveMax();
if (n_sets_ == 0) {
min_ = set_min;
max_ = set_max;
positive_min_ = set_positive_min;
positive_max_ = set_positive_max;
} else {
if (min_ > set_min && std::isfinite(set_min)) min_ = set_min;
if (positive_min_ > set_positive_min && std::isfinite(set_positive_min))
positive_min_ = set_positive_min;
if (max_ < set_max && std::isfinite(set_max)) max_ = set_max;
if (positive_max_ < set_positive_max && std::isfinite(set_positive_max))
positive_min_ = set_positive_max;
}
++n_sets_;
}
double Min() const { return min_; }
double Max() const { return max_; }
double PositiveMin() const { return positive_min_; }
double PositiveMax() const { return positive_max_; }
private:
size_t n_sets_ = 0;
double min_ = std::numeric_limits<double>::quiet_NaN();
double max_ = std::numeric_limits<double>::quiet_NaN();
double positive_min_ = std::numeric_limits<double>::quiet_NaN();
double positive_max_ = std::numeric_limits<double>::quiet_NaN();
};
#endif
|