21 void (*fn)(
void *,
const Ppoint_t *),
void *vc);
24 double d = (p1.
y - p2.
y) * (p3.
x - p2.
x) - (p3.
y - p2.
y) * (p1.
x - p2.
x);
40 const size_t pointn =
polygon->pn;
44 for (
size_t i = 0; i < pointn; i++)
62 void (*fn)(
void *,
const Ppoint_t *),
void *vc) {
66 for (
size_t i = 0; i < pointn; i++) {
67 const size_t ip1 = (i + 1) % pointn;
68 const size_t ip2 = (i + 2) % pointn;
75 for (i = 0; i < pointn; i++)
77 pointp[j++] = pointp[i];
91bool isdiagonal(
size_t i,
size_t ip2,
void *pointp,
size_t pointn,
96 const size_t ip1 = (i + 1) % pointn;
97 const size_t im1 = (i + pointn - 1) % pointn;
99 if (
ccw(indexer(pointp, im1), indexer(pointp, i), indexer(pointp, ip1)) ==
ISCCW)
100 res =
ccw(indexer(pointp, i), indexer(pointp, ip2), indexer(pointp, im1)) ==
ISCCW &&
101 ccw(indexer(pointp, ip2), indexer(pointp, i), indexer(pointp, ip1)) ==
ISCCW;
104 res =
ccw(indexer(pointp, i), indexer(pointp, ip2), indexer(pointp, ip1)) ==
ISCW;
110 for (
size_t j = 0; j < pointn; j++) {
111 const size_t jp1 = (j + 1) % pointn;
112 if (!(j == i || jp1 == i || j == ip2 || jp1 == ip2))
114 (indexer(pointp, i), indexer(pointp, ip2), indexer(pointp, j), indexer(pointp, jp1))) {
122 int ccw1, ccw2, ccw3, ccw4;
130 ccw1 =
ccw(pa, pb, pc) ==
ISCCW ? 1 : 0;
131 ccw2 =
ccw(pa, pb, pd) ==
ISCCW ? 1 : 0;
132 ccw3 =
ccw(pc, pd, pa) ==
ISCCW ? 1 : 0;
133 ccw4 =
ccw(pc, pd, pb) ==
ISCCW ? 1 : 0;
134 return (ccw1 ^ ccw2) && (ccw3 ^ ccw4);
144 return pca.
x * pba.
x + pca.
y * pba.
y >= 0 &&
145 pca.
x * pca.
x + pca.
y * pca.
y <= pba.
x * pba.
x + pba.
y * pba.
y;
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
Ppoint_t(* indexer_t)(void *base, size_t index)
bool intersects(Ppoint_t pa, Ppoint_t pb, Ppoint_t pc, Ppoint_t pd)
line to line intersection
bool isdiagonal(size_t i, size_t ip2, void *pointp, size_t pointn, indexer_t indexer)
is (i, i + 2) a diagonal?
bool between(Ppoint_t pa, Ppoint_t pb, Ppoint_t pc)
is pb between pa and pc?
static Ppoint_t point_indexer(void *base, size_t index)
int ccw(Ppoint_t p1, Ppoint_t p2, Ppoint_t p3)
are the given points counter-clockwise, clockwise, or co-linear?
static int triangulate(Ppoint_t **pointp, size_t pointn, void(*fn)(void *, const Ppoint_t *), void *vc)
int Ptriangulate(Ppoly_t *polygon, void(*fn)(void *, const Ppoint_t *), void *vc)