! Returns a sanitized version of the range. Sanitized means for logarithmic scales, that the range won't span the positive and negative sign domain, i.e. contain zero. Further \a lower will always be numerically smaller (or equal) to \a upper. If the original range does span positive and negative sign domains or contains zero, the returned range will try to approximate the original ra
| 2063 | is wider than the positive interval, this time by changing the \a upper bound. |
| 2064 | */ |
| 2065 | QCPRange QCPRange::sanitizedForLogScale() const |
| 2066 | { |
| 2067 | double rangeFac = 1e-3; |
| 2068 | QCPRange sanitizedRange(lower, upper); |
| 2069 | sanitizedRange.normalize(); |
| 2070 | // can't have range spanning negative and positive values in log plot, so change range to fix it |
| 2071 | //if (qFuzzyCompare(sanitizedRange.lower+1, 1) && !qFuzzyCompare(sanitizedRange.upper+1, 1)) |
| 2072 | if (sanitizedRange.lower == 0.0 && sanitizedRange.upper != 0.0) |
| 2073 | { |
| 2074 | // case lower is 0 |
| 2075 | if (rangeFac < sanitizedRange.upper*rangeFac) |
| 2076 | sanitizedRange.lower = rangeFac; |
| 2077 | else |
| 2078 | sanitizedRange.lower = sanitizedRange.upper*rangeFac; |
| 2079 | } //else if (!qFuzzyCompare(lower+1, 1) && qFuzzyCompare(upper+1, 1)) |
| 2080 | else if (sanitizedRange.lower != 0.0 && sanitizedRange.upper == 0.0) |
| 2081 | { |
| 2082 | // case upper is 0 |
| 2083 | if (-rangeFac > sanitizedRange.lower*rangeFac) |
| 2084 | sanitizedRange.upper = -rangeFac; |
| 2085 | else |
| 2086 | sanitizedRange.upper = sanitizedRange.lower*rangeFac; |
| 2087 | } else if (sanitizedRange.lower < 0 && sanitizedRange.upper > 0) |
| 2088 | { |
| 2089 | // find out whether negative or positive interval is wider to decide which sign domain will be chosen |
| 2090 | if (-sanitizedRange.lower > sanitizedRange.upper) |
| 2091 | { |
| 2092 | // negative is wider, do same as in case upper is 0 |
| 2093 | if (-rangeFac > sanitizedRange.lower*rangeFac) |
| 2094 | sanitizedRange.upper = -rangeFac; |
| 2095 | else |
| 2096 | sanitizedRange.upper = sanitizedRange.lower*rangeFac; |
| 2097 | } else |
| 2098 | { |
| 2099 | // positive is wider, do same as in case lower is 0 |
| 2100 | if (rangeFac < sanitizedRange.upper*rangeFac) |
| 2101 | sanitizedRange.lower = rangeFac; |
| 2102 | else |
| 2103 | sanitizedRange.lower = sanitizedRange.upper*rangeFac; |
| 2104 | } |
| 2105 | } |
| 2106 | // due to normalization, case lower>0 && upper<0 should never occur, because that implies upper<lower |
| 2107 | return sanitizedRange; |
| 2108 | } |
| 2109 | |
| 2110 | /*! |
| 2111 | Returns a sanitized version of the range. Sanitized means for linear scales, that |
no test coverage detected