<commit_before>#include "clar.h"

#include "poly.h"

klist_t(poly) *faces = NULL;
poly_t *top = NULL;
poly_t *bottom = NULL;

void test_polygon__initialize(void) {
	faces = kl_init(poly);

	// Set up two triangles, one on top of each other
	// stored in list `faces` for easy cleanup
	// and refferenced in `top` and `bottom`
	// used for inversion testing.

	float3 fs[] = {{-0.5, 0.0, 0.0},
				   {0.5, 0.0, 0.0},
				   {0.0, 0.5, 0.0}};
	bottom = poly_make_triangle(fs[0], fs[1], fs[2]);
	cl_assert_(bottom != NULL, "Out of memory");
	*kl_pushp(poly, faces) = bottom;

	for(int i = 0; i < 3; i++) {
		fs[i][2] += 1.0;
	}
	top = poly_make_triangle(fs[0], fs[1], fs[2]);
	cl_assert_(top != NULL, "Out of memory");
	*kl_pushp(poly, faces) = top;

	cl_assert_equal_i(poly_classify_poly(top, bottom), BACK);
	cl_assert_equal_i(poly_classify_poly(bottom, top), FRONT);
}

void test_polygon__cleanup(void) {
	if(faces) kl_destroy(poly, faces);
}

void test_polygon__inverting_top_makes_bottom_front(void) {
	cl_assert_equal_i(poly_classify_poly(top, bottom), BACK);
	poly_t *p = poly_invert(top);
	cl_assert_(p == top, "poly_invert() should return identity");

	cl_assert_equal_i(poly_classify_poly(top, bottom), FRONT);
	poly_update(top);
	cl_assert_equal_i(poly_classify_poly(top, bottom), FRONT);
}

void test_polygon__add_more_than_max_polys(void) {
	poly_t *p = alloc_poly();
	cl_assert(p != NULL);

	float3 point = FLOAT3_INIT;
	for(int i = 0; i < POLY_MAX_VERTS * 2; i++) {
		poly_push_vertex(p, point);
		// Might as well build a legitimate polygon
		f3X(point) += 1.0;
		f3Y(point) += 1.0;
	}

	cl_assert_(poly_vertex_count(p) > POLY_MAX_VERTS, "Polygon should have more vertex than the static maximum.");
	cl_assert_(poly_vertex_max(p) > POLY_MAX_VERTS, "The maximum verts in the polygon should exceed the static maximum.");

	if(p != NULL) free_poly(p, 1);
}<commit_msg>Extend the test to test the last vert == the last pushed vert<commit_after>#include "clar.h"

#include "poly.h"

klist_t(poly) *faces = NULL;
poly_t *top = NULL;
poly_t *bottom = NULL;

void test_polygon__initialize(void) {
	faces = kl_init(poly);

	// Set up two triangles, one on top of each other
	// stored in list `faces` for easy cleanup
	// and refferenced in `top` and `bottom`
	// used for inversion testing.

	float3 fs[] = {{-0.5, 0.0, 0.0},
				   {0.5, 0.0, 0.0},
				   {0.0, 0.5, 0.0}};
	bottom = poly_make_triangle(fs[0], fs[1], fs[2]);
	cl_assert_(bottom != NULL, "Out of memory");
	*kl_pushp(poly, faces) = bottom;

	for(int i = 0; i < 3; i++) {
		fs[i][2] += 1.0;
	}
	top = poly_make_triangle(fs[0], fs[1], fs[2]);
	cl_assert_(top != NULL, "Out of memory");
	*kl_pushp(poly, faces) = top;

	cl_assert_equal_i(poly_classify_poly(top, bottom), BACK);
	cl_assert_equal_i(poly_classify_poly(bottom, top), FRONT);
}

void test_polygon__cleanup(void) {
	if(faces) kl_destroy(poly, faces);
}

void test_polygon__inverting_top_makes_bottom_front(void) {
	cl_assert_equal_i(poly_classify_poly(top, bottom), BACK);
	poly_t *p = poly_invert(top);
	cl_assert_(p == top, "poly_invert() should return identity");

	cl_assert_equal_i(poly_classify_poly(top, bottom), FRONT);
	poly_update(top);
	cl_assert_equal_i(poly_classify_poly(top, bottom), FRONT);
}

void test_polygon__add_more_than_max_polys(void) {
	poly_t *p = alloc_poly();
	cl_assert(p != NULL);

	float3 point = FLOAT3_INIT;
	for(int i = 0; i < POLY_MAX_VERTS * 2; i++) {
		// Might as well build a legitimate polygon
		f3X(point) += 1.0;
		f3Y(point) += 1.0;
		poly_push_vertex(p, point);
	}

	cl_assert_(poly_vertex_count(p) > POLY_MAX_VERTS, "Polygon should have more vertex than the static maximum.");
	cl_assert_(poly_vertex_max(p) > POLY_MAX_VERTS, "The maximum verts in the polygon should exceed the static maximum.");

	float3 *last = &p->vertices[poly_vertex_count(p) - 1];

	cl_assert_(f3X(point) == f3X(*last), "The last point in the poly should be the last point we pushed.");

	if(p != NULL) free_poly(p, 1);
}
{'fraction_non_alphanumeric': 0.1509196271101033, 'fraction_numerical': 0.021667926429831192, 'mean_word_length': 4.872781065088757, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '59073', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1578, 'n_words': 384}