comparison base/MagnitudeRange.h @ 1429:48e9f538e6e9

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents 4d0d94ba2ea7
children bbfb5a1e4b84
comparison
equal deleted inserted replaced
1428:87ae75da6527 1429:48e9f538e6e9
27 public: 27 public:
28 MagnitudeRange() : m_min(0), m_max(0) { } 28 MagnitudeRange() : m_min(0), m_max(0) { }
29 MagnitudeRange(float min, float max) : m_min(min), m_max(max) { } 29 MagnitudeRange(float min, float max) : m_min(min), m_max(max) { }
30 30
31 bool operator==(const MagnitudeRange &r) { 31 bool operator==(const MagnitudeRange &r) {
32 return r.m_min == m_min && r.m_max == m_max; 32 return r.m_min == m_min && r.m_max == m_max;
33 } 33 }
34 bool operator!=(const MagnitudeRange &r) { 34 bool operator!=(const MagnitudeRange &r) {
35 return !(*this == r); 35 return !(*this == r);
36 } 36 }
37 37
38 bool isSet() const { return (m_min != 0.f || m_max != 0.f); } 38 bool isSet() const { return (m_min != 0.f || m_max != 0.f); }
39 void set(float min, float max) { 39 void set(float min, float max) {
40 m_min = min; 40 m_min = min;
41 m_max = max; 41 m_max = max;
42 if (m_max < m_min) m_max = m_min; 42 if (m_max < m_min) m_max = m_min;
43 } 43 }
44 bool sample(float f) { 44 bool sample(float f) {
45 bool changed = false; 45 bool changed = false;
46 if (isSet()) { 46 if (isSet()) {
47 if (f < m_min) { m_min = f; changed = true; } 47 if (f < m_min) { m_min = f; changed = true; }
48 if (f > m_max) { m_max = f; changed = true; } 48 if (f > m_max) { m_max = f; changed = true; }
49 } else { 49 } else {
50 m_max = m_min = f; 50 m_max = m_min = f;
51 changed = true; 51 changed = true;
52 } 52 }
53 return changed; 53 return changed;
54 } 54 }
55 bool sample(const std::vector<float> &ff) { 55 bool sample(const std::vector<float> &ff) {
56 bool changed = false; 56 bool changed = false;
57 for (auto f: ff) { 57 for (auto f: ff) {
58 if (sample(f)) { 58 if (sample(f)) {
60 } 60 }
61 } 61 }
62 return changed; 62 return changed;
63 } 63 }
64 bool sample(const MagnitudeRange &r) { 64 bool sample(const MagnitudeRange &r) {
65 bool changed = false; 65 bool changed = false;
66 if (isSet()) { 66 if (isSet()) {
67 if (r.m_min < m_min) { m_min = r.m_min; changed = true; } 67 if (r.m_min < m_min) { m_min = r.m_min; changed = true; }
68 if (r.m_max > m_max) { m_max = r.m_max; changed = true; } 68 if (r.m_max > m_max) { m_max = r.m_max; changed = true; }
69 } else { 69 } else {
70 m_min = r.m_min; 70 m_min = r.m_min;
71 m_max = r.m_max; 71 m_max = r.m_max;
72 changed = true; 72 changed = true;
73 } 73 }
74 return changed; 74 return changed;
75 } 75 }
76 float getMin() const { return m_min; } 76 float getMin() const { return m_min; }
77 float getMax() const { return m_max; } 77 float getMax() const { return m_max; }
78 private: 78 private:
79 float m_min; 79 float m_min;