Krita Source Code Documentation
Loading...
Searching...
No Matches
Trajectory Class Reference

#include <trajectory.h>

Public Member Functions

QVector< QPointF > getDDATrajectory (QPointF start, QPointF end, double space)
 
const QVector< QPointF > & getLinearTrajectory (const QPointF &start, const QPointF &end, double space)
 
int size () const
 
 Trajectory ()
 
 ~Trajectory ()
 

Private Member Functions

void addPoint (QPointF pos)
 
void reset ()
 

Private Attributes

int m_i
 
QVector< QPointF > m_path
 
int m_size
 

Detailed Description

Definition at line 14 of file trajectory.h.

Constructor & Destructor Documentation

◆ Trajectory()

Trajectory::Trajectory ( )

Definition at line 12 of file trajectory.cpp.

13{
14 m_i = 0;
15 m_size = 0;
16}

References m_i, and m_size.

◆ ~Trajectory()

Trajectory::~Trajectory ( )

Definition at line 18 of file trajectory.cpp.

19{
20}

Member Function Documentation

◆ addPoint()

void Trajectory::addPoint ( QPointF pos)
private

Definition at line 23 of file trajectory.cpp.

24{
25 if (m_i >= m_path.size()) {
26 m_path.append(pos);
27 m_i++;
28 } else {
29 m_path[m_i] = pos;
30 m_i++;
31 }
32
33 m_size++;
34}
QVector< QPointF > m_path
Definition trajectory.h:28

References m_i, m_path, and m_size.

◆ getDDATrajectory()

QVector< QPointF > Trajectory::getDDATrajectory ( QPointF start,
QPointF end,
double space )

Definition at line 103 of file trajectory.cpp.

104{
105 Q_UNUSED(space);
106 reset();
107 // Width and height of the line
108 int xd = (int)(end.x() - start.x());
109 int yd = (int)(end.y() - start.y());
110
111 int x = (int)start.x();
112 int y = (int)start.y();
113 float fx = start.x();
114 float fy = start.y();
115 float m = (float)yd / (float)xd;
116 int y2 = (int)end.y();
117 int x2 = (int)end.x();
118
119 if (fabs(m) > 1) {
120 int incr;
121 if (yd > 0) {
122 m = 1.0f / m;
123 incr = 1;
124 }
125 else {
126 m = -1.0f / m;
127 incr = -1;
128 }
129 while (y != y2) {
130 fx = fx + m;
131 y = y + incr;
132 x = (int)(fx + 0.5f);
133 addPoint(QPointF(x, y));
134 }
135 } else {
136 int incr;
137 if (xd > 0) {
138 incr = 1;
139 }
140 else {
141 incr = -1;
142 m = -m;
143 }
144 while (x != x2) {
145 fy = fy + m;
146 x = x + incr;
147 y = (int)(fy + 0.5f);
148 addPoint(QPointF(x, y));
149 }
150 }
151
152 return m_path;
153}
void reset()
void addPoint(QPointF pos)

References addPoint(), m_path, and reset().

◆ getLinearTrajectory()

const QVector< QPointF > & Trajectory::getLinearTrajectory ( const QPointF & start,
const QPointF & end,
double space )

Definition at line 44 of file trajectory.cpp.

45{
46 Q_UNUSED(space);
47 reset();
48
49 // Width and height of the line
50 qreal xd = (end.x() - start.x());
51 qreal yd = (end.y() - start.y());
52
53 int x = (int)start.x();
54 int y = (int)start.y();
55 qreal fx = start.x();
56 qreal fy = start.y();
57 qreal m = yd / xd;
58
59 int y2 = (int)end.y();
60 int x2 = (int)end.x();
61
62 addPoint(start);
63
64 if (fabs(m) > 1) {
65 // y - directional axis
66 int incr;
67 if (yd > 0) {
68 m = 1.0f / m;
69 incr = 1;
70 } else {
71 m = -1.0f / m;
72 incr = -1;
73 }
74 while (y != y2) {
75 fx = fx + m;
76 fy = fy + incr;
77 y += incr;
78// x = (int)(fx + 0.5f);
79 addPoint(QPointF(fx, fy));
80 }
81 } else {
82 // x - directional axis
83 int incr;
84 if (xd > 0) {
85 incr = 1;
86 } else {
87 incr = -1;
88 m = -m;
89 }
90 while (x != x2) {
91 fy = fy + m;
92 fx = fx + incr;
93 x += incr;
94// y = (int)(fy + 0.5f);
95 addPoint(QPointF(fx, fy));
96 }
97 }
98
99 addPoint(end);
100 return m_path;
101}

References addPoint(), m_path, and reset().

◆ reset()

void Trajectory::reset ( )
private

Definition at line 37 of file trajectory.cpp.

38{
39 m_size = 0;
40 m_i = 0;
41}

References m_i, and m_size.

◆ size()

int Trajectory::size ( ) const
inline

Definition at line 23 of file trajectory.h.

23 {
24 return m_size;
25 }

References m_size.

Member Data Documentation

◆ m_i

int Trajectory::m_i
private

Definition at line 29 of file trajectory.h.

◆ m_path

QVector<QPointF> Trajectory::m_path
private

Definition at line 28 of file trajectory.h.

◆ m_size

int Trajectory::m_size
private

Definition at line 30 of file trajectory.h.


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