示例#1
0
文件: attrlist.c 项目: kaiaie/bile
bool AttrList_setItem(AttrList l, String key, int v){
   bool   retVal = false;
   int    idx    = -1;
   size_t i;
   String tmpKey;

   idx = getIndex(l);
   if(idx >= 0){
      if(!keyExists(l, key)){
         if(attrListPool[idx].length == (attrListPool[idx].size - 1)){
            growList(idx, (attrListPool[idx].size * 2));
         }
         for(i = 0; i < attrListPool[idx].size; ++i){
            if(attrListPool[idx].keys[i] == INVALID_STRING){
               break;
            }
         }
         tmpKey = new_String(NULL);
         if(tmpKey != INVALID_STRING && String_copyString(tmpKey, key)){
            attrListPool[idx].keys[i] = tmpKey;
            attrListPool[idx].data[i] = v;
            attrListPool[idx].length++;
            retVal = true;
         }
      }
   }
   return retVal;
}
示例#2
0
文件: ejsList.c 项目: embedthis/ejs-1
/*
 *  Insert an item to the list at a specified position. We insert before "index".
 */
int ejsInsertItemAtPos(MprCtx ctx, EjsList *lp, int index, cvoid *item)
{
    void    **items;
    int     i;

    mprAssert(lp);
    mprAssert(lp->length >= 0);

    if (lp->length >= CAPACITY(lp->items)) {
        if (growList(ctx, lp, 1) < 0) {
            return MPR_ERR_TOO_MANY;
        }
    }

    /*
     *  Copy up items to make room to insert
     */
    items = lp->items;
    for (i = lp->length; i > index; i--) {
        items[i] = items[i - 1];
    }
    lp->items[index] = (void*) item;
    lp->length++;
    return index;
}
/*
  =======================================================================================
  =======================================================================================
*/
PixelChain& PixelChain::operator=(PixelChain &rhs)
{
	if (this != &rhs) {
		if (_pt) {
			delete [] _pt;
			_pt = NULL;
		}

		_maxPoints = 0;
		_numPoints = 0;

		if (rhs._numPoints > 0) {
			if (growList(rhs._numPoints)) {
				memcpy(_pt, rhs._pt, rhs._numPoints * sizeof(_pt[0]));
				_numPoints = rhs._numPoints;
			}
		}

		_maxFeretAngle = rhs._maxFeretAngle;
		_maxFeretDiameter = rhs._maxFeretDiameter;
		_boundingRect = rhs._boundingRect;
	}

	return *this;
}
示例#4
0
void LinePath::createHeadLines() {
    m_HeadList.clear();
    QCanvas * canvas = getCanvas();
    switch( getAssocType() ) {
    case Uml::at_Activity:
    case Uml::at_State:
    case Uml::at_Dependency:
    case Uml::at_UniAssociation:
    case Uml::at_Relationship:
        growList(m_HeadList, 2);
        break;

    case Uml::at_Generalization:
    case Uml::at_Realization:
        growList(m_HeadList, 3);
        m_pClearPoly = new QCanvasPolygon( canvas );
        m_pClearPoly -> setVisible( true );
        m_pClearPoly -> setBrush( QBrush( Qt::white ) );
        m_pClearPoly -> setZ( -1 );
        break;

    case Uml::at_Composition:
    case Uml::at_Aggregation:
        growList(m_HeadList, 4);
        m_pClearPoly = new QCanvasPolygon( canvas );
        m_pClearPoly -> setVisible( true );
        if( getAssocType() == Uml::at_Aggregation )
            m_pClearPoly -> setBrush( QBrush( Qt::white ) );
        else
            m_pClearPoly -> setBrush( QBrush( getLineColor() ) );
        m_pClearPoly -> setZ( -1 );
        break;

    case Uml::at_Containment:
        growList(m_HeadList, 1);
        if (!m_pCircle) {
            m_pCircle = new Circle( canvas, 6 );
            m_pCircle->show();
            m_pCircle->setPen( QPen( getLineColor(), getLineWidth() ) );
        }
        break;
    default:
        break;
    }
    m_bHeadCreated = true;
}
/*
  =======================================================================================
  =======================================================================================
*/
bool PixelChain::load(double max_feret_angle, double max_feret_diameter,
					  int left, int right, int top, int bottom,
					  int num_points, long *chain_id, long *x, long *y)
{
	_numPoints = 0;

	if (num_points < 1) {
		return true;
	}

	if (!chain_id || !x || !y) {
		return false;
	}

	// we only care about the outer chain, chain_id == 1
	for (_numPoints = 0; _numPoints < num_points; _numPoints++) {
		if (chain_id[_numPoints] != 1) {
			break;
		}
	}

	if (_numPoints == 0) {
		// should never happen
		return false;
	}

	if (_numPoints > _maxPoints) {
		if (!growList(_numPoints)) {
			return false;
		}
	}

	for (int i = 0; i < _numPoints; i++) {
		_pt[i].x = x[i];
		_pt[i].y = y[i];
	}

	_maxFeretAngle = max_feret_angle;
	_maxFeretDiameter = max_feret_diameter;
	_boundingRect.left = left;
	_boundingRect.right = right;
	_boundingRect.top = top;
	_boundingRect.bottom = bottom;

	return true;
}
示例#6
0
文件: ejsList.c 项目: embedthis/ejs-1
/*
 *  Add an item to the list and return the item index.
 */
