Exemplo n.º 1
0
typename range_value_type<CVsRange>::type
evaluate( std::size_t degree,
          const CVsRange& cvs,
          const KnotsRange& knots,
          typename range_value_type<KnotsRange>::type u)
{
    BOOST_CONCEPT_ASSERT(( boost::RandomAccessRangeConcept<CVsRange>));
    BOOST_CONCEPT_ASSERT(( boost::RandomAccessRangeConcept<KnotsRange>));

    std::size_t span = find_span( degree, boost::size( cvs), knots, u);

    boost::array<typename range_value_type<KnotsRange>::type, NURBS_MAX_BASIS_DEGREE> N;
    basis_functions( degree, u, span, knots, N.begin());
    return evaluate( degree, cvs, N, span, u);
}
Exemplo n.º 2
0
/**
 * Plot a polygon
 *
 * \param  nsfb	 framebuffer context
 * \param  p	 array of polygon vertices (x1, y1, x2, y2, ... , xN, yN)
 * \param  n	 number of polygon vertices (N)
 * \param  c	 fill colour
 * \return true	 if no errors
 */
static bool polygon(nsfb_t *nsfb, const int *p, unsigned int n, nsfb_colour_t c)
{
    int poly_x0, poly_y0; /* Bounding box top left corner */
    int poly_x1, poly_y1; /* Bounding box bottom right corner */
    int i, j; /* indexes */
    int x0, x1; /* filled span extents */
    int y; /* current y coordinate */
    int y_max; /* bottom of plot area */
    nsfb_bbox_t fline;
    nsfb_plot_pen_t pen;

    /* find no. of vertex values */
    int v = n * 2;

    /* Can't plot polygons with 2 or fewer vertices */
    if (n <= 2)
	return true;

    pen.stroke_colour = c;

    /* Find polygon bounding box */
    poly_x0 = poly_x1 = *p;
    poly_y0 = poly_y1 = p[1];
    for (i = 2; i < v; i = i + 2) {
	j = i + 1;
	if (p[i] < poly_x0)
	    poly_x0 = p[i];
	else if (p[i] > poly_x1)
	    poly_x1 = p[i];
	if (p[j] < poly_y0)
	    poly_y0 = p[j];
	else if (p[j] > poly_y1)
	    poly_y1 = p[j];
    }

    /* Don't try to plot it if it's outside the clip rectangle */
    if (nsfb->clip.y1 < poly_y0 ||
	nsfb->clip.y0 > poly_y1 ||
	nsfb->clip.x1 < poly_x0 ||
	nsfb->clip.x0 > poly_x1)
	return true;

    /* Find the top of the important area */
    if (poly_y0 > nsfb->clip.y0)
	y = poly_y0;
    else
	y = nsfb->clip.y0;

    /* Find the bottom of the important area */
    if (poly_y1 < nsfb->clip.y1)
	y_max = poly_y1;
    else
	y_max = nsfb->clip.y1;

    for (; y < y_max; y++) {
	x1 = poly_x0 - 1;
	/* For each row */
	while (find_span(p, v, x1 + 1, y, &x0, &x1)) {
	    /* don't draw anything outside clip region */
	    if (x1 < nsfb->clip.x0)
		continue;
	    else if (x0 < nsfb->clip.x0)
		x0 = nsfb->clip.x0;
	    if (x0 > nsfb->clip.x1)
		break;
	    else if (x1 > nsfb->clip.x1)
		x1 = nsfb->clip.x1;

	    fline.x0 = x0;
	    fline.y0 = y;
	    fline.x1 = x1;
	    fline.y1 = y;

	    /* draw this filled span on current row */
	    nsfb->plotter_fns->line(nsfb, 1, &fline, &pen);

	    /* don't look for more spans if already at end of clip
	     * region or polygon */
	    if (x1 == nsfb->clip.x1 || x1 == poly_x1)
		break;
	}
    }
    return true;
}