Logo ROOT   6.18/05
Reference Guide
RPadLength.hxx
Go to the documentation of this file.
1/// \file ROOT/RPadLength.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_RPadLength
17#define ROOT7_RPadLength
18
19#include <string>
20
21namespace ROOT {
22namespace Experimental {
23
24/** \class ROOT::Experimental::RPadLength
25 A coordinate in a `RPad`.
26 */
27
29public:
30 template <class DERIVED>
31 struct CoordSysBase {
32 double fVal = 0.; ///< Coordinate value
33
34 CoordSysBase() = default;
35 CoordSysBase(double val): fVal(val) {}
36 DERIVED &ToDerived() { return static_cast<DERIVED &>(*this); }
37
38 DERIVED operator-() { return DERIVED(-fVal); }
39
40 friend DERIVED operator+(DERIVED lhs, DERIVED rhs) { return DERIVED{lhs.fVal + rhs.fVal}; }
41 friend DERIVED operator-(DERIVED lhs, DERIVED rhs) { return DERIVED{lhs.fVal - rhs.fVal}; }
42 friend double operator/(DERIVED lhs, DERIVED rhs) { return lhs.fVal / rhs.fVal; }
43 DERIVED &operator+=(const DERIVED &rhs)
44 {
45 fVal += rhs.fVal;
46 return ToDerived();
47 }
48 DERIVED &operator-=(const DERIVED &rhs)
49 {
50 fVal -= rhs.fVal;
51 return ToDerived();
52 }
53 DERIVED &operator*=(double scale)
54 {
55 fVal *= scale;
56 return ToDerived();
57 }
58 friend DERIVED operator*(const DERIVED &lhs, double rhs) { return DERIVED(lhs.fVal * rhs); }
59 friend DERIVED operator*(double lhs, const DERIVED &rhs) { return DERIVED(lhs * rhs.fVal); }
60 friend DERIVED operator/(const DERIVED &lhs, double rhs) { return DERIVED(lhs.fVal * rhs); }
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 friend bool operator<=(const DERIVED &lhs, const DERIVED &rhs) { return lhs.fVal <= rhs.fVal; }
64 friend bool operator>=(const DERIVED &lhs, const DERIVED &rhs) { return lhs.fVal >= rhs.fVal; }
65 // no ==, !=
66 };
67
68 /// \defgroup PadCoordSystems RPad coordinate systems
69 /// These define typesafe coordinates used by RPad to identify which coordinate system a coordinate is referring to.
70 /// The origin (0,0) is in the `RPad`'s bottom left corner for all of them.
71 /// \{
72
73 /** \class Normal
74 A normalized coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the `RPad`. Resizing the pad
75 will resize the objects with it.
76 */
77 struct Normal: CoordSysBase<Normal> {
79 };
80
81 /** \class Pixel
82 A pixel coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the `RPad`. Resizing the pad will
83 keep the pixel-position of the objects positioned in `Pixel` coordinates.
84 */
85 struct Pixel: CoordSysBase<Pixel> {
87 };
88
89 /** \class User
90 A user coordinate, as defined by the EUserCoordSystem parameter of the `RPad`.
91 */
92 struct User: CoordSysBase<User> {
94 };
95 /// \}
96
97 /// The normalized coordinate summand.
99
100 /// The pixel coordinate summand.
102
103 /// The user coordinate summand.
105
106 /// Default constructor, initializing all coordinate parts to `0.`.
107 RPadLength() = default;
108
109 /// Constructor from a `Normal` coordinate.
110 RPadLength(Normal normal): fNormal(normal) {}
111
112 /// Constructor from a `Pixel` coordinate.
114
115 /// Constructor from a `User` coordinate.
116 RPadLength(User user): fUser(user) {}
117
118 /// Sort-of aggregate initialization constructor taking normal, pixel and user parts.
119 RPadLength(Normal normal, Pixel px, User user): fNormal(normal), fPixel(px), fUser(user) {}
120
121 /// Add two `RPadLength`s.
123 {
124 return RPadLength{lhs.fNormal + rhs.fNormal, lhs.fPixel + rhs.fPixel, lhs.fUser + rhs.fUser};
125 }
126
127 /// Subtract two `RPadLength`s.
129 {
130 return RPadLength{lhs.fNormal - rhs.fNormal, lhs.fPixel - rhs.fPixel, lhs.fUser - rhs.fUser};
131 }
132
133 /// Unary -.
135 return RPadLength(-fNormal, -fPixel, -fUser);
136 }
137
138 /// Add a `RPadLength`.
140 {
141 fNormal += rhs.fNormal;
142 fPixel += rhs.fPixel;
143 fUser += rhs.fUser;
144 return *this;
145 };
146
147 /// Subtract a `RPadLength`.
149 {
150 fNormal -= rhs.fNormal;
151 fPixel -= rhs.fPixel;
152 fUser -= rhs.fUser;
153 return *this;
154 };
155
156 RPadLength &operator*=(double scale)
157 {
158 fNormal *= scale;
159 fPixel *= scale;
160 fUser *= scale;
161 return *this;
162 }
163
164 void SetFromAttrString(const std::string &val, const std::string &name);
165};
166
167/// User-defined literal for `RPadLength::Normal`
168///
169/// Use as
170/// ```
171/// using namespace ROOT::Experimental;
172/// RLine(0.1_normal, 0.0_normal, RLineExtent(0.2_normal, 0.5_normal));
173/// ```
174inline RPadLength::Normal operator"" _normal(long double val)
175{
176 return RPadLength::Normal{(double)val};
177}
178inline RPadLength::Normal operator"" _normal(unsigned long long int val)
179{
180 return RPadLength::Normal{(double)val};
181}
182
183/// User-defined literal for `RPadLength::Pixel`
184///
185/// Use as
186/// ```
187/// using namespace ROOT::Experimental;
188/// RLine(100_px, 0_px, RLineExtent(20_px, 50_px));
189/// ```
190inline RPadLength::Pixel operator"" _px(long double val)
191{
192 return RPadLength::Pixel{(double)val};
193}
194inline RPadLength::Pixel operator"" _px(unsigned long long int val)
195{
196 return RPadLength::Pixel{(double)val};
197}
198
199/// User-defined literal for `RPadLength::User`
200///
201/// Use as
202/// ```
203/// using namespace ROOT::Experimental;
204/// RLine(0.1_user, 0.0_user, RLineExtent(0.2_user, 0.5_user));
205/// ```
206inline RPadLength::User operator"" _user(long double val)
207{
208 return RPadLength::User{(double)val};
209}
210inline RPadLength::User operator"" _user(unsigned long long int val)
211{
212 return RPadLength::User{(double)val};
213}
214
215RPadLength FromAttributeString(const std::string &val, const std::string &name, RPadLength*);
216std::string ToAttributeString(const RPadLength &len);
217
218} // namespace Experimental
219} // namespace ROOT
220
221#endif
char name[80]
Definition: TGX11.cxx:109
A coordinate in a RPad.
Definition: RPadLength.hxx:28
friend RPadLength operator+(RPadLength lhs, const RPadLength &rhs)
Add two RPadLengths.
Definition: RPadLength.hxx:122
friend RPadLength operator-(RPadLength lhs, const RPadLength &rhs)
Subtract two RPadLengths.
Definition: RPadLength.hxx:128
RPadLength(User user)
Constructor from a User coordinate.
Definition: RPadLength.hxx:116
RPadLength(Normal normal, Pixel px, User user)
Sort-of aggregate initialization constructor taking normal, pixel and user parts.
Definition: RPadLength.hxx:119
RPadLength(Normal normal)
Constructor from a Normal coordinate.
Definition: RPadLength.hxx:110
RPadLength(Pixel px)
Constructor from a Pixel coordinate.
Definition: RPadLength.hxx:113
Pixel fPixel
The pixel coordinate summand.
Definition: RPadLength.hxx:101
User fUser
The user coordinate summand.
Definition: RPadLength.hxx:104
RPadLength & operator-=(const RPadLength &rhs)
Subtract a RPadLength.
Definition: RPadLength.hxx:148
RPadLength operator-()
Unary -.
Definition: RPadLength.hxx:134
RPadLength & operator*=(double scale)
Definition: RPadLength.hxx:156
RPadLength()=default
Default constructor, initializing all coordinate parts to 0..
RPadLength & operator+=(const RPadLength &rhs)
Add a RPadLength.
Definition: RPadLength.hxx:139
void SetFromAttrString(const std::string &val, const std::string &name)
Initialize a RPadLength from a style string.
Definition: RPadLength.cxx:163
Normal fNormal
The normalized coordinate summand.
Definition: RPadLength.hxx:98
std::string ToAttributeString(const RColor &val)
Return a std::string representation of a RColor, suitable as input to ColorFromString().
Definition: RColor.cxx:144
RColor FromAttributeString(const std::string &str, const std::string &name, RColor *)
Initialize a RColor from a string value.
Definition: RColor.cxx:132
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
friend bool operator>=(const DERIVED &lhs, const DERIVED &rhs)
Definition: RPadLength.hxx:64
friend double operator/(DERIVED lhs, DERIVED rhs)
Definition: RPadLength.hxx:42
friend bool operator<=(const DERIVED &lhs, const DERIVED &rhs)
Definition: RPadLength.hxx:63
friend DERIVED operator*(double lhs, const DERIVED &rhs)
Definition: RPadLength.hxx:59
friend bool operator>(const DERIVED &lhs, const DERIVED &rhs)
Definition: RPadLength.hxx:62
friend DERIVED operator*(const DERIVED &lhs, double rhs)
Definition: RPadLength.hxx:58
friend DERIVED operator/(const DERIVED &lhs, double rhs)
Definition: RPadLength.hxx:60
DERIVED & operator+=(const DERIVED &rhs)
Definition: RPadLength.hxx:43
friend DERIVED operator+(DERIVED lhs, DERIVED rhs)
Definition: RPadLength.hxx:40
friend DERIVED operator-(DERIVED lhs, DERIVED rhs)
Definition: RPadLength.hxx:41
friend bool operator<(const DERIVED &lhs, const DERIVED &rhs)
Definition: RPadLength.hxx:61
DERIVED & operator-=(const DERIVED &rhs)
Definition: RPadLength.hxx:48
A normalized coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the RPad.
Definition: RPadLength.hxx:77
A pixel coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the RPad.
Definition: RPadLength.hxx:85
A user coordinate, as defined by the EUserCoordSystem parameter of the RPad.
Definition: RPadLength.hxx:92