int ejsAddItem(MprCtx ctx, EjsList *lp, cvoid *item)
{
    int     index, capacity;

    mprAssert(lp);
    mprAssert(lp->length >= 0);

    capacity = CAPACITY(lp->items);
    mprAssert(capacity >= 0);

    if (lp->items == 0 || lp->length >= capacity) {
        if (growList(ctx, lp, 1) < 0) {
            return MPR_ERR_TOO_MANY;
        }
    }
    index = lp->length++;
    lp->items[index] = (void*) item;
    return index;
}
示例#7
0
文件: ejsList.c 项目: embedthis/ejs-1
/*
 *  Change the item in the list at index. Return the old item.
 */
void *ejsSetItem(MprCtx ctx, EjsList *lp, int index, cvoid *item)
{
    void    *old;

    mprAssert(lp);
    mprAssert(lp->length >= 0);

    if (index >= lp->length) {
        lp->length = index + 1;
    }
    capacity = CAPACITY(lp->items);
    if (lp->length > capacity) {
        if (growList(ctx, lp, lp->length - capacity) < 0) {
            return 0;
        }
    }
    old = lp->items[index];
    lp->items[index] = (void*) item;
    return old;
}
示例#8
0
/*
 * Store the list of segments for a single level in the SEXP
 * list that will be returned to the user
 */
static
int addContourLines(double *x, int nx, double *y, int ny,
		     double *z, double zc, double atom,
		     SEGP* segmentDB, int nlines, SEXP container)
{
    double xend, yend;
    int i, ii, j, jj, ns, dir, nc;
    SEGP seglist, seg, s, start, end;
    SEXP ctr, level, xsxp, ysxp, names;
    /* Begin following contours. */
    /* 1. Grab a segment */
    /* 2. Follow its tail */
    /* 3. Follow its head */
    /* 4. Save the contour */
    for (i = 0; i < nx - 1; i++)
	for (j = 0; j < ny - 1; j++) {
	    while ((seglist = segmentDB[i + j * nx])) {
		ii = i; jj = j;
		start = end = seglist;
		segmentDB[i + j * nx] = seglist->next;
		xend = seglist->x1;
		yend = seglist->y1;
		while ((dir = ctr_segdir(xend, yend, x, y,
					 &ii, &jj, nx, ny))) {
		    segmentDB[ii + jj * nx]
			= ctr_segupdate(xend, yend, dir, TRUE,/* = tail */
					segmentDB[ii + jj * nx], &seg);
		    if (!seg) break;
		    end->next = seg;
		    end = seg;
		    xend = end->x1;
		    yend = end->y1;
		}
		end->next = nullptr; /* <<< new for 1.2.3 */
		ii = i; jj = j;
		xend = seglist->x0;
		yend = seglist->y0;
		while ((dir = ctr_segdir(xend, yend, x, y,
					 &ii, &jj, nx, ny))) {
		    segmentDB[ii + jj * nx]
			= ctr_segupdate(xend, yend, dir, FALSE,/* ie. head */
					segmentDB[ii+jj*nx], &seg);
		    if (!seg) break;
		    seg->next = start;
		    start = seg;
		    xend = start->x0;
		    yend = start->y0;
		}

		/* ns := #{segments of polyline} -- need to allocate */
		s = start;
		ns = 0;
		/* max_contour_segments: prevent inf.loop (shouldn't be needed) */
		while (s && ns < CXXRCONSTRUCT(int, max_contour_segments)) {
		    ns++;
		    s = s->next;
		}
		if(ns == CXXRCONSTRUCT(int, max_contour_segments))
		    warning(_("contour(): circular/long seglist -- set %s > %d?"), 
		            "options(\"max.contour.segments\")", max_contour_segments);
		/*
		 * "write" the contour locations into the list of contours
		 */
		ctr = PROTECT(allocVector(VECSXP, 3));
		level = PROTECT(allocVector(REALSXP, 1));
		xsxp = PROTECT(allocVector(REALSXP, ns + 1));
		ysxp = PROTECT(allocVector(REALSXP, ns + 1));
		REAL(level)[0] = zc;
		SET_VECTOR_ELT(ctr, CONTOUR_LIST_LEVEL, level);
		s = start;
		REAL(xsxp)[0] = s->x0;
		REAL(ysxp)[0] = s->y0;
		ns = 1;
		while (s->next && ns < CXXRCONSTRUCT(int, max_contour_segments)) {
		    s = s->next;
		    REAL(xsxp)[ns] = s->x0;
		    REAL(ysxp)[ns++] = s->y0;
		}
		REAL(xsxp)[ns] = s->x1;
		REAL(ysxp)[ns] = s->y1;
		SET_VECTOR_ELT(ctr, CONTOUR_LIST_X, xsxp);
		SET_VECTOR_ELT(ctr, CONTOUR_LIST_Y, ysxp);
		/*
		 * Set the names attribute for the contour
		 * So that users can extract components using
		 * meaningful names
		 */
		PROTECT(names = allocVector(STRSXP, 3));
		SET_STRING_ELT(names, 0, mkChar("level"));
		SET_STRING_ELT(names, 1, mkChar("x"));
		SET_STRING_ELT(names, 2, mkChar("y"));
		setAttrib(ctr, R_NamesSymbol, names);
		/*
		 * We're about to add another line to the list ...
		 */
		nlines += 1;
		nc = LENGTH(VECTOR_ELT(container, 0));
		if (nlines == nc)
		    /* Where does this get UNPROTECTed? */
		    SET_VECTOR_ELT(container, 0,
				   growList(VECTOR_ELT(container, 0)));
		SET_VECTOR_ELT(VECTOR_ELT(container, 0), nlines - 1, ctr);
		UNPROTECT(5);
	    }
	}
    return nlines;
}
示例#9
0
void LinePath::setupParallelLine() {
    m_ParallelList.clear();
    growList(m_ParallelList, 3);
    m_bParallelLineCreated = true;
}