Example #1
0
static unsigned int pf_ear_tip_find(PolyFill *pf)
#endif
{
	/* localize */
	const eSign *coords_sign = pf->coords_sign;
	const unsigned int coords_tot = pf->coords_tot;

	unsigned int i;


	i = coords_tot;
	while (i--) {
#ifdef USE_CLIP_EVEN
		unsigned int j = (i + index_offset) % coords_tot;
		if (pf_ear_tip_check(pf, j)) {
			return j;
		}
#else
		if (pf_ear_tip_check(pf, i)) {
			return i;
		}
#endif
	}

	/* Desperate mode: if no vertex is an ear tip, we are dealing with a degenerate polygon (e.g. nearly collinear).
	 * Note that the input was not necessarily degenerate, but we could have made it so by clipping some valid ears.
	 *
	 * Idea taken from Martin Held, "FIST: Fast industrial-strength triangulation of polygons", Algorithmica (1998),
	 * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.115.291
	 *
	 * Return a convex or tangential vertex if one exists.
	 */

	i = coords_tot;
	while (i--) {
#ifdef USE_CLIP_EVEN
		unsigned int j = (i + index_offset) % coords_tot;
		if (coords_sign[j] != CONCAVE) {
			return j;
		}
#else
		if (coords_sign[i] != CONCAVE) {
			return i;
		}
#endif
	}

	/* If all vertices are concave, just return the last one. */
	return coords_tot - 1;
}
Example #2
0
static PolyIndex *pf_ear_tip_find(
        PolyFill *pf
#ifdef USE_CLIP_EVEN
        , PolyIndex *pi_ear_init
#endif
#ifdef USE_CLIP_SWEEP
        , bool reverse
#endif
        )
{
	/* localize */
	const unsigned int coords_tot = pf->coords_tot;
	PolyIndex *pi_ear;

	unsigned int i;

#ifdef USE_CLIP_EVEN
	pi_ear = pi_ear_init;
#else
	pi_ear = pf->indices;
#endif

	i = coords_tot;
	while (i--) {
		if (pf_ear_tip_check(pf, pi_ear)) {
			return pi_ear;
		}
#ifdef USE_CLIP_SWEEP
		pi_ear = reverse ? pi_ear->prev : pi_ear->next;
#else
		pi_ear = pi_ear->next;
#endif
	}

	/* Desperate mode: if no vertex is an ear tip, we are dealing with a degenerate polygon (e.g. nearly collinear).
	 * Note that the input was not necessarily degenerate, but we could have made it so by clipping some valid ears.
	 *
	 * Idea taken from Martin Held, "FIST: Fast industrial-strength triangulation of polygons", Algorithmica (1998),
	 * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.115.291
	 *
	 * Return a convex or tangential vertex if one exists.
	 */

#ifdef USE_CLIP_EVEN
	pi_ear = pi_ear_init;
#else
	pi_ear = pf->indices;
#endif

	i = coords_tot;
	while (i--) {
		if (pi_ear->sign != CONCAVE) {
			return pi_ear;
		}
		pi_ear = pi_ear->next;
	}

	/* If all vertices are concave, just return the last one. */
	return pi_ear;
}