// twixt.c // // by John D. de Boer #include "twist.h" int SPHERES; // number of "spheres of influence" Sphere ***Spheres; // the spheres // void InitSpheres(void) { SPHERES=0; Spheres=(Sphere ***)handle(0); } Sphere *NewSphere(bool AddToList) { Sphere *R; R=pointer(sizeof(Sphere)); if (AddToList) { minimumsize(Spheres,SPHERES + 1,sizeof(Sphere *)); (*Spheres)[SPHERES++]=R; } R->name=NULL; R->loc.good=0; InitSpan(&(R->date)); R->num=0; R->polys=(TimePoly **)handle(0); return R; } static void OldSphere(Sphere *S) { if (!S) return; if (S->polys) release(S->polys); old(S); } void PurgeSpheres(void) { while (SPHERES>0) OldSphere((*Spheres)[--SPHERES]); } static Sphere *FindSphere(const char *S) { int i; Sphere *C; if (!S || !*S) return NULL; for (i=0;iname,S)) return C; } return NULL; } // void NewSphereDate(Sphere *S, const Day *D) { TimePoly *TP; if (!S || !S->polys || !D) return; S->num++; minimumsize(S->polys,S->num,sizeof(TimePoly)); lock(S->polys); TP= *(S->polys) + S->num - 1; if (S->num<=1) S->date.start=*D; else TP[-1].date.end=*D; TP->date.start=*D; InitDay(&(TP->date.end)); TP->poly=NULL; unlock(S->polys); } void SphereEndDate(Sphere *S, const Day *D) { TimePoly *TP; if (!S || !S->polys || !D) return; S->date.end=*D; lock(S->polys); TP=*(S->polys); if (S->num>0) TP[S->num - 1].date.end=*D; unlock(S->polys); } void AddPolyToSphere(Sphere *S, vectorpoly **P) { TimePoly *TP; if (!S || !S->polys || S->num<1 || !P) return; TP= (*(S->polys)) + S->num - 1; TP->poly=P; } void VerifyNewSphere(Sphere *S) { TimePoly *P; int i; if (!S) return; if (!S->name) { Warning("Sphere with no name"); S->name=copyof("Unknown Region"); } GeoRefToVector(&(S->loc),&(S->pos),S->name); if (S->num==0) WarnOld(cat3(0,"Sphere \"",S->name,"\" has no associated polygons")); if (S->date.start.kind==timeInval) WarnOld(cat3(0,"Start date of sphere \"",S->name,"\" is missing or has bad format")); if (S->date.end.kind==timeInval) WarnOld(cat3(0,"End date of sphere \"",S->name,"\" is missing or has bad format")); lock(S->polys); for (i=0;inum;i++) { P= (*(S->polys)) + i; if (P->date.start.kind==timeInval) WarnOld(cat5(2,"Start date of polygon #",fig(i + 1)," of sphere \"",S->name,"\" is missing or has bad format")); if (P->date.end.kind==timeInval) WarnOld(cat5(2,"End date of polygon #",fig(i + 1)," of sphere \"",S->name,"\" is missing or has bad format")); if (!P->poly) WarnOld(cat5(2,"Polygon #",fig(i + 1)," of sphere \"",S->name,"\" is missing or has bad format")); } unlock(S->polys); } // Database delta void CheckSphereDelta(Sphere *S) { Sphere *Ex; if (!S) return; Ex=FindSphere(S->name); if (!Ex) WarnOld(cat(0,"New sphere-of-influence definition: ",S->name)); OldSphere(S); } /* static bool HappenedEarlier(const void *A, const void *B) { Span *P,*Q; if (!A || !B) return 0; P=&(((Sphere *)A)->date); Q=&(((Sphere *)B)->date); if ((P->start.kind==timeInval)!=(Q->start.kind==timeInval)) return Q->start.kind==timeInval; return P->start.jdstart.jd; }*/ // Earth polygons read from database // These fuctions are just tagging along here. They really should have their own source file, since they have // little to do with "sphere-of-influence" polygons vectorpolys **TTTPoly; void InitGlobe(void) { TTTPoly=NULL; } void UsePolys(vectorpolys **P) { if (TTTPoly) oldvectorpolys(TTTPoly); TTTPoly=P; } void PurgeGlobe(void) { if (TTTPoly) oldvectorpolys(TTTPoly); TTTPoly=NULL; }