-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.h
141 lines (88 loc) · 2.42 KB
/
model.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#ifndef MODEL_H
#define MODEL_H
#include <iostream>
#include <math.h>
#include <algorithm>
#include <time.h>
#include <QGraphicsScene>
#include <QGraphicsRectItem>
#include <QGraphicsLineItem>
#include <QGraphicsEllipseItem>
#include <QTimer>
#include <vector>
#include "voronoi.h"
#include "vpoint.h"
#define MAX_NUM_OF_POINTS 100
#define ANIMATION_SPEED 1.0
#define ANIMATION_FPS 60
#define POINT_SIZE 5.0
#define PARABOLA_DRAW_STEP 3.0
#define PARABOLA_PRECISION 5.0
#define COLOR_DIAGRAM Qt::black
#define COLOR_BEACH_LINE Qt::green
#define COLOR_EVENT Qt::blue
using namespace vor;
class MainWindow;
class Model : QObject
{
Q_OBJECT
private:
MainWindow *window;
Voronoi *voronoi;
Vertices *vertices;
Edges *edges;
EventsData eventsData;
double width;
double height;
int numOfPoints;
double animationParameter;
QGraphicsScene *scene;
std::vector <QGraphicsItem *> toDeleteFromScene;
QTimer timer;
bool animationOngoing;
bool animationToOngoing;
double animateToY;
EventsData::iterator FindEventData(double y);
public:
Model(MainWindow *window, int w, int h);
double Width() const;
void SetWidth(double w);
double Height() const;
void SetHeight(double h);
int NumOfPoints() const;
double MinHeight() const;
double GetYFromAP(double ap);
double GetAPFromY(double y);
double ModelToDisplayX(double x);
double ModelToDisplayY(double y);
double DisplayToModelY(double y);
void SetNumOfPoints(int n);
void SetAnimationParameter(double ap, bool updateSlider = true);
double AnimationParameter() const;
QGraphicsScene *Scene();
QTimer *Timer();
bool AnimationOngoing() const;
void SetAnimationOngoing(bool ao);
void SetAnimateTo(double at);
bool AnimationToOngoing() const;
void SetAnimationToOngoing(bool ato);
void Clear(bool clearAll = false);
void Init();
void Display(bool clearAll = false);
void DrawPoint(VPoint *point, bool isMarked = false, bool isEvent = false);
void DrawLine(const VEdge *edge);
void DrawLine(
double startX,
double startY,
double endX,
double endY,
bool isBeachLine = false);
void AnimateToPrevious();
void AnimateToNext();
void AnimateTo(double y);
void AddPoint(double x, double y);
public slots:
void Animate();
void AnimateTo();
};
#endif // MODEL_H