00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GENLIB2_GRID_INCLUDED
00022 #define GENLIB2_GRID_INCLUDED
00023
00024 #define MAXGRID 128
00025
00026 using namespace std;
00027
00028 namespace GenLib2
00029 {
00030
00032 struct point {double x, y; int c;};
00033
00035 struct rect {double x1, y1, x2, y2;};
00036
00038 struct range {double min, max;};
00039
00040
00052 class Grid
00053 {
00054 public:
00056 Grid();
00057
00059 ~Grid();
00060
00062 void clear();
00063
00065 void set(struct range x, struct range y);
00066
00068 void info(ostream& os) const;
00069
00071 void insert(struct point p);
00072
00074 size_t size() const;
00075
00077 void occupied(ostream& os) const;
00078
00083 int average(struct rect range, struct point& p) const;
00084
00086 bool bbox(struct range& rx, struct range& ry) const;
00087
00089 struct point* closest(struct rect range, struct point& o) const;
00090
00092 void print(ostream& os) const;
00093
00095 void print(ostream& os, char* fmt) const;
00096
00097 protected:
00099 struct node
00100 {
00102 struct point p;
00103
00105 struct node* next;
00106 };
00107
00109 struct node* grid[MAXGRID][MAXGRID];
00110
00112 struct node* z;
00113
00115 struct point origin;
00116
00118 double width;
00119
00120 private:
00122 double min2;
00123
00125 struct point cp1, cp2;
00126
00128 void check(struct point p1, struct point p2);
00129
00131 int insiderect(struct point p, struct rect range) const;
00132 };
00133
00134 }
00135
00136 #endif