13 static double dist_plane(
double x,
double y,
const struct plane *p)
15 return x * p->
x + y * p->
y + p->
k;
18 static double interpolate(
double a,
double b,
double ka,
double kb)
20 return (a * kb - b * ka) / (kb - ka);
23 static void clip_path_plane(
struct path *
dst,
const struct path *src,
24 const struct plane *p)
29 double d0 = dist_plane(x0, y0, p);
34 for (i = 0; i < src->
count; i++) {
38 double d1 = dist_plane(x1, y1, p);
44 double x = interpolate(x0, x1, d0, d1);
45 double y = interpolate(y0, y1, d0, d1);
51 double x = interpolate(x0, x1, d0, d1);
52 double y = interpolate(y0, y1, d0, d1);
68 static void cull_path_plane(
struct path *dst,
const struct path *src,
69 const struct plane *p)
72 int prev = src->
count - 1;
76 double d0 = dist_plane(x0, y0, p);
81 for (i = 0; i < src->
count; i++) {
85 double d1 = dist_plane(x1, y1, p);
89 if (!in0 && in1 && last != prev) {
114 clip->left.k = rect->
left;
118 clip->rite.k = -rect->
rite;
122 clip->bot.k = rect->
bot;
131 struct path tmp1, tmp2;
136 cull_path_plane(&tmp1, src, &clip->left);
137 cull_path_plane(&tmp2, &tmp1, &clip->rite);
138 cull_path_plane(&tmp1, &tmp2, &clip->bot);
139 cull_path_plane(dst, &tmp1, &clip->
top);
147 struct path tmp1, tmp2;
152 clip_path_plane(&tmp1, src, &clip->left);
153 clip_path_plane(&tmp2, &tmp1, &clip->rite);
154 clip_path_plane(&tmp1, &tmp2, &clip->bot);
155 clip_path_plane(dst, &tmp1, &clip->
top);
void D__set_clip_planes(struct clip *clip, const struct rectangle *rect)
void path_cont(struct path *p, double x, double y)
void path_free(struct path *p)
void path_move(struct path *p, double x, double y)
void D__cull_path(struct path *dst, const struct path *src, const struct clip *clip)
void path_reset(struct path *p)
void D__clip_path(struct path *dst, const struct path *src, const struct clip *clip)
struct plane left rite bot top
void path_init(struct path *p)