45 static int dpd_isdiagonal(
int,
int,
Ppoint_t **,
int);
48 static void triangulate(
Ppoint_t ** pointp,
int pointn,
49 void (*fn) (
void *,
Ppoint_t *),
void *vc);
54 ((p1->
y - p2->
y) * (p3->
x - p2->
x)) -
55 ((p3->
y - p2->
y) * (p1->
x - p2->
x));
73 for (i = 0; i < pointn; i++)
74 pointp[i] = &(polygon->
ps[i]);
80 triangulate(pointp, pointn, fn, vc);
91 triangulate(
Ppoint_t ** pointp,
int pointn,
92 void (*fn) (
void *,
Ppoint_t *),
void *vc)
97 for (i = 0; i < pointn; i++) {
98 ip1 = (i + 1) % pointn;
99 ip2 = (i + 2) % pointn;
100 if (dpd_isdiagonal(i, ip2, pointp, pointn)) {
106 for (i = 0; i < pointn; i++)
108 pointp[j++] = pointp[i];
109 triangulate(pointp, pointn - 1, fn, vc);
123 static int dpd_isdiagonal(
int i,
int ip2,
Ppoint_t ** pointp,
int pointn)
125 int ip1, im1, j, jp1, res;
128 ip1 = (i + 1) % pointn;
129 im1 = (i + pointn - 1) % pointn;
131 if (dpd_ccw(pointp[im1], pointp[i], pointp[ip1]) ==
ISCCW)
132 res = (dpd_ccw(pointp[i], pointp[ip2], pointp[im1]) ==
ISCCW) &&
133 (dpd_ccw(pointp[ip2], pointp[i], pointp[ip1]) ==
ISCCW);
136 res = ((dpd_ccw(pointp[i], pointp[ip2], pointp[ip1]) ==
ISCW)
147 for (j = 0; j < pointn; j++) {
148 jp1 = (j + 1) % pointn;
149 if (!((j == i) || (jp1 == i) || (j == ip2) || (jp1 == ip2)))
151 (pointp[i], pointp[ip2], pointp[j], pointp[jp1])) {
162 int ccw1, ccw2, ccw3, ccw4;
164 if (dpd_ccw(pa, pb, pc) ==
ISON || dpd_ccw(pa, pb, pd) ==
ISON ||
165 dpd_ccw(pc, pd, pa) ==
ISON || dpd_ccw(pc, pd, pb) ==
ISON) {
166 if (dpd_between(pa, pb, pc) || dpd_between(pa, pb, pd) ||
167 dpd_between(pc, pd, pa) || dpd_between(pc, pd, pb))
170 ccw1 = (dpd_ccw(pa, pb, pc) ==
ISCCW) ? 1 : 0;
171 ccw2 = (dpd_ccw(pa, pb, pd) ==
ISCCW) ? 1 : 0;
172 ccw3 = (dpd_ccw(pc, pd, pa) ==
ISCCW) ? 1 : 0;
173 ccw4 = (dpd_ccw(pc, pd, pb) ==
ISCCW) ? 1 : 0;
174 return (ccw1 ^ ccw2) && (ccw3 ^ ccw4);
183 pba.
x = pb->
x - pa->
x, pba.
y = pb->
y - pa->
y;
184 pca.
x = pc->
x - pa->
x, pca.
y = pc->
y - pa->
y;
185 if (dpd_ccw(pa, pb, pc) !=
ISON)
187 return (pca.
x * pba.
x + pca.
y * pba.
y >= 0) &&
188 (pca.
x * pca.
x + pca.
y * pca.
y <= pba.
x * pba.
x + pba.
y * pba.
y);
int Ptriangulate(Ppoly_t *polygon, void(*fn)(void *closure, Ppoint_t tri[]), void *vc)
struct dpd_triangle ltriangle_t
struct lvertex_2_t lvertex_2_t