Date: | 2012-03-20 23:30:03 (11 years 11 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 7a61482a045f50239106f4bd8dab91ad2202c26b |
Message: | cameo/area.c: move handling of left/right from hit_path to
hit_segment For future extensions. |
Files: |
cameo/area.c (3 diffs) |
Change Details
cameo/area.c | ||
---|---|---|
155 | 155 | |
156 | 156 | static int hit_segment(double fx, double fy, double tx, double ty, |
157 | 157 | const struct point *a, const struct point *b, double r, int enter, |
158 | double *n) | |
158 | int left, double *n) | |
159 | 159 | { |
160 | double dx, dy, d; | |
160 | double dx, dy, nx, ny, nn; | |
161 | 161 | double px, py; |
162 | 162 | double na, nb; |
163 | 163 | |
... | ... | |
167 | 167 | dx = b->x-a->x; |
168 | 168 | dy = b->y-a->y; |
169 | 169 | |
170 | if (left) { | |
171 | nx = dx; | |
172 | ny = dy; | |
173 | } else { | |
174 | nx = -dx; | |
175 | ny = -dy; | |
176 | } | |
177 | ||
170 | 178 | /* -dy becomes the x component of the normal vector */ |
171 | if (enter ? dy < 0 : dy > 0) | |
179 | if (enter ? ny < 0 : ny > 0) | |
172 | 180 | return 0; |
173 | 181 | |
174 | d = hypot(dx, dy); | |
182 | nn = hypot(nx, ny); | |
175 | 183 | |
176 | px = a->x-dy/d*r; | |
177 | py = a->y+dx/d*r; | |
184 | px = a->x-ny/nn*r; | |
185 | py = a->y+nx/nn*r; | |
178 | 186 | |
179 | 187 | if (!intersect(fx, fy, tx, ty, px, py, dx, dy, &na, &nb)) |
180 | 188 | return 0; |
... | ... | |
205 | 213 | if (inside) |
206 | 214 | left = !left; |
207 | 215 | for (p = path->first; p != path->last; p = p->next) { |
208 | if (hit_segment(fx, fy, tx, ty, | |
209 | left ? p : p->next, left ? p->next : p, r, enter, &tmp)) { | |
216 | if (hit_segment(fx, fy, tx, ty, p, p->next, | |
217 | r, enter, left, &tmp)) { | |
210 | 218 | if (!found || nx > tmp) |
211 | 219 | nx = tmp; |
212 | 220 | found = 1; |
Branches:
master