/* The rim may have tiny hole fragments due to rounding error, see
   off_rnd_05as2: placing one radial edge would cross another but
   due to the crossing point the resulting radial line's slope changes.
   Placing an overlapping radial for the next segment should have the same
   slope but because the previous slope changed a tiny triangular hole is
   formed. This code removes any first level negative island from the rim
   union whose area is smaller than hole_area_thrs, which should be comparable
   to the offset value. */
RND_INLINE void pb2_offset3_remove_rim_spikes(pb2_ctx_t *ctx, double hole_area_thrs)
{
	pb2_face_t *f = ctx->root.children;
/*fprintf(stderr, "FACES! %p offs2=%f\n", (void *)f, hole_area_thrs);*/
	if (f == NULL)
		return;

	/* list holes in the union */
	for(f = f->children; f != NULL; f = f->next) {
/*		fprintf(stderr, " negface %p %f\n", f, f->area);*/
		if (f->area < hole_area_thrs) {
/*			fprintf(stderr, "  REMOVE\n");*/
			f->destroy = 1;
		}
	}
}

/* Add the next segment incrementally to the rim, remove tiny cutouts formed
   due to rounding errors */
void pb2_offset3_rim_incremental(pb2_ctx_t *ctx, double hole_area_thrs)
{
	pb2_exec_inner(ctx);
	pb2_offset3_remove_rim_spikes(ctx, hole_area_thrs);
	pb2_7_output(ctx, NULL);
}
