Blame view

src/ParamOutputImpl/Plot/Range.cc 1.56 KB
fbe3c2bb   Benjamin Renard   First commit
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * Range.cc
 *
 *  Created on: 17 déc. 2013
 *      Author: CS
 */

#include "Range.hh"
#include "iostream"

namespace plot {

Range extendRange(Range pRange) {
	// Check in term of value which is the maximum value
	// and which is the minimum.

	double lMin = pRange.getMin();
	double lMax = pRange.getMax();
	if(lMin < lMax) {
		if ( (lMin < 1 && lMin > -1) &&
			(lMax < 1 && lMax > -1) ) {
			lMin = extend2LowerValue(lMin);
			lMax = extend2UpperValue(lMax);
		} else {
			lMax = ceil(lMax);
			lMin = floor(lMin);
		}
	} else {
		if ( (lMin < 1 && lMin > -1) &&
			(lMax < 1 && lMax > -1) ) {
			lMin = extend2UpperValue(lMin);
			lMax = extend2LowerValue(lMax);
		} else {
			lMin = ceil(lMin);
			lMax = floor(lMax);
		}
	}

	Range lRange (lMin, lMax);
	lRange._extend = pRange._extend;
	return lRange;
}

double extend2UpperValue(double lValue) {
	// this give -0.0035 => 0.0035 => -2.4... => -3
	int lExp;
	if(lValue > 0) {
		lExp = floor(log10(lValue));
	} else {
		lExp = floor(log10(-1 * lValue));
	}
	// -0.0035 => -3.5
	double lTmpValue = lValue * pow(10, abs(lExp));
	// -3.5 => -3
	lTmpValue = ceil(lTmpValue);

	// -3 => -0.003
	lValue = lTmpValue * pow(10, lExp);

	return lValue;
}

double extend2LowerValue(double lValue) {
	// this give -0.0035 => 0.0035 => -2.4... => -3
	int lExp;
	if(lValue > 0) {
		lExp = floor(log10(lValue));
	} else {
		lExp = floor(log10(-1 * lValue));
	}
	// -0.0035 => -3.5
	double lTmpValue = lValue * pow(10, abs(lExp));
	// -3.5 => -4
	lTmpValue = floor(lTmpValue);

	// -4 => -0.004
	lValue = lTmpValue * pow(10, lExp);

	return lValue;
}

}