Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CallbackBoundingRects.cpp
Go to the documentation of this file.
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 
8 #include "EngaugeAssert.h"
9 #include "Logger.h"
10 #include "Point.h"
11 #include <qmath.h>
12 #include "QtToString.h"
13 #include "Transformation.h"
14 
16  const Transformation &transformation) :
17  m_documentAxesPointsRequired (documentAxesPointsRequired),
18  m_isEmptyGraphX (true),
19  m_isEmptyGraphY (true),
20  m_isEmptyScreenX (true),
21  m_isEmptyScreenY (true),
22  m_transformation (transformation)
23 {
24 }
25 
26 QPointF CallbackBoundingRects::boundingRectGraphMax (bool &isEmpty) const
27 {
28  // Need both X and Y before results are useful
29  isEmpty = m_isEmptyGraphX || m_isEmptyGraphY;
30 
31  return m_boundingRectGraphMax;
32 }
33 
34 QPointF CallbackBoundingRects::boundingRectGraphMin (bool &isEmpty) const
35 {
36  // Need both X and Y before results are useful
37  isEmpty = m_isEmptyGraphX || m_isEmptyGraphY;
38 
39  return m_boundingRectGraphMin;
40 }
41 
42 QRectF CallbackBoundingRects::boundingRectScreen (bool &isEmpty) const
43 {
44  // Need both X and Y before results are useful
45  isEmpty = m_isEmptyScreenX || m_isEmptyScreenY;
46 
47  return QRectF (m_boundingRectScreenMin,
48  m_boundingRectScreenMax).normalized();
49 }
50 
52  const Point &point)
53 {
54  QPointF posGraph;
55  bool haveGraphX = true, haveGraphY = true;
56  if (curveName == AXIS_CURVE_NAME) {
57  posGraph = point.posGraph(); // Axis point has graph coordinates
58 
59  haveGraphX = (m_documentAxesPointsRequired != DOCUMENT_AXES_POINTS_REQUIRED_4) || point.isXOnly();
60  haveGraphY = (m_documentAxesPointsRequired != DOCUMENT_AXES_POINTS_REQUIRED_4) || !point.isXOnly();
61 
62  } else {
63  m_transformation.transformScreenToRawGraph (point.posScreen(),
64  posGraph); // Curve point has undefined graph coordinates, but they can be calculated
65  }
66 
67  if (haveGraphX) {
68  mergeCoordinateX (posGraph,
69  m_boundingRectGraphMin,
70  m_boundingRectGraphMax,
71  m_isEmptyGraphX);
72  }
73  if (haveGraphY) {
74  mergeCoordinateY (posGraph,
75  m_boundingRectGraphMin,
76  m_boundingRectGraphMax,
77  m_isEmptyGraphY);
78  }
79  mergeCoordinateX (point.posScreen(),
80  m_boundingRectScreenMin,
81  m_boundingRectScreenMax,
82  m_isEmptyScreenX);
83  mergeCoordinateY (point.posScreen(),
84  m_boundingRectScreenMin,
85  m_boundingRectScreenMax,
86  m_isEmptyScreenY);
87 
89 }
90 
91 void CallbackBoundingRects::mergeCoordinateX (const QPointF &pos,
92  QPointF &boundingRectMin,
93  QPointF &boundingRectMax,
94  bool &isEmpty)
95 {
96  bool newGraphMin = isEmpty;
97  bool newGraphMax = isEmpty;
98 
99  if (!newGraphMin) {
100  newGraphMin = (pos.x() < boundingRectMin.x());
101  }
102  if (!newGraphMax) {
103  newGraphMax = (boundingRectMax.x() < pos.x());
104  }
105 
106  if (newGraphMin) {
107  boundingRectMin.setX (pos.x());
108  }
109  if (newGraphMax) {
110  boundingRectMax.setX (pos.x());
111  }
112 
113  isEmpty = false;
114 }
115 
116 void CallbackBoundingRects::mergeCoordinateY (const QPointF &pos,
117  QPointF &boundingRectMin,
118  QPointF &boundingRectMax,
119  bool &isEmpty)
120 {
121  bool newGraphMin = isEmpty;
122  bool newGraphMax = isEmpty;
123 
124  if (!newGraphMin) {
125  newGraphMin = (pos.y() < boundingRectMin.y());
126  }
127  if (!newGraphMax) {
128  newGraphMax = (boundingRectMax.y() < pos.y());
129  }
130 
131  if (newGraphMin) {
132  boundingRectMin.setY (pos.y());
133  }
134  if (newGraphMax) {
135  boundingRectMax.setY (pos.y());
136  }
137 
138  isEmpty = false;
139 }
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
QPointF posGraph(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Accessor for graph position. Skip check if copying one instance to another.
Definition: Point.cpp:395
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
Definition: Point.h:25
QPointF posScreen() const
Accessor for screen position.
Definition: Point.cpp:404
CallbackSearchReturn
Return values for search callback methods.
QPointF boundingRectGraphMax(bool &isEmpty) const
Graph coordinate bounding rectangle&#39;s (xmax,ymax) corner.
CallbackBoundingRects(DocumentAxesPointsRequired documentAxesPointsRequired, const Transformation &transformation)
Single constructor.
Continue normal execution of the search.
Affine transformation between screen and graph coordinates, based on digitized axis points...
bool isXOnly() const
In DOCUMENT_AXES_POINTS_REQUIRED_4 modes, this is true/false if y/x coordinate is undefined...
Definition: Point.cpp:286
QPointF boundingRectGraphMin(bool &isEmpty) const
Graph coordinate bounding rectangle&#39;s (xmin,ymin) corner.
QRectF boundingRectScreen(bool &isEmpty) const
Screen coordinate bounding rectangle.
DocumentAxesPointsRequired
const QString AXIS_CURVE_NAME