1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released      *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission.     *
5  ******************************************************************************************************/
6 
7 #ifndef CALLBACK_BOUNDING_RECTS_H
8 #define CALLBACK_BOUNDING_RECTS_H
9 
10 #include "CallbackSearchReturn.h"
11 #include "DocumentAxesPointsRequired.h"
12 #include <QPointF>
13 #include <QRectF>
14 #include <QString>
15 #include "Transformation.h"
16 
17 class Point;
18 
19 /// Callback for computing the bounding rectangles of the screen and graph coordinates of the points in the Document.
20 class CallbackBoundingRects
21 {
22 public:
23   /// Single constructor
24   CallbackBoundingRects(DocumentAxesPointsRequired documentAxesPointsRequired,
25                         const Transformation &transformation);
26 
27   /// Graph coordinate bounding rectangle's (xmin,ymin) corner. QRectF is not returned since it rounds
28   /// off the smaller coordinates to zero when large dynamic ranges appear, and those zeros
29   /// break the log scale algorithm
30   QPointF boundingRectGraphMin (bool &isEmpty) const;
31 
32   /// Graph coordinate bounding rectangle's (xmax,ymax) corner. QRectF is not returned since it rounds
33   /// off the smaller coordinates to zero when large dynamic ranges appear, and those zeros
34   /// break the log scale algorithm
35   QPointF boundingRectGraphMax (bool &isEmpty) const;
36 
37   /// Screen coordinate bounding rectangle
38   QRectF boundingRectScreen (bool &isEmpty) const;
39 
40   /// Callback method.
41   CallbackSearchReturn callback (const QString &curveName,
42                                  const Point &point);
43 
44 private:
45   CallbackBoundingRects();
46 
47   void mergeCoordinateX (const QPointF &pos,
48                          QPointF &boundingRectMin,
49                          QPointF &boundingRectMax,
50                          bool &isEmpty);
51   void mergeCoordinateY (const QPointF &pos,
52                          QPointF &boundingRectMin,
53                          QPointF &boundingRectMax,
54                          bool &isEmpty);
55 
56   DocumentAxesPointsRequired m_documentAxesPointsRequired;
57   bool m_isEmptyGraphX; // Have x graph bounds been initialized
58   bool m_isEmptyGraphY; // Have y graph bounds been initialized
59   bool m_isEmptyScreenX; // Have x screen bounds been initialized
60   bool m_isEmptyScreenY; // Have y screen bounds been initialized
61   const Transformation m_transformation;
62   QPointF m_boundingRectGraphMin; // Not a QRectF for reasons explained by boundingRectGraphMin
63   QPointF m_boundingRectGraphMax; // Not a QRectF for reasons explained by boundingRectGraphMax
64   QPointF m_boundingRectScreenMin; // Consistent with m_boundingRectGraphMin
65   QPointF m_boundingRectScreenMax; // Consistent with m_boundingRectGraphMax
66 };
67 
68 #endif // CALLBACK_BOUNDING_RECTS_H
69