solvespace/dsc.h
Jonathan Westhues f201d52247 Add hyperlink and colour support to the text window. Don't redraw
the text window every time we refresh the graphics window, because
that's slow. Use classes instead of structs for everything; I don't
understand the template handling for structs. And implement the
IdList, which I will try to use in many places.

[git-p4: depot-paths = "//depot/solvespace/": change = 1655]
2008-03-28 02:00:37 -08:00

89 lines
1.6 KiB
C++

#ifndef __DSC_H
#define __DSC_H
typedef unsigned long DWORD;
typedef unsigned char BYTE;
class Vector {
public:
double x, y, z;
Vector Cross(Vector b);
double Vector::Dot(Vector b);
Vector RotatedAbout(Vector axis, double theta);
double Magnitude(void);
Vector ScaledBy(double v);
};
class Point2d {
public:
double x, y;
};
template <class T, class H>
class IdList {
public:
typedef struct {
T v;
H h;
int tag;
} Elem;
Elem *elem;
int elems;
int elemsAllocated;
void AddAndAssignId(T *v) {
int i;
int id = 0;
for(i = 0; i < elems; i++) {
id = max(id, elem[i].h.v);
}
H h;
h.v = id + 1;
AddById(v, h);
}
void AddById(T *v, H h) {
if(elems >= elemsAllocated) {
elemsAllocated = (elemsAllocated + 32)*2;
elem = (Elem *)realloc(elem, elemsAllocated*sizeof(elem[0]));
if(!elem) oops();
}
elem[elems].v = *v;
elem[elems].h = h;
elem[elems].tag = 0;
elems++;
}
void RemoveTagged(void) {
int src, dest;
dest = 0;
for(src = 0; src < elems; src++) {
if(elem[src].tag) {
// this item should be deleted
} else {
if(src != dest) {
elem[dest] = elem[src];
}
dest++;
}
}
elems = dest;
// and elemsAllocated is untouched
}
void Clear(void) {
elemsAllocated = elems = 0;
if(elem) free(elem);
}
};
#endif