23 void (*fn)(
void *,
const Ppoint_t *),
void *vc);
26 double d = (p1.
y - p2.
y) * (p3.
x - p2.
x) - (p3.
y - p2.
y) * (p1.
x - p2.
x);
42 const size_t pointn =
polygon->pn;
46 for (
size_t i = 0; i < pointn; i++)
64 void (*fn)(
void *,
const Ppoint_t *),
void *vc) {
68 for (
size_t i = 0; i < pointn; i++) {
69 const size_t ip1 = (i + 1) % pointn;
70 const size_t ip2 = (i + 2) % pointn;
77 for (i = 0; i < pointn; i++)
79 pointp[j++] = pointp[i];
99 return pca.
x * pba.
x + pca.
y * pba.
y >= 0 &&
100 pca.
x * pca.
x + pca.
y * pca.
y <= pba.
x * pba.
x + pba.
y * pba.
y;
105 int ccw1, ccw2, ccw3, ccw4;
113 ccw1 =
ccw(pa, pb, pc) ==
ISCCW ? 1 : 0;
114 ccw2 =
ccw(pa, pb, pd) ==
ISCCW ? 1 : 0;
115 ccw3 =
ccw(pc, pd, pa) ==
ISCCW ? 1 : 0;
116 ccw4 =
ccw(pc, pd, pb) ==
ISCCW ? 1 : 0;
117 return (ccw1 ^ ccw2) && (ccw3 ^ ccw4);
122bool isdiagonal(
size_t i,
size_t ip2,
void *pointp,
size_t pointn,
127 const size_t ip1 = (i + 1) % pointn;
128 const size_t im1 = (i + pointn - 1) % pointn;
130 if (
ccw(indexer(pointp, im1), indexer(pointp, i), indexer(pointp, ip1)) ==
ISCCW)
131 res =
ccw(indexer(pointp, i), indexer(pointp, ip2), indexer(pointp, im1)) ==
ISCCW &&
132 ccw(indexer(pointp, ip2), indexer(pointp, i), indexer(pointp, ip1)) ==
ISCCW;
135 res =
ccw(indexer(pointp, i), indexer(pointp, ip2), indexer(pointp, ip1)) ==
ISCW;
141 for (
size_t j = 0; j < pointn; j++) {
142 const size_t jp1 = (j + 1) % pointn;
143 if (!(j == i || jp1 == i || j == ip2 || jp1 == ip2))
145 (indexer(pointp, i), indexer(pointp, ip2), indexer(pointp, j), indexer(pointp, jp1))) {
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 isdiagonal(size_t i, size_t ip2, void *pointp, size_t pointn, indexer_t indexer)
is (i, i + 2) a diagonal?
static 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)
static bool intersects(Ppoint_t pa, Ppoint_t pb, Ppoint_t pc, Ppoint_t pd)
line to line intersection
int Ptriangulate(Ppoly_t *polygon, void(*fn)(void *, const Ppoint_t *), void *vc)