[LIBART] more on clipping



In an effort to figure out why clipping (art_svp_intersect) wasn't
working for me as expected, I wrote some standalone code modeled after
testart.c.

In this example, the clipping works (mostly) as expected (the arc is
clipped to within the box) but there is an unexpected horizontal line
that extends across the image.  From my understanding of intersect,
the image should just show the arc fragment.  Here is the output

  http://nitace.bsd.uchicago.edu:8080/files/share/jdh.ppm

I would be much obliged if a libart veteran could provide some
insight.  I've spent many hours pouring over the src code of libart,
gnome canvas, gnome print, python paint, reading the gnome docs, and
I'm still stumped by the strange clipping behavior I'm observing.
I've seem many references issues of numerical stability and path
intersection, but don't know if that is what I'm observing here.

//gcc -I/usr/include/libart-2.0/ clip3.c -lart_lgpl_2

#include <stdio.h>
#include <libart_lgpl/art_svp_vpath.h>
#include <libart_lgpl/art_svp_ops.h>
#include <libart_lgpl/art_svp_vpath_stroke.h>
#include <libart_lgpl/art_render_svp.h>
#include <libart_lgpl/art_svp_intersect.h>

#define BYTES_PP 3

static void
output_svp_ppm (const ArtSVP *svp, int color)
{
  art_u8 buf[100 * 100 * 3];
  art_rgb_svp_aa (svp, 0, 0, 100, 100, color, 0x000080, 
		  buf, 100 * 3, NULL);
  printf ("P6\n100 100\n255\n");
  fwrite (buf, 1, 100 * 100 * 3, stdout);
}

static void
print_svp (ArtSVP *vp)
{
  int i, j;

  for (i = 0; i < vp->n_segs; i++)
    {
      printf ("segment %d, dir = %s (%f, %f) - (%f, %f)\n",
	      i, vp->segs[i].dir ? "down" : "up",
	      vp->segs[i].bbox.x0,
	      vp->segs[i].bbox.y0,
	      vp->segs[i].bbox.x1,
	      vp->segs[i].bbox.y1);
      for (j = 0; j < vp->segs[i].n_points; j++)
        printf ("  (%g, %g)\n",
                vp->segs[i].points[j].x,
                vp->segs[i].points[j].y);
    }
}

int
main (int argc, char **argv)
{

  ArtVpath vpath1[] = {  // a square
    { ART_MOVETO, 20, 10 },
    { ART_LINETO, 20, 50 },
    { ART_LINETO, 70, 50 },
    { ART_LINETO, 70, 10 },
    { ART_LINETO, 70, 10 },
    { ART_END, 0, 0}
  };


  ArtVpath vpath2[] = {
    { ART_LINETO, 40, 10},
    { ART_LINETO, 42, 10},
    { ART_LINETO, 45, 11},
    { ART_LINETO, 48, 12},
    { ART_LINETO, 50, 14},
    { ART_LINETO, 53, 17},
    { ART_LINETO, 55, 20},
    { ART_LINETO, 56, 23},
    { ART_LINETO, 58, 27},
    { ART_LINETO, 59, 31},
    { ART_LINETO, 59, 35},
    { ART_LINETO, 60, 40},
    { ART_LINETO, 59, 44},
    { ART_LINETO, 59, 48},
    { ART_LINETO, 58, 52},
    { ART_LINETO, 56, 56},
    { ART_LINETO, 55, 59},
    { ART_LINETO, 53, 62},
    { ART_LINETO, 50, 65},
    { ART_LINETO, 48, 67},
    { ART_LINETO, 45, 68},
    { ART_LINETO, 42, 69},
    { ART_LINETO, 40, 70},
    { ART_END, 0, 0}
  };
  ArtSVP *svp1, *svp2, *svp3;

  svp1 = art_svp_from_vpath (vpath1);
  svp2 = art_svp_vpath_stroke (vpath2,
			       ART_PATH_STROKE_JOIN_MITER,
			       ART_PATH_STROKE_CAP_BUTT,
			        5,
			       4,
			       0.5);


  svp3 = art_svp_intersect(svp1, svp2);  
  //print_svp(svp3);
  output_svp_ppm (svp3, 0x00ee80);
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]