Polygon* polyRectangle(const Vertex* V1, const Vertex* V2, const Vertex* V3, const Vertex* V4) { Polygon* newRectangle = newPolygon(4, V1, V2, V3, V4); polyAddInternal(newRectangle, 0, 2, -1); polyAddInternal(newRectangle, 1, 3, -1); return newRectangle; }
QPolygon RedEyeDetection::scalePolygon(const QPolygon &polygon, const QSize &scaleBefore, const QSize &scaleAfter) const { QPolygon newPolygon(polygon); for (int i=0; i<newPolygon.size(); i++) newPolygon.setPoint(i, scalePoint(newPolygon.point(i), scaleBefore, scaleAfter)); return newPolygon; }
void polyRegressionTest() { printf("\n === Debut du test de regression de Polygon === \n\n"); unsigned int i; float prevdt = 1.f, dt = 1.f; Vertex* V1 = newVertex(); Vertex* V2 = newVertex(); Vertex* V3 = newVertex(); Vertex* V10 = newVertex(); Vertex* V11 = newVertex(); Vertex* V12 = newVertex(); Vertex* V13 = newVertex(); vxSetPosition(V1, vec2(0.f, 0.f)); vxSetPosition(V2, vec2(10.f, 0.f)); vxSetPosition(V3, vec2(0.f, 10.f)); vxSetPosition(V10, vec2(20.f, 0.f)); vxSetPosition(V11, vec2(30.f, 0.f)); vxSetPosition(V12, vec2(30.f, 10.f)); vxSetPosition(V13, vec2(20.f, 10.f)); Polygon* Poly = newPolygon(3, V1, V2, V3); Polygon* Rectangle = polyRectangle(V10, V11, V12, V13); for(i = 0; i < 10; i++) { printf("Frame #%d\n", i); printf("Triangle : (%f, %f) (%f, %f) (%f, %f)\n\n", vxGetPosition(V1).x, vxGetPosition(V1).y, vxGetPosition(V2).x, vxGetPosition(V2).y, vxGetPosition(V3).x, vxGetPosition(V3).y); printf("Rectangle : (%f, %f) (%f, %f) \n (%f, %f), (%f, %f)\n\n", vxGetPosition(V10).x, vxGetPosition(V10).y, vxGetPosition(V11).x, vxGetPosition(V11).y, vxGetPosition(V12).x, vxGetPosition(V12).y, vxGetPosition(V13).x, vxGetPosition(V13).y); vxApplyForce(V1, vec2(1.f, 0.f), 0); vxApplyForce(V10, vec2(1.f, 0.f), 0); vxResolve(V1, prevdt, dt); vxResolve(V2, prevdt, dt); vxResolve(V3, prevdt, dt); vxResolve(V10, prevdt, dt); vxResolve(V11, prevdt, dt); vxResolve(V12, prevdt, dt); vxResolve(V13, prevdt, dt); polyResolve(Poly); polyResolve(Rectangle); } delPolygon(Rectangle); delPolygon(Poly); delVertex(V13); delVertex(V12); delVertex(V11); delVertex(V10); delVertex(V3); delVertex(V2); delVertex(V1); printf("\n === Fin du test de regression de Polygon === \n\n"); }
void wdRegressionTest() { printf("\n === Debut du test de regression de World === \n\n"); World* W = newWorld(500.f, 500.f); Vertex* V1 = newVertex(); Vertex* V2 = newVertex(); Vertex* V3 = newVertex(); Vertex* V10 = newVertex(); Vertex* V11 = newVertex(); Vertex* V12 = newVertex(); Vertex* V13 = newVertex(); vxSetPosition(V1, vec2(0.f, 0.f)); vxSetPosition(V2, vec2(10.f, 0.f)); vxSetPosition(V3, vec2(0.f, 10.f)); vxSetPosition(V10, vec2(20.f, 0.f)); vxSetPosition(V11, vec2(30.f, 0.f)); vxSetPosition(V12, vec2(30.f, 10.f)); vxSetPosition(V13, vec2(20.f, 10.f)); Polygon* Poly = newPolygon(3, V1, V2, V3); Polygon* Rectangle = polyRectangle(V10, V11, V12, V13); wdAddVertex(W, V1); assert(wdGetVxCount(W) == 1); wdAddVertex(W, V2); assert(wdGetVxCount(W) == 2); wdAddVertex(W, V3); assert(wdGetVxCount(W) == 3); wdAddVertex(W, V10); assert(wdGetVxCount(W) == 4); wdAddVertex(W, V11); assert(wdGetVxCount(W) == 5); wdAddVertex(W, V12); assert(wdGetVxCount(W) == 6); wdAddVertex(W, V13); assert(wdGetVxCount(W) == 7); wdAddPolygon(W, Poly); assert(wdGetPolyCount(W) == 1); wdAddPolygon(W, Rectangle); assert(wdGetPolyCount(W) == 2); for(unsigned int i = 0; i < 10000; i++) { wdApplyForce(W, vec2(0.f, 0.6f)); wdResolveVextex(W); wdUpdateGrid(W, FALSE); for(unsigned int j = 0; j < 4; j++) { wdResolveRigid(W); wdResolveElastic(W); wdHandleCollision(W); } } delWorld(W); printf("\n === Fin du test de regression de World ===== \n\n"); }
/** * Intersect the subject polygon using clip polygon and store into * polygons structure, returns the total number of polygons. */ int createClippedPolygon(struct vertex *lclip, struct vertex *lsubject, struct vertex **polygons, int *total) { struct vertex *isubject = lsubject->next, *current; struct vertex *poly = NULL, *first = NULL; int npolys = 0; int nvertex = 0; while (isubject) { for (; isubject != lsubject && !(isubject->intersect && !isubject->processed); isubject = isubject->next); if (isubject == lsubject) break; isubject->processed = 1; current = isubject; if (first == NULL) { first = (struct vertex *) malloc (sizeof(struct vertex)); first->x = current->x; first->y = current->y; first->o = current->o; first->nextPoly = NULL; poly = first; } else poly = newPolygon(poly, current); npolys++; nvertex++; struct vertex *lastPoint = poly; do { if (current->entry_exit == STATUS_ENTRY) do { current = current->next; newVertex(lastPoint, current); lastPoint = lastPoint->next; nvertex++; } while (!current->intersect); else do { current = current->prev; newVertex(lastPoint, current); lastPoint = lastPoint->next; nvertex++; } while (!current->intersect); current->processed = 1; current = current->neighbour; current->processed = 1; } while (! (poly->x == current->x && poly->y == current->y) ); } if (polygons) *polygons = first; if (total) *total = nvertex; return npolys; }