// sphpoly.c // // by John D. de Boer #include "common.h" #include "cstring.h" #include "cyber.h" #include "disk.h" #include "floating.h" #include "frame.h" #include "gui.h" #include "vector.h" #include "view.h" #include "polygon.h" #include "sphcoord.h" #include "sphpoly.h" // Sectors of spheres static void initsphererect(sphererect *R, real Theta, real Phi) { if (!R) return; R->north=R->south=Theta; Phi=modtwopisym(Phi); R->east=R->west=Phi; } static void growsphererect(sphererect *R, real Theta, real Phi) { real Centre; if (!R) return; if (Thetanorth) R->north=Theta; if (Theta>R->south) R->south=Theta; Phi=modtwopisym(Phi); Centre= (R->east + R->west) / 2.0; if (fabs(Phi - twopi - Centre)west) R->west=Phi; if (Phi>R->east) R->east=Phi; } bool sphererectsect(const sphererect *A, const sphererect *B) { if (!A || !B) return 0; if (A->southnorth) return 0; if (A->north>B->south) return 0; if (A->east > B->west && A->west < B->east) return 1; if (A->east - twopi > B->west && A->west - twopi < B->east) return 1; if (A->east + twopi > B->west && A->west + twopi < B->east) return 1; return 0; } // Floating-point polygons void calcpolywedge(vectorpoly **VP) { int i,NUM; real Theta,Phi; vectorpoly *MV; if (!VP || !*VP) return; lock(VP); MV=*VP; NUM=MV->num; for (i=0;ipt + i,NULL,&Theta,&Phi); if (i==0) initsphererect(&(MV->rect),Theta,Phi); else growsphererect(&(MV->rect),Theta,Phi); } unlock(VP); } vectorpoly **longtovectorpoly(polygon **P) { int i,NUM; bool Closed; vectorpoly **VP,*MV; polygon *MP; if (!P || !*P) return NULL; NUM= (*P)->num; Closed=!((*P)->open); if (Closed) NUM++; VP=(vectorpoly **)handle(sizeof(vectorpoly) + (NUM * sizeof(vector))); lock(P); MP=*P; lock(VP); MV=*VP; MV->name=copyof(MP->name); MV->num=NUM; MV->open=MP->open; for (i=0;ipt; else L= MP->pt + i; Theta=((90 * 60) - L->v) / (60.0 * fiftyseven); Phi=L->h / (60.0 * fiftyseven); if (i==0) initsphererect(&(MV->rect),Theta,Phi); else growsphererect(&(MV->rect),Theta,Phi); polartocartesian(1.0,Theta,Phi,MV->pt + i); } unlock(P); unlock(VP); return VP; } static bool islakename(const char *S) { if (!S) return 0; if (position("Sea",S)) return 1; if (position("Lake",S)) return 1; if (position("Lakes",S)) return 1; if (position("Sap",S)) return 1; // TonlŽ Sap return 0; } vectorpolys **longtovectorpolys(polygons **Py) { int i,NUM; vectorpolys **R; vectorpoly **VP; if (!Py || !*Py) return NULL; R=(vectorpolys **)handle(sizeof(vectorpolys)); NUM=(*Py)->num; (*R)->num=NUM; resizehandle(R,sizeof(vectorpolys) + (NUM * sizeof(vectorpoly **))); for (i=0;ipoly[i]); (*R)->poly[i]=VP; (*VP)->lake=islakename((*VP)->name); } return R; } void oldvectorpolys(vectorpolys **P) { int i,NUM; if (!P || !*P) return; NUM=(*P)->num; for (i=0;ipoly[i]); release(P); }