<commit_before>#include "fitz.h"

fz_shade *
fz_keepshade(fz_shade *shade)
{
	shade->refs ++;
	return shade;
}

void
fz_dropshade(fz_shade *shade)
{
	if (shade && --shade->refs == 0)
	{
		if (shade->cs)
			fz_dropcolorspace(shade->cs);
		fz_free(shade->mesh);
		fz_free(shade);
	}
}

fz_rect
fz_boundshade(fz_shade *shade, fz_matrix ctm)
{
	ctm = fz_concat(shade->matrix, ctm);
	return fz_transformrect(ctm, shade->bbox);
}

void
fz_debugshade(fz_shade *shade)
{
	int i, j, n;
	float *vert;

	printf("shade {\n");

	printf("  bbox [%g %g %g %g]\n",
		shade->bbox.x0, shade->bbox.y0,
		shade->bbox.x1, shade->bbox.y1);

	printf("  colorspace %s\n", shade->cs->name);

	printf("  matrix [%g %g %g %g %g %g]\n",
			shade->matrix.a, shade->matrix.b, shade->matrix.c,
			shade->matrix.d, shade->matrix.e, shade->matrix.f);

	if (shade->usebackground)
	{
		printf("  background [");
		for (i = 0; i < shade->cs->n; i++)
			printf("%s%g", i == 0 ? "" : " ", shade->background[i]);
		printf("]\n");
	}

	if (shade->usefunction)
	{
		printf("  function\n");
		n = 3;
	}
	else
		n = 2 + shade->cs->n;

	vert = shade->mesh;
	i = 0;
	while (i < shade->meshlen)
	{
		printf("  (%g, %g): ", vert[0], vert[1]);

		for (j = 2; j < n; j++)
			printf("%s%g", j == 2 ? "" : " ", vert[j]);
		printf("\n");

		vert += n;
		i++;
	}
<commit_msg>Improved debug printing of shading to show vertex grouping into triangles.<commit_after>#include "fitz.h"

fz_shade *
fz_keepshade(fz_shade *shade)
{
	shade->refs ++;
	return shade;
}

void
fz_dropshade(fz_shade *shade)
{
	if (shade && --shade->refs == 0)
	{
		if (shade->cs)
			fz_dropcolorspace(shade->cs);
		fz_free(shade->mesh);
		fz_free(shade);
	}
}

fz_rect
fz_boundshade(fz_shade *shade, fz_matrix ctm)
{
	ctm = fz_concat(shade->matrix, ctm);
	return fz_transformrect(ctm, shade->bbox);
}

void
fz_debugshade(fz_shade *shade)
{
	int i, j, n;
	float *vertex;
	int triangle;

	printf("shade {\n");

	printf("  bbox [%g %g %g %g]\n",
		shade->bbox.x0, shade->bbox.y0,
		shade->bbox.x1, shade->bbox.y1);

	printf("  colorspace %s\n", shade->cs->name);

	printf("  matrix [%g %g %g %g %g %g]\n",
			shade->matrix.a, shade->matrix.b, shade->matrix.c,
			shade->matrix.d, shade->matrix.e, shade->matrix.f);

	if (shade->usebackground)
	{
		printf("  background [");
		for (i = 0; i < shade->cs->n; i++)
			printf("%s%g", i == 0 ? "" : " ", shade->background[i]);
		printf("]\n");
	}

	if (shade->usefunction)
	{
		printf("  function\n");
		n = 3;
	}
	else
		n = 2 + shade->cs->n;

	printf("  triangles: %d\n", shade->meshlen);

	vertex = shade->mesh;
	triangle = 0;
	i = 0;
	while (i < shade->meshlen * 3)
	{
		printf("  %d:(%g, %g): ", triangle, vertex[0], vertex[1]);

		for (j = 2; j < n; j++)
			printf("%s%g", j == 2 ? "" : " ", vertex[j]);
		printf("\n");

		vertex += n;
		i++;
		if (i % 3 == 0)
			triangle++;
	}

{'fraction_non_alphanumeric': 0.22609001406469761, 'fraction_numerical': 0.011251758087201125, 'mean_word_length': 3.356814701378254, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1406879', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1308, 'n_words': 267}