Make the tag (for items in an idlist) a member of the templated
data structure, and thus get rid of a level of struct. [git-p4: depot-paths = "//depot/solvespace/": change = 1671]solver
parent
2f4a3917c5
commit
c097fea4f3
24
dsc.h
24
dsc.h
|
@ -43,21 +43,16 @@ public:
|
|||
template <class T, class H>
|
||||
class IdList {
|
||||
public:
|
||||
typedef struct {
|
||||
T t;
|
||||
int tag;
|
||||
} Elem;
|
||||
|
||||
Elem *elem;
|
||||
int elems;
|
||||
int elemsAllocated;
|
||||
T *elem;
|
||||
int elems;
|
||||
int elemsAllocated;
|
||||
|
||||
H AddAndAssignId(T *t) {
|
||||
int i;
|
||||
DWORD id = 0;
|
||||
|
||||
for(i = 0; i < elems; i++) {
|
||||
id = max(id, elem[i].t.h.v);
|
||||
id = max(id, elem[i].h.v);
|
||||
}
|
||||
|
||||
t->h.v = (id + 1);
|
||||
|
@ -69,12 +64,11 @@ public:
|
|||
void Add(T *t) {
|
||||
if(elems >= elemsAllocated) {
|
||||
elemsAllocated = (elemsAllocated + 32)*2;
|
||||
elem = (Elem *)MemRealloc(elem, elemsAllocated*sizeof(elem[0]));
|
||||
elem = (T *)MemRealloc(elem, elemsAllocated*sizeof(elem[0]));
|
||||
if(!elem) oops();
|
||||
}
|
||||
|
||||
elem[elems].t = *t;
|
||||
elem[elems].tag = 0;
|
||||
elem[elems] = *t;
|
||||
elems++;
|
||||
}
|
||||
|
||||
|
@ -90,8 +84,8 @@ public:
|
|||
T *FindByIdNoOops(H h) {
|
||||
int i;
|
||||
for(i = 0; i < elems; i++) {
|
||||
if(elem[i].t.h.v == h.v) {
|
||||
return &(elem[i].t);
|
||||
if(elem[i].h.v == h.v) {
|
||||
return &(elem[i]);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
@ -107,7 +101,7 @@ public:
|
|||
void Tag(H h, int tag) {
|
||||
int i;
|
||||
for(i = 0; i < elems; i++) {
|
||||
if(elem[i].t.h.v == h.v) {
|
||||
if(elem[i].h.v == h.v) {
|
||||
elem[i].tag = tag;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,12 +157,12 @@ void GraphicsWindow::EnsureValidActives(void) {
|
|||
if((!g) || (g->h.v == Group::HGROUP_REFERENCES.v)) {
|
||||
int i;
|
||||
for(i = 0; i < SS.group.elems; i++) {
|
||||
if(SS.group.elem[i].t.h.v != Group::HGROUP_REFERENCES.v) {
|
||||
if(SS.group.elem[i].h.v != Group::HGROUP_REFERENCES.v) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i >= SS.group.elems) oops();
|
||||
activeGroup = SS.group.elem[i].t.h;
|
||||
activeGroup = SS.group.elem[i].h;
|
||||
change = true;
|
||||
}
|
||||
|
||||
|
@ -363,28 +363,28 @@ void GraphicsWindow::HitTestMakeSelection(Point2d mp, Selection *dest) {
|
|||
|
||||
// Do the points
|
||||
for(i = 0; i < SS.entity.elems; i++) {
|
||||
d = SS.entity.elem[i].t.GetDistance(mp);
|
||||
d = SS.entity.elem[i].GetDistance(mp);
|
||||
if(d < 10 && d < dmin) {
|
||||
memset(dest, 0, sizeof(*dest));
|
||||
dest->entity = SS.entity.elem[i].t.h;
|
||||
dest->entity = SS.entity.elem[i].h;
|
||||
}
|
||||
}
|
||||
|
||||
// Entities
|
||||
for(i = 0; i < SS.point.elems; i++) {
|
||||
d = SS.point.elem[i].t.GetDistance(mp);
|
||||
d = SS.point.elem[i].GetDistance(mp);
|
||||
if(d < 10 && d < dmin) {
|
||||
memset(dest, 0, sizeof(*dest));
|
||||
dest->point = SS.point.elem[i].t.h;
|
||||
dest->point = SS.point.elem[i].h;
|
||||
}
|
||||
}
|
||||
|
||||
// Constraints
|
||||
for(i = 0; i < SS.constraint.elems; i++) {
|
||||
d = SS.constraint.elem[i].t.GetDistance(mp);
|
||||
d = SS.constraint.elem[i].GetDistance(mp);
|
||||
if(d < 10 && d < dmin) {
|
||||
memset(dest, 0, sizeof(*dest));
|
||||
dest->constraint = SS.constraint.elem[i].t.h;
|
||||
dest->constraint = SS.constraint.elem[i].h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -582,15 +582,15 @@ void GraphicsWindow::Paint(int w, int h) {
|
|||
// First, draw the entire scene.
|
||||
glColor3f(1, 1, 1);
|
||||
for(i = 0; i < SS.entity.elems; i++) {
|
||||
SS.entity.elem[i].t.Draw();
|
||||
SS.entity.elem[i].Draw();
|
||||
}
|
||||
glColor3f(0, 0.8f, 0);
|
||||
for(i = 0; i < SS.point.elems; i++) {
|
||||
SS.point.elem[i].t.Draw();
|
||||
SS.point.elem[i].Draw();
|
||||
}
|
||||
glColor3f(1.0f, 0, 1.0f);
|
||||
for(i = 0; i < SS.constraint.elems; i++) {
|
||||
SS.constraint.elem[i].t.Draw();
|
||||
SS.constraint.elem[i].Draw();
|
||||
}
|
||||
|
||||
// Then redraw whatever the mouse is hovering over, highlighted. Have
|
||||
|
|
48
sketch.h
48
sketch.h
|
@ -61,6 +61,7 @@ class Group {
|
|||
public:
|
||||
static const hGroup HGROUP_REFERENCES;
|
||||
|
||||
int tag;
|
||||
hGroup h;
|
||||
|
||||
NameStr name;
|
||||
|
@ -77,6 +78,7 @@ public:
|
|||
static const hRequest HREQUEST_REFERENCE_YZ;
|
||||
static const hRequest HREQUEST_REFERENCE_ZX;
|
||||
|
||||
int tag;
|
||||
hRequest h;
|
||||
|
||||
// Types of requests
|
||||
|
@ -112,6 +114,7 @@ public:
|
|||
static const int LINE_SEGMENT = 1010;
|
||||
int type;
|
||||
|
||||
int tag;
|
||||
hEntity h;
|
||||
|
||||
Expr *expr[16];
|
||||
|
@ -140,7 +143,9 @@ public:
|
|||
|
||||
class Param {
|
||||
public:
|
||||
int tag;
|
||||
hParam h;
|
||||
|
||||
double val;
|
||||
bool known;
|
||||
|
||||
|
@ -149,6 +154,7 @@ public:
|
|||
|
||||
class Point {
|
||||
public:
|
||||
int tag;
|
||||
// The point ID is equal to the initial param ID.
|
||||
hPoint h;
|
||||
|
||||
|
@ -176,6 +182,26 @@ public:
|
|||
double GetDistance(Point2d mp);
|
||||
};
|
||||
|
||||
inline hEntity hRequest::entity(int i)
|
||||
{ hEntity r; r.v = (v << 10) | i; return r; }
|
||||
|
||||
inline hRequest hEntity::request(void)
|
||||
{ hRequest r; r.v = (v >> 10); return r; }
|
||||
inline hParam hEntity::param(int i)
|
||||
{ hParam r; r.v = (v << 7) | i; return r; }
|
||||
inline hPoint hEntity::point(int i)
|
||||
{ hPoint r; r.v = (v << 7) | i; return r; }
|
||||
|
||||
inline bool hPoint::isFromReferences(void) {
|
||||
DWORD d = v >> 17;
|
||||
if(d == Request::HREQUEST_REFERENCE_XY.v) return true;
|
||||
if(d == Request::HREQUEST_REFERENCE_YZ.v) return true;
|
||||
if(d == Request::HREQUEST_REFERENCE_ZX.v) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class hConstraint {
|
||||
public:
|
||||
DWORD v;
|
||||
|
@ -191,7 +217,9 @@ public:
|
|||
static const int HORIZONTAL = 40;
|
||||
static const int VERTICAL = 41;
|
||||
|
||||
int tag;
|
||||
hConstraint h;
|
||||
|
||||
int type;
|
||||
hGroup group;
|
||||
|
||||
|
@ -235,27 +263,11 @@ public:
|
|||
|
||||
class Equation {
|
||||
public:
|
||||
int tag;
|
||||
hEquation h;
|
||||
|
||||
Expr *e;
|
||||
};
|
||||
|
||||
|
||||
inline hEntity hRequest::entity(int i)
|
||||
{ hEntity r; r.v = (v << 10) | i; return r; }
|
||||
|
||||
inline hRequest hEntity::request(void)
|
||||
{ hRequest r; r.v = (v >> 10); return r; }
|
||||
inline hParam hEntity::param(int i)
|
||||
{ hParam r; r.v = (v << 7) | i; return r; }
|
||||
inline hPoint hEntity::point(int i)
|
||||
{ hPoint r; r.v = (v << 7) | i; return r; }
|
||||
|
||||
inline bool hPoint::isFromReferences(void) {
|
||||
DWORD d = v >> 17;
|
||||
if(d == Request::HREQUEST_REFERENCE_XY.v) return true;
|
||||
if(d == Request::HREQUEST_REFERENCE_YZ.v) return true;
|
||||
if(d == Request::HREQUEST_REFERENCE_ZX.v) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -59,13 +59,13 @@ void SolveSpace::GenerateAll(void) {
|
|||
entity.Clear();
|
||||
point.Clear();
|
||||
for(i = 0; i < request.elems; i++) {
|
||||
request.elem[i].t.Generate(&entity, &point, ¶m);
|
||||
request.elem[i].Generate(&entity, &point, ¶m);
|
||||
}
|
||||
|
||||
for(i = 0; i < param.elems; i++) {
|
||||
Param *p = prev.FindByIdNoOops(param.elem[i].t.h);
|
||||
Param *p = prev.FindByIdNoOops(param.elem[i].h);
|
||||
if(p) {
|
||||
param.elem[i].t.val = p->val;
|
||||
param.elem[i].val = p->val;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ void TextWindow::ShowAllGroups(void) {
|
|||
s = "all requests from all groups";
|
||||
v = 0;
|
||||
} else {
|
||||
Group *g = &(SS.group.elem[i].t);
|
||||
Group *g = &(SS.group.elem[i]);
|
||||
s = g->DescriptionString();
|
||||
v = g->h.v;
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ void TextWindow::ShowRequestsInGroup(void) {
|
|||
|
||||
int i;
|
||||
for(i = 0; i < SS.request.elems; i++) {
|
||||
Request *r = &(SS.request.elem[i].t);
|
||||
Request *r = &(SS.request.elem[i]);
|
||||
|
||||
if(r->group.v == shown->group.v || shown->group.v == 0) {
|
||||
char *s = r->DescriptionString();
|
||||
|
|
Loading…
Reference in New Issue