memononen / libtess2

Game and tools oriented refactored version of GLU tesselator.
Other
465 stars 98 forks source link

Add a reversed flag to tessAddContour() #27

Closed mindbrix closed 6 years ago

mindbrix commented 6 years ago

Need to sort this out

memononen commented 6 years ago

You just allocate an array of points and put your points in reversed order there before adding the contour. Like this:

// The points
float* pts = ...;
int npts = ...;

float* rev = malloc(sizeof(float)*2*npts);
float* dst = &rev[(npts-1)*2];
float* src = pts;
for (int i = 0; i < npts; i++) {
  dst[0] = src[0];
  dst[1] = src[1];
  dst -= 2:
  src += 2;
}

tessAddContour(...);

free(rev);

People often need to change the contours from their internal format to the one used by libtess2, that is a good spot to put the reversing code too.

mindbrix commented 6 years ago

Hi. The flag was added to optimise away this extra allocation and copy.

memononen commented 6 years ago

Fair enough. I would not like to break the API for tessAddContour(). I would like to keep the function to bare minimum, just enough params that are required to pass in a contour.

How about:

tessSetOption(tess, TESS_REVERSE_CONTOUR);
tessAddContour(...);

I'm not super proud of tessSetOption() either, but it seemed like the best compromise for tessTesselate(), so maybe for this case too.

mindbrix commented 6 years ago

Yes. Better to just break my code than everyone else's ;-)

28 adds support for TESS_REVERSE_CONTOUR option