Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
CallbackPointOrdinal Class Reference

Callback for computing the ordinal for a specified point, as a function of the LineStyle and curve geometry. More...

#include <CallbackPointOrdinal.h>

Collaboration diagram for CallbackPointOrdinal:
Collaboration graph

Public Member Functions

 CallbackPointOrdinal (const LineStyle &lineStyle, const Transformation &transformation, const QPointF &posScreen)
 Single constructor. More...
 
CallbackSearchReturn callback (const Point &pointStart, const Point &pointStop)
 Callback method. More...
 
double ordinal () const
 Computed ordinal. More...
 

Detailed Description

Callback for computing the ordinal for a specified point, as a function of the LineStyle and curve geometry.

Definition at line 19 of file CallbackPointOrdinal.h.

Constructor & Destructor Documentation

CallbackPointOrdinal::CallbackPointOrdinal ( const LineStyle lineStyle,
const Transformation transformation,
const QPointF &  posScreen 
)

Single constructor.

Definition at line 15 of file CallbackPointOrdinal.cpp.

17  :
18  m_lineStyle (lineStyle),
19  m_transformation (transformation),
20  m_posScreen (posScreen),
21  m_haveMinimumDistanceToLine (false),
22  m_minimumDistanceToLine (0.0),
23  m_minimumProjectedDistanceOutsideLine (0.0),
24  m_ordinal (0)
25 {
26 }

Member Function Documentation

CallbackSearchReturn CallbackPointOrdinal::callback ( const Point pointStart,
const Point pointStop 
)

Callback method.

Definition at line 28 of file CallbackPointOrdinal.cpp.

30 {
31  double xProjection, yProjection, projectedDistanceOutsideLine, distanceToLine;
32 
33  projectPointOntoLine(m_posScreen.x(),
34  m_posScreen.y(),
35  pointStart.posScreen().x(),
36  pointStart.posScreen().y(),
37  pointStop.posScreen().x(),
38  pointStop.posScreen().y(),
39  &xProjection,
40  &yProjection,
41  &projectedDistanceOutsideLine,
42  &distanceToLine);
43 
44  // Compare the best so far
45  bool distancesAreEqual = (qAbs (distanceToLine - m_minimumDistanceToLine) <= 0); // Epsilon test prevents compiler warning
46  if (!m_haveMinimumDistanceToLine ||
47  (distanceToLine < m_minimumDistanceToLine) ||
48  (distancesAreEqual && projectedDistanceOutsideLine < m_minimumProjectedDistanceOutsideLine)) {
49 
50  // Compute ordinal using epsilon test to prevent compiler warning
51  if (qAbs (projectedDistanceOutsideLine) <= 0) {
52 
53  // Put new point inside the line segment
54  m_ordinal = (pointStart.ordinal() + pointStop.ordinal()) / 2.0;
55 
56  } else {
57 
58  // Put new point just outside the line segment
59  double distanceProjectionToStart = qSqrt ((xProjection - pointStart.posScreen().x()) * (xProjection - pointStart.posScreen().x()) +
60  (yProjection - pointStart.posScreen().y()) * (yProjection - pointStart.posScreen().y()));
61  double distanceProjectionToStop = qSqrt ((xProjection - pointStop.posScreen().x()) * (xProjection - pointStop.posScreen().x()) +
62  (yProjection - pointStop.posScreen().y()) * (yProjection - pointStop.posScreen().y()));
63  if (distanceProjectionToStart < distanceProjectionToStop) {
64 
65  // Before start point
66  m_ordinal = pointStart.ordinal() - 0.5;
67 
68  } else {
69 
70  // After stop point
71  m_ordinal = pointStop.ordinal() + 0.5;
72  }
73  }
74 
75  // Save as new 'best'
76  m_haveMinimumDistanceToLine = true;
77  m_minimumDistanceToLine = distanceToLine;
78  m_minimumProjectedDistanceOutsideLine = projectedDistanceOutsideLine;
79  }
80 
82 }
void projectPointOntoLine(double xToProject, double yToProject, double xStart, double yStart, double xStop, double yStop, double *xProjection, double *yProjection, double *projectedDistanceOutsideLine, double *distanceToLine)
Find the projection of a point onto a line segment such that the line through the point and its proje...
Definition: mmsubs.cpp:211
QPointF posScreen() const
Accessor for screen position.
Definition: Point.cpp:404
Continue normal execution of the search.
double ordinal(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Get method for ordinal. Skip check if copying one instance to another.
Definition: Point.cpp:386
double CallbackPointOrdinal::ordinal ( ) const

Computed ordinal.

Definition at line 84 of file CallbackPointOrdinal.cpp.

85 {
86  return m_ordinal;
87 }

The documentation for this class was generated from the following files: