| 1 |
/* |
| 2 |
* graphical interfaces |
| 3 |
*/ |
| 4 |
|
| 5 |
#include "config.h" |
| 6 |
|
| 7 |
#include "interface.h" |
| 8 |
|
| 9 |
// the simplest way I could imagine fast enough to find out wether a polygon |
| 10 |
// is clockwise or ccw could probably be *much* faster |
| 11 |
// |
| 12 |
double winding (const points &v) t_no |
| 13 |
{ |
| 14 |
double wind = 0; |
| 15 |
|
| 16 |
points::const_iterator a = v.begin (); |
| 17 |
points::const_iterator b = a; b++; |
| 18 |
points::const_iterator c = b; c++; |
| 19 |
|
| 20 |
for (;;) |
| 21 |
{ |
| 22 |
if (c == v.end ()) c = v.begin (); |
| 23 |
if (b == v.end ()) b = v.begin (); |
| 24 |
if (a == v.end ()) return wind; |
| 25 |
|
| 26 |
vec d = cross (b->v - a->v, c->v - b->v); |
| 27 |
|
| 28 |
if (abs (d) > 1e-6) // ignore almost coincident edges |
| 29 |
wind += normalize (d) * normalize (b->n); |
| 30 |
|
| 31 |
++c; |
| 32 |
++b; |
| 33 |
++a; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
|