Engauge Digitizer  2
CallbackBoundingRects.cpp
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 #include "CallbackBoundingRects.h"
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  m_isEmpty (true),
17  m_transformation (transformation)
18 {
19 }
20 
21 QRectF CallbackBoundingRects::boundingRectGraph (bool &isEmpty) const
22 {
23  isEmpty = m_isEmpty;
24 
25  return m_boundingRectGraph;
26 }
27 
28 QRectF CallbackBoundingRects::boundingRectScreen (bool &isEmpty) const
29 {
30  isEmpty = m_isEmpty;
31 
32  return m_boundingRectScreen;
33 }
34 
35 CallbackSearchReturn CallbackBoundingRects::callback (const QString &curveName,
36  const Point &point)
37 {
38  QPointF posGraph;
39  if (curveName == AXIS_CURVE_NAME) {
40  posGraph = point.posGraph(); // Axis point has graph coordinates
41  } else {
42  m_transformation.transformScreenToRawGraph (point.posScreen(),
43  posGraph); // Curve point has undefined graph coordinates, but they can be calculated
44  }
45  mergeCoordinates (posGraph,
46  m_boundingRectGraph);
47  mergeCoordinates (point.posScreen(),
48  m_boundingRectScreen);
49 
50  m_isEmpty = false; // Set this after the calls to mergeCoordinates which uses it
51 
52  return CALLBACK_SEARCH_RETURN_CONTINUE;
53 }
54 
55 void CallbackBoundingRects::mergeCoordinates (const QPointF &pos,
56  QRectF &boundingRect)
57 {
58  bool newGraphLeft = m_isEmpty;
59  bool newGraphTop = m_isEmpty;
60  bool newGraphRight = m_isEmpty;
61  bool newGraphBottom = m_isEmpty;
62 
63  if (!newGraphLeft) {
64  newGraphLeft = (pos.x() < boundingRect.left());
65  }
66  if (!newGraphTop) {
67  newGraphTop = (pos.y() < boundingRect.top());
68  }
69  if (!newGraphRight) {
70  newGraphRight = (boundingRect.right() < pos.x());
71  }
72  if (!newGraphBottom) {
73  newGraphBottom = (boundingRect.bottom() < pos.y());
74  }
75 
76  if (newGraphLeft) {
77  boundingRect.setLeft (pos.x());
78  }
79  if (newGraphTop) {
80  boundingRect.setTop (pos.y());
81  }
82  if (newGraphRight) {
83  boundingRect.setRight (pos.x());
84  }
85  if (newGraphBottom) {
86  boundingRect.setBottom (pos.y());
87  }
88 }
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
QRectF boundingRectScreen(bool &isEmpty) const
Screen coordinate bounding rectangle.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
Definition: Point.h:23
QPointF posScreen() const
Accessor for screen position.
Definition: Point.cpp:392
Affine transformation between screen and graph coordinates, based on digitized axis points...
QPointF posGraph(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Accessor for graph position. Skip check if copying one instance to another.
Definition: Point.cpp:383
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
QRectF boundingRectGraph(bool &isEmpty) const
Graph coordinate bounding rectangle.
CallbackBoundingRects(const Transformation &transformation)
Single constructor.