Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
CallbackPointOrdinal.cpp
1 #include "CallbackPointOrdinal.h"
2 #include "EngaugeAssert.h"
3 #include "Logger.h"
4 #include "mmsubs.h"
5 #include "Point.h"
6 #include <qmath.h>
7 #include "Transformation.h"
8 
10  const Transformation &transformation,
11  const QPointF &posScreen) :
12  m_lineStyle (lineStyle),
13  m_transformation (transformation),
14  m_posScreen (posScreen),
15  m_haveMinimumDistanceToLine (false),
16  m_minimumDistanceToLine (0.0),
17  m_minimumProjectedDistanceOutsideLine (0.0),
18  m_ordinal (0)
19 {
20 }
21 
23  const Point &pointStop)
24 {
25  double xProjection, yProjection, projectedDistanceOutsideLine, distanceToLine;
26 
27  projectPointOntoLine(m_posScreen.x(),
28  m_posScreen.y(),
29  pointStart.posScreen().x(),
30  pointStart.posScreen().y(),
31  pointStop.posScreen().x(),
32  pointStop.posScreen().y(),
33  &xProjection,
34  &yProjection,
35  &projectedDistanceOutsideLine,
36  &distanceToLine);
37 
38  // Compare to best so far
39  if (!m_haveMinimumDistanceToLine ||
40  (distanceToLine < m_minimumDistanceToLine) ||
41  (distanceToLine == m_minimumDistanceToLine && projectedDistanceOutsideLine < m_minimumProjectedDistanceOutsideLine)) {
42 
43  // Compute ordinal
44  if (projectedDistanceOutsideLine == 0) {
45 
46  // Put new point inside the line segment
47  m_ordinal = (pointStart.ordinal() + pointStop.ordinal()) / 2.0;
48 
49  } else {
50 
51  // Put new point just outside the line segment
52  double distanceProjectionToStart = qSqrt ((xProjection - pointStart.posScreen().x()) * (xProjection - pointStart.posScreen().x()) +
53  (yProjection - pointStart.posScreen().y()) * (yProjection - pointStart.posScreen().y()));
54  double distanceProjectionToStop = qSqrt ((xProjection - pointStop.posScreen().x()) * (xProjection - pointStop.posScreen().x()) +
55  (yProjection - pointStop.posScreen().y()) * (yProjection - pointStop.posScreen().y()));
56  if (distanceProjectionToStart < distanceProjectionToStop) {
57 
58  // Before start point
59  m_ordinal = pointStart.ordinal() - 0.5;
60 
61  } else {
62 
63  // After stop point
64  m_ordinal = pointStop.ordinal() + 0.5;
65  }
66  }
67 
68  // Save as new 'best'
69  m_haveMinimumDistanceToLine = true;
70  m_minimumDistanceToLine = distanceToLine;
71  m_minimumProjectedDistanceOutsideLine = projectedDistanceOutsideLine;
72  }
73 
75 }
76 
78 {
79  return m_ordinal;
80 }
double ordinal() const
Computed ordinal.
CallbackSearchReturn callback(const Point &pointStart, const Point &pointStop)
Callback method.
CallbackPointOrdinal(const LineStyle &lineStyle, const Transformation &transformation, const QPointF &posScreen)
Single constructor.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
Definition: Point.h:17
QPointF posScreen() const
Accessor for screen position.
Definition: Point.cpp:344
CallbackSearchReturn
Return values for search callback methods.
Continue normal execution of the search.
Affine transformation between screen and graph coordinates, based on digitized axis points...
Details for a specific Line.
Definition: LineStyle.h:13
double ordinal(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Get method for ordinal. Skip check if copying one instance to another.
Definition: Point.cpp:326