Computational Geometry Algorithms Library  1.0
Computational Geometry Algorithms Library Documentation
VertexList.h
Go to the documentation of this file.
1 #include <iostream>
2 using namespace std;
3 class VertexList
4 {
5 public:
6  VertexList(void);
7  ~VertexList(void);
8 
11 
12  void addToList(DCELVertex* newVertex);
13  int length;
14  void removeFromList(DCELVertex* vertex);
15  void echo();
16 };
17 
18 VertexList::VertexList(void) : head(NULL), tail(NULL), length(0)
19 {
20 }
21 
23 {
24 }
25 
27  DCELVertex* walker = head;
28  int i = 0;
29  while (1) {
30  walker->index = i++;
31  cout << walker->x << " " << walker->y << " 0" << endl;
32  if (walker->next)
33  walker = walker->next;
34  else break;
35  }
36 }
37 
39 {
40  length++;
41  if ( head ) {
42  if ((head->y < newVertex->y) || (head->y == newVertex->y && head->x > newVertex->x)) {
43  newVertex->next = head;
44  head = newVertex;
45  return;
46  }
47  DCELVertex* walker = head;
48  while (walker->next) {
49  if ((walker->next->y < newVertex->y) || (walker->next->y == newVertex->y && walker->next->x > newVertex->x)) break;
50  walker = walker->next;
51  }
52  newVertex->next = walker->next;
53  walker->next = newVertex;
54  }
55  else {
56  head = newVertex;
57  tail = newVertex;
58  }
59 }
60 
62 {
63  length--;
64  if (head) {
65  DCELVertex* walker = head;
66  if (walker == vertex) {
67  head = walker->next;
68  delete walker;
69  }
70  while (walker->next != vertex && walker->next != NULL) {
71  walker = walker->next;
72  }
73  if (walker->next = vertex) {
74  walker->next = vertex->next;
75  delete vertex;
76  }
77  }
78 }
void removeFromList(DCELVertex *vertex)
Definition: VertexList.h:61
DCELVertex * tail
Definition: VertexList.h:10
VertexList(void)
Definition: VertexList.h:18
void echo()
Definition: VertexList.h:26
Definition: DCELVertex.h:2
~VertexList(void)
Definition: VertexList.h:22
double x
Definition: DCELVertex.h:8
int index
Definition: DCELVertex.h:16
int length
Definition: VertexList.h:13
Definition: VertexList.h:3
double y
Definition: DCELVertex.h:9
void addToList(DCELVertex *newVertex)
Definition: VertexList.h:38
DCELVertex * next
Definition: DCELVertex.h:18
DCELVertex * head
Definition: VertexList.h:9