-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvparabola.h
149 lines (116 loc) · 3.32 KB
/
vparabola.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
142
143
144
145
146
147
148
149
#ifndef VPARABOLA_H
#define VPARABOLA_H
#include "vpoint.h"
#include "vedge.h"
/*
* Parabolas and events have pointers to each other, so we declare class
* VEvent, which will be defined later.
*/
class VEvent;
class Model;
class QGraphicsScene;
/*
* A class that stores information about an item in beachline sequence (see
* Fortune's algorithm).
* It can represent an arch of parabola or an intersection between two archs
* (which defines an edge).
* In my implementation I build a binary tree with them (internal nodes are
* edges, leaves are archs).
*/
class VParabola
{
public:
/*
* isLeaf : flag whether the node is Leaf or internal node
* site : pointer to the focus point of parabola (when it is parabola)
* edge : pointer to the edge (when it is an edge)
* cEvent : pointer to the event, when the arch disappears (circle event)
* parent : pointer to the parent node in tree
*/
bool isLeaf;
VPoint *site;
VEdge *edge;
VEvent *cEvent;
VParabola *parent;
/*
* Constructors of the class (empty for edge, with focus parameter for an
* arch).
*/
VParabola();
VParabola(VPoint *s);
/*
* Functions for deep copying and deep deleting the entire tree.
*/
VParabola *DeepCopy() const;
void DeepDelete();
/*
* Functions for traversing the tree and displaying its elements.
*/
void Display(Model *model);
void Draw(Model *model, const VPoint *focus, double directrixHeight) const;
void DrawFromTo(
Model * model,
const VPoint * focus,
double directrixHeight,
double xFrom,
double xTo) const;
/*
* Access to the children (in tree).
*/
void SetLeft(VParabola *p)
{
_left = p;
p->parent = this;
}
void SetRight(VParabola *p)
{
_right = p;
p->parent = this;
}
VParabola *Left()
{
return _left;
}
VParabola *Right()
{
return _right;
}
const VParabola *Left() const
{
return _left;
}
const VParabola *Right() const
{
return _right;
}
/*
* Some useful tree operations
*
* GetLeft : returns the closest left leave of the tree
* GetRight : returns the closest right leafe of the tree
* GetLeftParent : returns the closest parent which is on the left
* GetRightParent : returns the closest parent which is on the right
* GetLeftChild : returns the closest leave which is on the left of
* current node
* GetRightChild : returns the closest leave which is on the right of
* current node
*/
static VParabola *GetLeft(VParabola *p);
static VParabola *GetRight(VParabola *p);
static VParabola *GetLeftParent(VParabola *p);
static VParabola *GetRightParent(VParabola *p);
static VParabola *GetLeftChild(VParabola *p);
static VParabola *GetRightChild(VParabola *p);
/*
* Function for intersecting two parabolae
*/
static VPoint Intersect(
const VParabola * p1,
const VParabola * p2,
double sweepingLine,
bool firstIntersection);
private:
VParabola *_left;
VParabola *_right;
};
#endif // VPARABOLA_H