16 #ifndef ROOT7_RPadLength
17 #define ROOT7_RPadLength
23 namespace Experimental {
34 std::vector<double> fArr;
37 template <
class DERIVED>
41 CoordSysBase() =
default;
42 CoordSysBase(
double val): fVal(val) {}
43 DERIVED &ToDerived() {
return static_cast<DERIVED &
>(*this); }
45 DERIVED operator-() {
return DERIVED(-fVal); }
47 friend DERIVED operator+(DERIVED lhs, DERIVED rhs) {
return DERIVED{lhs.fVal + rhs.fVal}; }
48 friend DERIVED operator-(DERIVED lhs, DERIVED rhs) {
return DERIVED{lhs.fVal - rhs.fVal}; }
49 friend double operator/(DERIVED lhs, DERIVED rhs) {
return lhs.fVal / rhs.fVal; }
50 DERIVED &operator+=(
const DERIVED &rhs)
55 DERIVED &operator-=(
const DERIVED &rhs)
60 DERIVED &operator*=(
double scale)
65 friend DERIVED operator*(
const DERIVED &lhs,
double rhs) {
return DERIVED(lhs.fVal * rhs); }
66 friend DERIVED operator*(
double lhs,
const DERIVED &rhs) {
return DERIVED(lhs * rhs.fVal); }
67 friend DERIVED operator/(
const DERIVED &lhs,
double rhs) {
return DERIVED(lhs.fVal * rhs); }
68 friend bool operator<(
const DERIVED &lhs,
const DERIVED &rhs) {
return lhs.fVal < rhs.fVal; }
69 friend bool operator>(
const DERIVED &lhs,
const DERIVED &rhs) {
return lhs.fVal > rhs.fVal; }
70 friend bool operator<=(
const DERIVED &lhs,
const DERIVED &rhs) {
return lhs.fVal <= rhs.fVal; }
71 friend bool operator>=(
const DERIVED &lhs,
const DERIVED &rhs) {
return lhs.fVal >= rhs.fVal; }
87 struct Normal: CoordSysBase<Normal> {
88 using CoordSysBase<Normal>::CoordSysBase;
97 struct Pixel: CoordSysBase<Pixel> {
98 using CoordSysBase<Pixel>::CoordSysBase;
106 struct User: CoordSysBase<User> {
107 using CoordSysBase<User>::CoordSysBase;
114 RPadLength(Normal normal): RPadLength() { SetNormal(normal.fVal); }
117 RPadLength(Pixel px): RPadLength() { SetPixel(px.fVal); }
120 RPadLength(User user) : RPadLength() { SetUser(user.fVal); }
123 RPadLength(Normal normal, Pixel px): RPadLength() { SetPixel(px.fVal); SetNormal(normal.fVal); }
126 RPadLength(Normal normal, Pixel px, User user): RPadLength() { SetUser(user.fVal); SetPixel(px.fVal); SetNormal(normal.fVal); }
128 bool HasNormal()
const {
return fArr.size() > 0; }
129 bool HasPixel()
const {
return fArr.size() > 1; }
130 bool HasUser()
const {
return fArr.size() > 2; }
132 RPadLength &SetNormal(
double v)
139 RPadLength &SetPixel(
double v)
146 RPadLength &SetUser(
double v)
154 double GetNormal()
const {
return fArr.size() > 0 ? fArr[0] : 0.; }
155 double GetPixel()
const {
return fArr.size() > 1 ? fArr[1] : 0.; }
156 double GetUser()
const {
return fArr.size() > 2 ? fArr[2] : 0.; }
158 void ClearUser() {
if (fArr.size()>2) fArr.resize(2); }
160 void Clear() { fArr.clear(); }
163 friend RPadLength operator+(RPadLength lhs,
const RPadLength &rhs)
166 if (lhs.HasUser() || rhs.HasUser())
167 res.SetUser(lhs.GetUser() + rhs.GetUser());
168 if (lhs.HasPixel() || rhs.HasPixel())
169 res.SetPixel(lhs.GetPixel() + rhs.GetPixel());
170 if (lhs.HasNormal() || rhs.HasNormal())
171 res.SetNormal(lhs.GetNormal() + rhs.GetNormal());
176 friend RPadLength operator-(RPadLength lhs,
const RPadLength &rhs)
179 if (lhs.HasUser() || rhs.HasUser())
180 res.SetUser(lhs.GetUser() - rhs.GetUser());
181 if (lhs.HasPixel() || rhs.HasPixel())
182 res.SetPixel(lhs.GetPixel() - rhs.GetPixel());
183 if (lhs.HasNormal() || rhs.HasNormal())
184 res.SetNormal(lhs.GetNormal() - rhs.GetNormal());
189 RPadLength operator-()
192 if (HasUser()) res.SetUser(-GetUser());
193 if (HasPixel()) res.SetPixel(-GetPixel());
194 if (HasNormal()) res.SetNormal(-GetNormal());
199 RPadLength &operator+=(
const RPadLength &rhs)
201 if (HasUser() || rhs.HasUser())
202 SetUser(GetUser() + rhs.GetUser());
203 if (HasPixel() || rhs.HasPixel())
204 SetPixel(GetPixel() + rhs.GetPixel());
205 if (HasNormal() || rhs.HasNormal())
206 SetNormal(GetNormal() + rhs.GetNormal());
211 RPadLength &operator-=(
const RPadLength &rhs)
213 if (HasUser() || rhs.HasUser())
214 SetUser(GetUser() - rhs.GetUser());
215 if (HasPixel() || rhs.HasPixel())
216 SetPixel(GetPixel() - rhs.GetPixel());
217 if (HasNormal() || rhs.HasNormal())
218 SetNormal(GetNormal() - rhs.GetNormal());
222 RPadLength &operator*=(
double scale)
224 if (HasUser()) SetUser(scale*GetUser());
225 if (HasPixel()) SetPixel(scale*GetPixel());
226 if (HasNormal()) SetNormal(scale*GetNormal());
239 inline RPadLength::Normal
operator"" _normal(
long double val)
241 return RPadLength::Normal{(double)val};
243 inline RPadLength::Normal
operator"" _normal(
unsigned long long int val)
245 return RPadLength::Normal{(double)val};
255 inline RPadLength::Pixel
operator"" _px(
long double val)
257 return RPadLength::Pixel{(double)val};
259 inline RPadLength::Pixel
operator"" _px(
unsigned long long int val)
261 return RPadLength::Pixel{(double)val};
271 inline RPadLength::User
operator"" _user(
long double val)
273 return RPadLength::User{(double)val};
275 inline RPadLength::User
operator"" _user(
unsigned long long int val)
277 return RPadLength::User{(double)val};