Gnome2-Canvas

 view release on metacpan or  search on metacpan

xs/GnomeCanvasUtil.xs  view on Meta::CPAN

                                const char * package,
                                SV         * sv)
{
	GnomeCanvasPoints * points;
	AV * av;
	int i, n;

	if (!sv || !SvROK (sv) || SvTYPE (SvRV (sv)) != SVt_PVAV)
		return NULL;

	av = (AV*) SvRV (sv);
	n = av_len (av) + 1;

	points = gperl_alloc_temp (sizeof (GnomeCanvasPoints));
	points->ref_count = 1;
	points->num_points = n / 2;
	points->coords = gperl_alloc_temp (sizeof (double) * n);

	for (i = 0 ; i < n ; i++) {
		SV ** svp = av_fetch (av, i, FALSE);
		points->coords[i] = svp ? SvNV (*svp) : 0.0;
	}

	return points;
}


MODULE = Gnome2::Canvas::Util	PACKAGE = Gnome2::Canvas::Points	PREFIX = gnome_canvas_points_

BOOT:
	/* override default wrapper implementation for GnomeCanvasPoints */
	gperl_register_boxed (GNOME_TYPE_CANVAS_POINTS,
	                      "Gnome2::Canvas::Points",
	                      &point_wrapper_class);

 ## not needed
###  GnomeCanvasPoints *gnome_canvas_points_new (int num_points) 
###  GnomeCanvasPoints *gnome_canvas_points_ref (GnomeCanvasPoints *points) 
###  void gnome_canvas_points_free (GnomeCanvasPoints *points) 

MODULE = Gnome2::Canvas::Util	PACKAGE = Gnome2::Canvas	PREFIX = gnome_canvas_

=for object Gnome2::Canvas::main
=cut

##  int gnome_canvas_get_miter_points (double x1, double y1, double x2, double y2, double x3, double y3, double width, double *mx1, double *my1, double *mx2, double *my2) 
=for apidoc
=for signature ($mx1, $my1, $mx2, $my2) = Gnome2::Canvas->get_miter_points ($x1, $y1, $x2, $y2, $x3, $y3, $width)
=cut
void
gnome_canvas_get_miter_points (class, x1, y1, x2, y2, x3, y3, width)
	double x1
	double y1
	double x2
	double y2
	double x3
	double y3
	double width
    PREINIT:
	double mx1, my1, mx2, my2;
    PPCODE:
	if (!gnome_canvas_get_miter_points (x1, y1, x2, y2, x3, y3, width,
	                                    &mx1, &my1, &mx2, &my2))
		XSRETURN_EMPTY;
	EXTEND (SP, 4);
	PUSHs (sv_2mortal (newSVnv (mx1)));
	PUSHs (sv_2mortal (newSVnv (my1)));
	PUSHs (sv_2mortal (newSVnv (mx2)));
	PUSHs (sv_2mortal (newSVnv (my2)));

##  void gnome_canvas_get_butt_points (double x1, double y1, double x2, double y2, double width, int project, double *bx1, double *by1, double *bx2, double *by2) 
=for apidoc
=for signature ($bx1, $by1, $bx2, $by2) = Gnome2::Canvas->get_butt_points ($x1, $y1, $x2, $y2, $width, $project)
=cut
void
gnome_canvas_get_butt_points (class, x1, y1, x2, y2, width, project)
	double x1
	double y1
	double x2
	double y2
	double width
	int project
    PREINIT:
	double bx1, by1, bx2, by2;
    PPCODE:
	gnome_canvas_get_butt_points (x1, y1, x2, y2, width, project,
	                              &bx1, &by1, &bx2, &by2);
	EXTEND (SP, 4);
	PUSHs (sv_2mortal (newSVnv (bx1)));
	PUSHs (sv_2mortal (newSVnv (by1)));
	PUSHs (sv_2mortal (newSVnv (bx2)));
	PUSHs (sv_2mortal (newSVnv (by2)));

##  double gnome_canvas_polygon_to_point (double *poly, int num_points, double x, double y) 
=for apidoc
=for arg poly_ref (arrayref) coordinate pairs that make up the polygon
Return the distance from the point I<$x>,I<$y> to the polygon described by
the vertices in I<$poly_ref>, or zero if the point is inside the polygon.
=cut
double
gnome_canvas_polygon_to_point (class, poly_ref, x, y)
	SV *poly_ref
	double x
	double y
    PREINIT:
	double *poly;
	AV *array;
	int length, i;
    CODE:
	if (! (SvRV (poly_ref) && SvTYPE (SvRV (poly_ref)) == SVt_PVAV))
		croak ("the polygon parameter should be a reference to an "
		       "array of coordinate pairs");

	array = (AV *) SvRV (poly_ref);
	length = av_len (array) + 1;

	if (length % 2 != 0)
		croak ("the polygon array must contain x,y coordinate pairs,"
		       " so its length cannot be odd (got %d)", length);

	poly = g_new0 (double, length);

	for (i = 0; i < length; i += 2) {
		SV **value;
		value = av_fetch (array, i, 0);
		if (value && SvOK (*value))
			poly[i] = SvNV (*value);

		value = av_fetch (array, i + 1, 0);
		if (value && SvOK (*value))
			poly[i + 1] = SvNV (*value);
	}

	RETVAL = gnome_canvas_polygon_to_point (poly, length/2, x, y);

	g_free (poly);
    OUTPUT:
	RETVAL

###  void gnome_canvas_render_svp (GnomeCanvasBuf *buf, ArtSVP *svp, guint32 rgba) 
#void
#gnome_canvas_render_svp (buf, svp, rgba)
#	GnomeCanvasBuf *buf
#	ArtSVP *svp
#	guint32 rgba



( run in 1.218 second using v1.01-cache-2.11-cpan-5511b514fd6 )