int
pc_patch_uncompressed_add_point(PCPATCH_UNCOMPRESSED *c, const PCPOINT *p)
{
	size_t sz;
	uint8_t *ptr;
	double x, y;

	if ( ! ( c && p ) )
	{
		pcerror("%s: null point or patch argument", __func__);
		return PC_FAILURE;
	}

	if ( c->schema->pcid != p->schema->pcid )
	{
		pcerror("%s: pcids of point (%d) and patch (%d) not equal", __func__, c->schema->pcid, p->schema->pcid);
		return PC_FAILURE;
	}

	if ( c->readonly )
	{
		pcerror("%s: cannot add point to readonly patch", __func__);
		return PC_FAILURE;
	}

	if ( c->type != PC_NONE )
	{
		pcerror("%s: cannot add point to compressed patch", __func__);
		return PC_FAILURE;
	}

	sz = c->schema->size;

	/* Double the data buffer if it's already full */
	if ( c->npoints == c->maxpoints )
	{
		c->maxpoints *= 2;
		c->datasize = c->maxpoints * sz;
		c->data = pcrealloc(c->data, c->datasize);
	}

	/* Copy the data buffer from point to patch */
	ptr = c->data + sz * c->npoints;
	memcpy(ptr, p->data, sz);
	c->npoints += 1;

	/* Update bounding box */
	x = pc_point_get_x(p);
	y = pc_point_get_y(p);
	if ( c->bounds.xmin > x ) c->bounds.xmin = x;
	if ( c->bounds.ymin > y ) c->bounds.ymin = y;
	if ( c->bounds.xmax < x ) c->bounds.xmax = x;
	if ( c->bounds.ymax < y ) c->bounds.ymax = y;

	return PC_SUCCESS;
}
Пример #2
0
static void
bytebuffer_memcpy(bytebuffer_t *bb, void *ptr, size_t sz)
{
    size_t cursz = bb->ptr - bb->buf;
    if ( (bb->sz - cursz) < sz )
    {
        bb->sz *= 2;
        bb->buf = pcrealloc(bb->buf, bb->sz);
        bb->ptr = bb->buf + cursz;
    }
    memcpy(bb->ptr, ptr, sz);
    bb->ptr += sz;
}
Пример #3
0
void
pc_pointlist_add_point(PCPOINTLIST *pl, PCPOINT *pt)
{
	if ( pl->npoints >= pl->maxpoints )
	{
		if ( pl->maxpoints < 1 ) pl->maxpoints = 1;
		pl->maxpoints *= 2;
		pl->points = pcrealloc(pl->points, pl->maxpoints * sizeof(PCPOINT*));
	}

	pl->points[pl->npoints] = pt;
	pl->npoints += 1;
	return;
}