Ejemplo n.º 1
0
static PyObject *
vs_interpolate(PyGimpVectorsStroke *self, PyObject *args, PyObject *kwargs)
{
    double precision;
    double *coords;
    int i, num_coords;
    gboolean closed;
    PyObject *ret, *ret_coords;

    static char *kwlist[] = { "precision", NULL };

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "d:interpolate", kwlist,
                                     &precision))
        return NULL;

    coords = gimp_vectors_stroke_interpolate(self->vectors_ID, self->stroke,
                                             precision, &num_coords, &closed);

    ret = PyTuple_New(2);
    if (ret == NULL)
        return NULL;

    ret_coords = PyList_New(num_coords);
    if (ret_coords == NULL) {
        Py_DECREF(ret);
        return NULL;
    }

    for (i = 0; i < num_coords; i++)
        PyList_SetItem(ret_coords, i, PyFloat_FromDouble(coords[i]));

    PyTuple_SetItem(ret, 0, ret_coords);
    PyTuple_SetItem(ret, 1, PyBool_FromLong(closed));

    return ret;
}
void fill_stop_path_buffer_from_path(gint32 path_id) {
	int i,j,num_strokes;
	gint stroke_id;
#ifdef DEBUG
	g_warning("fill_stop_path_buffer_from_path with path_id = %d, previewWidth  = %d, height = %d",path_id,
			interface_vals.previewWidth,interface_vals.previewHeight );
#endif
	for (i = 0; i < interface_vals.previewWidth * interface_vals.previewHeight; i++)
			interface_vals.previewStopPath[i] = 0;
#ifdef DEBUG
	g_warning("fill_stop_path_buffer_from_path init finish",path_id);
#endif

	if (path_id <= 0) return;
	if (!gimp_vectors_is_valid(path_id)) {
		g_error("selected path is not valid!");
	}

	stroke_id = gimp_vectors_get_strokes(path_id,&num_strokes)[0];
#ifdef DEBUG
	g_warning("vectors has %d strokes, using stroke_id = %d",stroke_id);
#endif
	if (num_strokes > 0) {
		gboolean closed;
		gdouble   *coords;
		gint num_coords;
#ifdef DEBUG
		g_warning("going to interpolate");
#endif
		coords = gimp_vectors_stroke_interpolate(path_id,stroke_id,1.0,&num_coords,&closed);
#ifdef DEBUG
		g_warning("got %d interpolation points",num_coords/2);
#endif
		if (coords) {
			gint oldx,oldy;
			for (i = 0; i < num_coords; i+=2) {
				gint x = coords[i] - interface_vals.selectionX0;
				gint y = coords[i+1] - interface_vals.selectionY0;
#ifdef DEBUG
				g_warning("%d: putting in point x,y = %d,%d",i/2,x,y);
#endif

				if (x >= 0 && y >= 0 && x < interface_vals.previewWidth && y < interface_vals.previewHeight) {
					interface_vals.previewStopPath[y * interface_vals.previewWidth + x] = 1;
					if (i>0) {
						gdouble len = sqrt((gdouble)(x-oldx)*(x-oldx) + (gdouble)(y-oldy)*(y-oldy));
						if (len > 1) {
							gdouble xcoeff = (gdouble)(x-oldx) / len;
							gdouble ycoeff = (gdouble)(y-oldy) / len;
							for (j = 0; j < floor(len); ++j) {
								gint xtmp = ROUND(oldx + xcoeff*j);
								gint ytmp = ROUND(oldy + ycoeff*j);
								interface_vals.previewStopPath[ytmp * interface_vals.previewWidth + xtmp] = 1;
							}
						}
					}
				}
				oldx = x;
				oldy = y;
			}
			g_free(coords);
		}
	}
#ifdef DEBUG
	g_warning("fill_stop_path_buffer_from_path finished");
#endif

}