2008-04-23 07:29:19 +00:00
|
|
|
|
|
|
|
#ifndef __POLYGON_H
|
|
|
|
#define __POLYGON_H
|
|
|
|
|
2008-04-25 07:04:09 +00:00
|
|
|
class SPolygon;
|
|
|
|
|
2008-04-24 06:22:16 +00:00
|
|
|
template <class T>
|
|
|
|
class SList {
|
2008-04-23 07:29:19 +00:00
|
|
|
public:
|
2008-04-24 06:22:16 +00:00
|
|
|
T *elem;
|
|
|
|
int n;
|
|
|
|
int elemsAllocated;
|
2008-04-25 07:04:09 +00:00
|
|
|
|
|
|
|
void Add(T *t) {
|
|
|
|
if(n >= elemsAllocated) {
|
|
|
|
elemsAllocated = (elemsAllocated + 32)*2;
|
|
|
|
elem = (T *)MemRealloc(elem, elemsAllocated*sizeof(elem[0]));
|
|
|
|
}
|
|
|
|
elem[n++] = *t;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearTags(void) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < n; i++) {
|
|
|
|
elem[i].tag = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear(void) {
|
|
|
|
if(elem) MemFree(elem);
|
|
|
|
elem = NULL;
|
|
|
|
n = elemsAllocated = 0;
|
|
|
|
}
|
2008-04-23 07:29:19 +00:00
|
|
|
};
|
|
|
|
|
2008-04-24 06:22:16 +00:00
|
|
|
class SEdge {
|
2008-04-23 07:29:19 +00:00
|
|
|
public:
|
2008-04-25 07:04:09 +00:00
|
|
|
int tag;
|
2008-04-24 06:22:16 +00:00
|
|
|
Vector a, b;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SEdgeList {
|
|
|
|
public:
|
|
|
|
SList<SEdge> l;
|
|
|
|
|
2008-04-25 07:04:09 +00:00
|
|
|
bool AssemblePolygon(SPolygon *dest, SEdge *errorAt);
|
2008-05-16 06:34:06 +00:00
|
|
|
void BreakEdgesInto(SEdgeList *el);
|
2008-04-25 07:04:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SPoint {
|
|
|
|
public:
|
|
|
|
int tag;
|
|
|
|
Vector p;
|
2008-04-23 07:29:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SContour {
|
|
|
|
public:
|
2008-04-25 07:04:09 +00:00
|
|
|
SList<SPoint> l;
|
2008-05-02 10:54:22 +00:00
|
|
|
|
|
|
|
void MakeEdgesInto(SEdgeList *el);
|
2008-05-05 09:47:23 +00:00
|
|
|
void Reverse(void);
|
|
|
|
Vector ComputeNormal(void);
|
|
|
|
bool IsClockwiseProjdToNormal(Vector n);
|
|
|
|
bool ContainsPointProjdToNormal(Vector n, Vector p);
|
2008-04-23 07:29:19 +00:00
|
|
|
};
|
|
|
|
|
2008-04-24 06:22:16 +00:00
|
|
|
class SPolygon {
|
|
|
|
public:
|
|
|
|
SList<SContour> l;
|
2008-05-05 09:47:23 +00:00
|
|
|
Vector normal;
|
2008-04-25 07:04:09 +00:00
|
|
|
|
2008-05-05 09:47:23 +00:00
|
|
|
Vector ComputeNormal(void);
|
2008-04-25 07:04:09 +00:00
|
|
|
void AddEmptyContour(void);
|
|
|
|
void AddPoint(Vector p);
|
2008-05-02 10:54:22 +00:00
|
|
|
void MakeEdgesInto(SEdgeList *el);
|
2008-05-05 09:47:23 +00:00
|
|
|
void FixContourDirections(void);
|
2008-04-25 07:04:09 +00:00
|
|
|
void Clear(void);
|
2008-04-24 06:22:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SPolyhedron {
|
|
|
|
SList<SPolygon> l;
|
2008-04-23 07:29:19 +00:00
|
|
|
public:
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2008-04-24 06:22:16 +00:00
|
|
|
|