Logo ROOT   6.12/07
Reference Guide
TPadCoord.hxx
Go to the documentation of this file.
1 /// \file ROOT/TPadCoord.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_TPadCoord
17 #define ROOT7_TPadCoord
18 
19 namespace ROOT {
20 namespace Experimental {
21 
22 /** \class ROOT::Experimental::TPadCoord
23  A coordinate in a `TPad`.
24  */
25 
26 class TPadCoord {
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 bool operator<(const DERIVED &lhs, const DERIVED &rhs) { return lhs.fVal < rhs.fVal; }
57  friend bool operator>(const DERIVED &lhs, const DERIVED &rhs) { return lhs.fVal > rhs.fVal; }
58  friend bool operator<=(const DERIVED &lhs, const DERIVED &rhs) { return lhs.fVal <= rhs.fVal; }
59  friend bool operator>=(const DERIVED &lhs, const DERIVED &rhs) { return lhs.fVal >= rhs.fVal; }
60  // no ==, !=
61  };
62 
63  /// \defgroup PadCoordSystems TPad coordinate systems
64  /// These define typesafe coordinates used by TPad to identify which coordinate system a coordinate is referring to.
65  /// The origin (0,0) is in the `TPad`'s bottom left corner for all of them.
66  /// \{
67 
68  /** \class Normal
69  A normalized coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the `TPad`. Resizing the pad
70  will resize the objects with it.
71  */
72  struct Normal: CoordSysBase<Normal> {
74  };
75 
76  /** \class Pixel
77  A pixel coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the `TPad`. Resizing the pad will
78  keep the pixel-position of the objects positioned in `Pixel` coordinates.
79  */
80  struct Pixel: CoordSysBase<Pixel> {
82  };
83 
84  /** \class User
85  A user coordinate, as defined by the EUserCoordSystem parameter of the `TPad`.
86  */
87  struct User: CoordSysBase<User> {
89  };
90  /// \}
91 
92  /// The normalized coordinate summand.
94 
95  /// The pixel coordinate summand.
97 
98  /// The user coordinate summand.
100 
101  /// Default constructor, initializing all coordinate parts to `0.`.
102  TPadCoord() = default;
103 
104  /// Constructor from a `Normal` coordinate.
105  TPadCoord(Normal normal): fNormal(normal) {}
106 
107  /// Constructor from a `Pixel` coordinate.
108  TPadCoord(Pixel px): fPixel(px) {}
109 
110  /// Constructor from a `User` coordinate.
111  TPadCoord(User user): fUser(user) {}
112 
113  /// Sort-of aggregate initialization constructor taking normal, pixel and user parts.
114  TPadCoord(Normal normal, Pixel px, User user): fNormal(normal), fPixel(px), fUser(user) {}
115 
116  /// Add two `TPadCoord`s.
117  friend TPadCoord operator+(TPadCoord lhs, const TPadCoord &rhs)
118  {
119  return TPadCoord{lhs.fNormal + rhs.fNormal, lhs.fPixel + rhs.fPixel, lhs.fUser + rhs.fUser};
120  }
121 
122  /// Subtract two `TPadCoord`s.
123  friend TPadCoord operator-(TPadCoord lhs, const TPadCoord &rhs)
124  {
125  return TPadCoord{lhs.fNormal - rhs.fNormal, lhs.fPixel - rhs.fPixel, lhs.fUser - rhs.fUser};
126  }
127 
128  /// Unary -.
130  return TPadCoord(-fNormal, -fPixel, -fUser);
131  }
132 
133  /// Add a `TPadCoord`.
135  {
136  fNormal += rhs.fNormal;
137  fPixel += rhs.fPixel;
138  fUser += rhs.fUser;
139  return *this;
140  };
141 
142  /// Subtract a `TPadCoord`.
144  {
145  fNormal -= rhs.fNormal;
146  fPixel -= rhs.fPixel;
147  fUser -= rhs.fUser;
148  return *this;
149  };
150 
151  TPadCoord &operator*=(double scale)
152  {
153  fNormal *= scale;
154  fPixel *= scale;
155  fUser *= scale;
156  return *this;
157  }
158 };
159 
160 /// User-defined literal for `TPadCoord::Normal`
161 ///
162 /// Use as
163 /// ```
164 /// using namespace ROOT::Experimental;
165 /// TLine(0.1_normal, 0.0_normal, TLineExtent(0.2_normal, 0.5_normal));
166 /// ```
167 inline TPadCoord::Normal operator"" _normal(long double val)
168 {
169  return TPadCoord::Normal{(double)val};
170 }
171 inline TPadCoord::Normal operator"" _normal(unsigned long long int val)
172 {
173  return TPadCoord::Normal{(double)val};
174 }
175 
176 /// User-defined literal for `TPadCoord::Pixel`
177 ///
178 /// Use as
179 /// ```
180 /// using namespace ROOT::Experimental;
181 /// TLine(100_px, 0_px, TLineExtent(20_px, 50_px));
182 /// ```
183 inline TPadCoord::Pixel operator"" _px(long double val)
184 {
185  return TPadCoord::Pixel{(double)val};
186 }
187 inline TPadCoord::Pixel operator"" _px(unsigned long long int val)
188 {
189  return TPadCoord::Pixel{(double)val};
190 }
191 
192 /// User-defined literal for `TPadCoord::User`
193 ///
194 /// Use as
195 /// ```
196 /// using namespace ROOT::Experimental;
197 /// TLine(0.1_user, 0.0_user, TLineExtent(0.2_user, 0.5_user));
198 /// ```
199 inline TPadCoord::User operator"" _user(long double val)
200 {
201  return TPadCoord::User{(double)val};
202 }
203 inline TPadCoord::User operator"" _user(unsigned long long int val)
204 {
205  return TPadCoord::User{(double)val};
206 }
207 
208 } // namespace Experimental
209 } // namespace ROOT
210 
211 #endif
friend bool operator>(const DERIVED &lhs, const DERIVED &rhs)
Definition: TPadCoord.hxx:57
TPadCoord(User user)
Constructor from a User coordinate.
Definition: TPadCoord.hxx:111
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Normal fNormal
The normalized coordinate summand.
Definition: TPadCoord.hxx:93
A user coordinate, as defined by the EUserCoordSystem parameter of the TPad.
Definition: TPadCoord.hxx:87
DERIVED & operator-=(const DERIVED &rhs)
Definition: TPadCoord.hxx:46
A pixel coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the TPad...
Definition: TPadCoord.hxx:80
friend bool operator<=(const DERIVED &lhs, const DERIVED &rhs)
Definition: TPadCoord.hxx:58
TPadCoord & operator-=(const TPadCoord &rhs)
Subtract a TPadCoord.
Definition: TPadCoord.hxx:143
TPadCoord(Pixel px)
Constructor from a Pixel coordinate.
Definition: TPadCoord.hxx:108
friend bool operator<(const DERIVED &lhs, const DERIVED &rhs)
Definition: TPadCoord.hxx:56
friend TPadCoord operator+(TPadCoord lhs, const TPadCoord &rhs)
Add two TPadCoords.
Definition: TPadCoord.hxx:117
TPadCoord()=default
Default constructor, initializing all coordinate parts to 0..
Pixel fPixel
The pixel coordinate summand.
Definition: TPadCoord.hxx:96
TPadCoord(Normal normal)
Constructor from a Normal coordinate.
Definition: TPadCoord.hxx:105
TPadCoord & operator+=(const TPadCoord &rhs)
Add a TPadCoord.
Definition: TPadCoord.hxx:134
friend DERIVED operator-(DERIVED lhs, DERIVED rhs)
Definition: TPadCoord.hxx:39
friend TPadCoord operator-(TPadCoord lhs, const TPadCoord &rhs)
Subtract two TPadCoords.
Definition: TPadCoord.hxx:123
friend DERIVED operator+(DERIVED lhs, DERIVED rhs)
Definition: TPadCoord.hxx:38
friend double operator/(DERIVED lhs, DERIVED rhs)
Definition: TPadCoord.hxx:40
User fUser
The user coordinate summand.
Definition: TPadCoord.hxx:99
friend bool operator>=(const DERIVED &lhs, const DERIVED &rhs)
Definition: TPadCoord.hxx:59
TPadCoord & operator*=(double scale)
Definition: TPadCoord.hxx:151
A normalized coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the TPad...
Definition: TPadCoord.hxx:72
TPadCoord operator-()
Unary -.
Definition: TPadCoord.hxx:129
def normal(shape, name=None)
DERIVED & operator+=(const DERIVED &rhs)
Definition: TPadCoord.hxx:41
A coordinate in a TPad.
Definition: TPadCoord.hxx:26
TPadCoord(Normal normal, Pixel px, User user)
Sort-of aggregate initialization constructor taking normal, pixel and user parts. ...
Definition: TPadCoord.hxx:114