-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathedge_table.h
More file actions
63 lines (48 loc) · 1.27 KB
/
edge_table.h
File metadata and controls
63 lines (48 loc) · 1.27 KB
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
#ifndef EDGE_TABLE_H_
#define EDGE_TABLE_H_
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>
#include "point.h"
#include "config.h"
#include "edge_sort.h"
using namespace std;
class EdgeTable {
public:
EdgeTable() {
}
EdgeTable( vector<Edge> edges ) {
for ( auto &edge : edges ) {
// skip all horizontal lines, not needed
if ( edge.is_horizontal_line() ) {
continue;
}
edge_table.insert( pair<int, Edge>( edge.get_min_y(), edge ) );
}
}
void push_active_edges( int y, vector<Edge> &active_edge_list ) {
int count = edge_table.count( y );
if ( count > 0 ) {
multimap<int, Edge>::const_iterator itr = edge_table.find(y);
for(int i = 0; i < count; ++i){
active_edge_list.push_back((*itr).second);
++itr;
}
// list has been changed,
// sort edges so that concave edges can be drawn
sort(active_edge_list.begin(), active_edge_list.end(), EdgeSort(y));
}
}
friend ostream& operator<<( ostream& os, const EdgeTable& et ) {
for ( multimap<int, Edge>::const_iterator it = et.edge_table.begin();
it != et.edge_table.end(); ++it ) {
os << "[" << (*it).first << ", " << (*it).second << "]" << endl;
}
return os;
}
private:
// y, edge associated with a given y
multimap<int, Edge> edge_table;
};
#endif