/* See {Polygon.h} */ #include /* Last edited on 2021-07-18 00:42:38 by jstolfi */ #define Polygon_C_COPYRIGHT \ "Copyright © 2000,2007 Universidade Estadual de Campinas (UNICAMP)" #include #include #include #include #include #include #include #include #include #include Place_vec_t PolygonMake(uint n, bool_t nodes, bool_t edges, bool_t walls, bool_t cells) { int i; /* Create one cell {sc}, one wall {sf}: */ Wall_t sf = (walls ? MakeWall(0) : NULL); Cell_t sc = (cells ? MakeCell(0) : NULL); /* Create {n} nodes {sv[0..n-1]}, and {n} edges {se[0..n-1]}: */ Node_t sv[n]; Edge_t se[n]; for (i = 0; i < n; i++) { se[i] = (edges ? MakeEdge(i) : NULL); sv[i] = (nodes ? MakeNode(i) : NULL); } /* Create {n} wedges {sp[0..n-1]}, connect them: */ Place_vec_t sp = Place_vec_new(n); for (i = 0; i < n; i++) { Wedge_t w = MakeWedge(); Place_t p = WedgeBase(w); Place_t q = Clock(p); w->num = i; /* Set the node data slots of {w}: */ uint j = (i+1) % n; SetOrg(p, sv[i]); affirm(OrgV(p) == sv[i], "bug 1"); SetOrg(q, sv[j]); affirm(OrgV(q) == sv[j], "bug 2"); /* Set the edge data slot of {w}: */ SetEdge(p, se[i]); affirm(PEdge(p) == se[i], "bug 3"); affirm(PEdge(q) == se[i], "bug 4"); /* Set the wall data slo of {w}t: */ SetWall(p, sf); affirm(PWall(p) == sf, "bug 5"); affirm(PWall(q) == sf, "bug 6"); /* Set the cell data slots of {w}: */ SetPneg(p, sc); affirm(PnegP(p) == sc, "bug 7"); SetPneg(q, sc); affirm(PnegP(q) == sc, "bug 8"); sp.e[i] = p; } /* Connect the wedges together: */ for (i = 0; i < n; i++) { SetNextE(sp.e[i], sp.e[(i+1) % n]); SetNextF(sp.e[i], sp.e[i]); } return sp; } Place_t PolygonMakeSng(uint n) { Place_vec_t sp = PolygonMake(n, TRUE, TRUE, TRUE, TRUE); Place_t p = sp.e[0]; free(sp.e); return p; } void PolygonFixCoords(Place_t p, uint n, Coords_t *c) { /* Assign the coordinates: */ Place_t q = p; int i; for (i = 0; i < n; i++) { /* Compute the corner coordinates {cv}: */ double theta = 2*i*M_PI/n; double x = cos(theta); double y = sin(theta); /* Assign them: */ Node_t v = OrgV(q); c->e[v->num] = (r4_t){{ x, y, 0, 0}}; /* Go to the next node: */ q = NextE(q); } demand(q == p, "inconsistent {n}"); } #define Polygon_C_author \ "Created by L. A. P. Lozada, 2000.\n" \ " 26-01-2007 : Converted to C by J. Stolfi; got {FixCoordsGon} from\n" \ " {MakePolygon.c}"