Logo ROOT   6.14/05
Reference Guide
TPadLength.hxx
Go to the documentation of this file.
1 /// \file ROOT/TPadLength.hxx
2 /// \ingroup Gpad ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2017-07-06
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_TPadLength
17 #define ROOT7_TPadLength
18 
19 namespace ROOT {
20 namespace Experimental {
21 
22 /** \class ROOT::Experimental::TPadLength
23  A coordinate in a `TPad`.
24  */
25 
26 class TPadLength {
27 public:
28  template <class DERIVED>
29  struct CoordSysBase {
30  double fVal = 0.; ///< Coordinate value
31 
32  CoordSysBase() = default;
33  CoordSysBase(double val): fVal(val) {}
34  DERIVED &ToDerived() { return static_cast<DERIVED &>(*this); }
35 
36  DERIVED operator-() { return DERIVED(-fVal); }
37 
38  friend DERIVED operator+(DERIVED lhs, DERIVED rhs) { return DERIVED{lhs.fVal + rhs.fVal}; }
39  friend DERIVED operator-(DERIVED lhs, DERIVED rhs) { return DERIVED{lhs.fVal - rhs.fVal}; }
40  friend double operator/(DERIVED lhs, DERIVED rhs) { return lhs.fVal / rhs.fVal; }
41  DERIVED &operator+=(const DERIVED &rhs)
42  {
43  fVal += rhs.fVal;
44  return ToDerived();
45  }
46  DERIVED &operator-=(const DERIVED &rhs)
47  {
48  fVal -= rhs.fVal;
49  return ToDerived();
50  }
51  DERIVED &operator*=(double scale)
52  {
53  fVal *= scale;
54  return ToDerived();
55  }
56  friend DERIVED operator*(const DERIVED &lhs, double rhs) { return DERIVED(lhs.fVal * rhs); }
57  friend DERIVED operator*(double lhs, const DERIVED &rhs) { return DERIVED(lhs * rhs.fVal); }
58  friend DERIVED operator/(const DERIVED &lhs, double rhs) { return DERIVED(lhs.fVal * rhs); }
59  friend bool operator<(const DERIVED &lhs, const DERIVED &rhs) { return lhs.fVal < rhs.fVal; }
60  friend bool operator>(const DERIVED &lhs, const DERIVED &rhs) { return lhs.fVal > rhs.fVal; }
61  friend bool operator<=(const DERIVED &lhs, const DERIVED &rhs) { return lhs.fVal <= rhs.fVal; }
62  friend bool operator>=(const DERIVED &lhs, const DERIVED &rhs) { return lhs.fVal >= rhs.fVal; }
63  // no ==, !=
64  };
65 
66  /// \defgroup PadCoordSystems TPad coordinate systems
67  /// These define typesafe coordinates used by TPad to identify which coordinate system a coordinate is referring to.
68  /// The origin (0,0) is in the `TPad`'s bottom left corner for all of them.
69  /// \{
70 
71  /** \class Normal
72  A normalized coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the `TPad`. Resizing the pad
73  will resize the objects with it.
74  */
75  struct Normal: CoordSysBase<Normal> {
77  };
78 
79  /** \class Pixel
80  A pixel coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the `TPad`. Resizing the pad will
81  keep the pixel-position of the objects positioned in `Pixel` coordinates.
82  */
83  struct Pixel: CoordSysBase<Pixel> {
85  };
86 
87  /** \class User
88  A user coordinate, as defined by the EUserCoordSystem parameter of the `TPad`.
89  */
90  struct User: CoordSysBase<User> {
92  };
93  /// \}
94 
95  /// The normalized coordinate summand.
97 
98  /// The pixel coordinate summand.
100 
101  /// The user coordinate summand.
103 
104  /// Default constructor, initializing all coordinate parts to `0.`.
105  TPadLength() = default;
106 
107  /// Constructor from a `Normal` coordinate.
108  TPadLength(Normal normal): fNormal(normal) {}
109 
110  /// Constructor from a `Pixel` coordinate.
111  TPadLength(Pixel px): fPixel(px) {}
112 
113  /// Constructor from a `User` coordinate.
114  TPadLength(User user): fUser(user) {}
115 
116  /// Sort-of aggregate initialization constructor taking normal, pixel and user parts.
117  TPadLength(Normal normal, Pixel px, User user): fNormal(normal), fPixel(px), fUser(user) {}
118 
119  /// Add two `TPadLength`s.
120  friend TPadLength operator+(TPadLength lhs, const TPadLength &rhs)
121  {
122  return TPadLength{lhs.fNormal + rhs.fNormal, lhs.fPixel + rhs.fPixel, lhs.fUser + rhs.fUser};
123  }
124 
125  /// Subtract two `TPadLength`s.
126  friend TPadLength operator-(TPadLength lhs, const TPadLength &rhs)
127  {
128  return TPadLength{lhs.fNormal - rhs.fNormal, lhs.fPixel - rhs.fPixel, lhs.fUser - rhs.fUser};
129  }
130 
131  /// Unary -.
133  return TPadLength(-fNormal, -fPixel, -fUser);
134  }
135 
136  /// Add a `TPadLength`.
138  {
139  fNormal += rhs.fNormal;
140  fPixel += rhs.fPixel;
141  fUser += rhs.fUser;
142  return *this;
143  };
144 
145  /// Subtract a `TPadLength`.
147  {
148  fNormal -= rhs.fNormal;
149  fPixel -= rhs.fPixel;
150  fUser -= rhs.fUser;
151  return *this;
152  };
153 
154  TPadLength &operator*=(double scale)
155  {
156  fNormal *= scale;
157  fPixel *= scale;
158  fUser *= scale;
159  return *this;
160  }
161 };
162 
163 /// User-defined literal for `TPadLength::Normal`
164 ///
165 /// Use as
166 /// ```
167 /// using namespace ROOT::Experimental;
168 /// TLine(0.1_normal, 0.0_normal, TLineExtent(0.2_normal, 0.5_normal));
169 /// ```
170 inline TPadLength::Normal operator"" _normal(long double val)
171 {
172  return TPadLength::Normal{(double)val};
173 }
174 inline TPadLength::Normal operator"" _normal(unsigned long long int val)
175 {
176  return TPadLength::Normal{(double)val};
177 }
178 
179 /// User-defined literal for `TPadLength::Pixel`
180 ///
181 /// Use as
182 /// ```
183 /// using namespace ROOT::Experimental;
184 /// TLine(100_px, 0_px, TLineExtent(20_px, 50_px));
185 /// ```
186 inline TPadLength::Pixel operator"" _px(long double val)
187 {
188  return TPadLength::Pixel{(double)val};
189 }
190 inline TPadLength::Pixel operator"" _px(unsigned long long int val)
191 {
192  return TPadLength::Pixel{(double)val};
193 }
194 
195 /// User-defined literal for `TPadLength::User`
196 ///
197 /// Use as
198 /// ```
199 /// using namespace ROOT::Experimental;
200 /// TLine(0.1_user, 0.0_user, TLineExtent(0.2_user, 0.5_user));
201 /// ```
202 inline TPadLength::User operator"" _user(long double val)
203 {
204  return TPadLength::User{(double)val};
205 }
206 inline TPadLength::User operator"" _user(unsigned long long int val)
207 {
208  return TPadLength::User{(double)val};
209 }
210 
211 } // namespace Experimental
212 } // namespace ROOT
213 
214 #endif
friend DERIVED operator*(double lhs, const DERIVED &rhs)
Definition: TPadLength.hxx:57
A normalized coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the TPad...
Definition: TPadLength.hxx:75
TPadLength(Normal normal, Pixel px, User user)
Sort-of aggregate initialization constructor taking normal, pixel and user parts. ...
Definition: TPadLength.hxx:117
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
TPadLength & operator*=(double scale)
Definition: TPadLength.hxx:154
friend DERIVED operator*(const DERIVED &lhs, double rhs)
Definition: TPadLength.hxx:56
friend DERIVED operator+(DERIVED lhs, DERIVED rhs)
Definition: TPadLength.hxx:38
Pixel fPixel
The pixel coordinate summand.
Definition: TPadLength.hxx:99
DERIVED & operator+=(const DERIVED &rhs)
Definition: TPadLength.hxx:41
friend bool operator>=(const DERIVED &lhs, const DERIVED &rhs)
Definition: TPadLength.hxx:62
TPadLength & operator+=(const TPadLength &rhs)
Add a TPadLength.
Definition: TPadLength.hxx:137
TPadLength(User user)
Constructor from a User coordinate.
Definition: TPadLength.hxx:114
Normal fNormal
The normalized coordinate summand.
Definition: TPadLength.hxx:96
TPadLength operator-()
Unary -.
Definition: TPadLength.hxx:132
A user coordinate, as defined by the EUserCoordSystem parameter of the TPad.
Definition: TPadLength.hxx:90
friend DERIVED operator/(const DERIVED &lhs, double rhs)
Definition: TPadLength.hxx:58
friend TPadLength operator-(TPadLength lhs, const TPadLength &rhs)
Subtract two TPadLengths.
Definition: TPadLength.hxx:126
friend bool operator<=(const DERIVED &lhs, const DERIVED &rhs)
Definition: TPadLength.hxx:61
friend bool operator>(const DERIVED &lhs, const DERIVED &rhs)
Definition: TPadLength.hxx:60
friend bool operator<(const DERIVED &lhs, const DERIVED &rhs)
Definition: TPadLength.hxx:59
TPadLength(Pixel px)
Constructor from a Pixel coordinate.
Definition: TPadLength.hxx:111
TPadLength(Normal normal)
Constructor from a Normal coordinate.
Definition: TPadLength.hxx:108
TPadLength()=default
Default constructor, initializing all coordinate parts to 0..
friend TPadLength operator+(TPadLength lhs, const TPadLength &rhs)
Add two TPadLengths.
Definition: TPadLength.hxx:120
friend double operator/(DERIVED lhs, DERIVED rhs)
Definition: TPadLength.hxx:40
A coordinate in a TPad.
Definition: TPadLength.hxx:26
DERIVED & operator-=(const DERIVED &rhs)
Definition: TPadLength.hxx:46
User fUser
The user coordinate summand.
Definition: TPadLength.hxx:102
TPadLength & operator-=(const TPadLength &rhs)
Subtract a TPadLength.
Definition: TPadLength.hxx:146
A pixel coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the TPad...
Definition: TPadLength.hxx:83
friend DERIVED operator-(DERIVED lhs, DERIVED rhs)
Definition: TPadLength.hxx:39