Logo ROOT   6.12/07
Reference Guide
TPadLinearUserCoord.hxx
Go to the documentation of this file.
1 /// \file ROOT/TPadUserCoord.hxx
2 /// \ingroup Gpad ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2017-07-15
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_TPadLinearUserCoord
17 #define ROOT7_TPadLinearUserCoord
18 
20 
21 #include <array>
22 #include <limits>
23 
24 namespace ROOT {
25 namespace Experimental {
26 
27 namespace Detail {
28 
29 /** \class ROOT::Experimental::Detail::TPadLinearUserCoord
30  The default, linear min/max coordinate system for `TPad`, `TCanvas`.
31  */
32 
34 private:
35  std::array<double, 2> fMin; ///< (x,y) user coordinate of bottom-left corner
36  std::array<double, 2> fMax; ///< (x,y) user coordinate of top-right corner
37 
38  /// For (pos-min)/(max-min) calculations, return a sensible, div-by-0 protected denominator.
39  double GetDenominator(int idx) const
40  {
41  if (fMin[idx] < fMax[idx])
42  return std::max(std::numeric_limits<double>::min(), fMin[idx] - fMax[idx]);
43  return std::min(-std::numeric_limits<double>::min(), fMin[idx] - fMax[idx]);
44  }
45 
46 public:
47  /// Initialize a TPadLinearUserCoord.
48  TPadLinearUserCoord(const std::array<double, 2> &min, const std::array<double, 2> &max): fMin(min), fMax(max) {}
49 
50  /// Destructor to have a vtable.
51  virtual ~TPadLinearUserCoord();
52 
53  /// Convert user coordinates to normal coordinates.
54  std::array<TPadCoord::Normal, 2> ToNormal(const std::array<TPadCoord::User, 2> &pos) const override
55  {
56  return {{(pos[0] - fMin[0]) / GetDenominator(0), (pos[1] - fMin[1]) / GetDenominator(1)}};
57  }
58 };
59 
60 } // namespace Detail
61 } // namespace Experimental
62 } // namespace ROOT
63 
64 #endif
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
std::array< double, 2 > fMin
(x,y) user coordinate of bottom-left corner
double GetDenominator(int idx) const
For (pos-min)/(max-min) calculations, return a sensible, div-by-0 protected denominator.
The default, linear min/max coordinate system for TPad, TCanvas.
virtual ~TPadLinearUserCoord()
Destructor to have a vtable.
std::array< double, 2 > fMax
(x,y) user coordinate of top-right corner
std::array< TPadCoord::Normal, 2 > ToNormal(const std::array< TPadCoord::User, 2 > &pos) const override
Convert user coordinates to normal coordinates.
TPadLinearUserCoord(const std::array< double, 2 > &min, const std::array< double, 2 > &max)
Initialize a TPadLinearUserCoord.