void embPattern_addPolygonObjectAbs(EmbPattern* p, EmbPolygonObject* obj) { if(!p) { embLog_error("emb-pattern.c embPattern_addPolygonObjectAbs(), p argument is null\n"); return; } if(!obj) { embLog_error("emb-pattern.c embPattern_addPolygonObjectAbs(), obj argument is null\n"); return; } if(embPointList_empty(obj->pointList)) { embLog_error("emb-pattern.c embPattern_addPolygonObjectAbs(), obj->pointList is empty\n"); return; } if(embPolygonObjectList_empty(p->polygonObjList)) { p->polygonObjList = p->lastPolygonObj = embPolygonObjectList_create(obj); } else { p->lastPolygonObj = embPolygonObjectList_add(p->lastPolygonObj, obj); } }
/* Calculates a rectangle that encapsulates all stitches and objects in the pattern. */ EmbRect embPattern_calcBoundingBox(EmbPattern* p) { EmbStitchList* pointer = 0; EmbRect boundingRect; EmbStitch pt; EmbArcObjectList* aObjList = 0; EmbArc arc; EmbCircleObjectList* cObjList = 0; EmbCircle circle; EmbEllipseObjectList* eObjList = 0; EmbEllipse ellipse; EmbLineObjectList* liObjList = 0; EmbLine line; EmbPointObjectList* pObjList = 0; EmbPoint point; EmbPolygonObjectList* pogObjList = 0; EmbPointList* pogPointList = 0; EmbPoint pogPoint; EmbPolylineObjectList* polObjList = 0; EmbPointList* polPointList = 0; EmbPoint polPoint; EmbRectObjectList* rObjList = 0; EmbRect rect; EmbSplineObjectList* sObjList = 0; EmbBezier bezier; if(!p) { embLog_error("emb-pattern.c embPattern_calcBoundingBox(), p argument is null\n"); return boundingRect; } /* Calculate the bounding rectangle. It's needed for smart repainting. */ /* TODO: Come back and optimize this mess so that after going thru all objects and stitches, if the rectangle isn't reasonable, then return a default rect */ if(embStitchList_empty(p->stitchList) && embArcObjectList_empty(p->arcObjList) && embCircleObjectList_empty(p->circleObjList) && embEllipseObjectList_empty(p->ellipseObjList) && embLineObjectList_empty(p->lineObjList) && embPointObjectList_empty(p->pointObjList) && embPolygonObjectList_empty(p->polygonObjList) && embPolylineObjectList_empty(p->polylineObjList) && embRectObjectList_empty(p->rectObjList) && embSplineObjectList_empty(p->splineObjList)) { boundingRect.top = 0.0; boundingRect.left = 0.0; boundingRect.bottom = 1.0; boundingRect.right = 1.0; return boundingRect; } boundingRect.left = 99999.0; boundingRect.top = 99999.0; boundingRect.right = -99999.0; boundingRect.bottom = -99999.0; pointer = p->stitchList; while(pointer) { /* If the point lies outside of the accumulated bounding * rectangle, then inflate the bounding rect to include it. */ pt = pointer->stitch; if(!(pt.flags & TRIM)) { boundingRect.left = (double)min(boundingRect.left, pt.xx); boundingRect.top = (double)min(boundingRect.top, pt.yy); boundingRect.right = (double)max(boundingRect.right, pt.xx); boundingRect.bottom = (double)max(boundingRect.bottom, pt.yy); } pointer = pointer->next; } aObjList = p->arcObjList; while(aObjList) { arc = aObjList->arcObj.arc; /* TODO: embPattern_calcBoundingBox for arcs */ aObjList = aObjList->next; } cObjList = p->circleObjList; while(cObjList) { circle = cObjList->circleObj.circle; boundingRect.left = (double)min(boundingRect.left, circle.centerX - circle.radius); boundingRect.top = (double)min(boundingRect.top, circle.centerY - circle.radius); boundingRect.right = (double)max(boundingRect.right, circle.centerX + circle.radius); boundingRect.bottom = (double)max(boundingRect.bottom, circle.centerY + circle.radius); cObjList = cObjList->next; } eObjList = p->ellipseObjList; while(eObjList) { ellipse = eObjList->ellipseObj.ellipse; /* TODO: embPattern_calcBoundingBox for ellipses */ eObjList = eObjList->next; } liObjList = p->lineObjList; while(liObjList) { line = liObjList->lineObj.line; /* TODO: embPattern_calcBoundingBox for lines */ liObjList = liObjList->next; } pObjList = p->pointObjList; while(pObjList) { point = pObjList->pointObj.point; /* TODO: embPattern_calcBoundingBox for points */ pObjList = pObjList->next; } pogObjList = p->polygonObjList; while(pogObjList) { pogPointList = pogObjList->polygonObj->pointList; while(pogPointList) { pogPoint = pogPointList->point; /* TODO: embPattern_calcBoundingBox for polygons */ pogPointList = pogPointList->next; } pogObjList = pogObjList->next; } polObjList = p->polylineObjList; while(polObjList) { polPointList = polObjList->polylineObj->pointList; while(polPointList) { polPoint = polPointList->point; /* TODO: embPattern_calcBoundingBox for polylines */ polPointList = polPointList->next; } polObjList = polObjList->next; } rObjList = p->rectObjList; while(rObjList) { rect = rObjList->rectObj.rect; /* TODO: embPattern_calcBoundingBox for rectangles */ rObjList = rObjList->next; } sObjList = p->splineObjList; while(sObjList) { bezier = sObjList->splineObj.bezier; /* TODO: embPattern_calcBoundingBox for splines */ sObjList = sObjList->next; } return boundingRect; }