~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to tclpathplan/makecw.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Force the vertices of a polygon to be in CW order.
 
3
 * 
 
4
 * Works for polygons with concavities.
 
5
 * Does not work for twisted polygons.
 
6
 *
 
7
 * ellson@lucent.com    October 2nd, 1996
 
8
 */
 
9
 
 
10
#include <pathutil.h>
 
11
 
 
12
void
 
13
make_CW (Ppoly_t *poly)
 
14
{
 
15
    int                 i, j, n;
 
16
        Ppoint_t        *P;
 
17
    Ppoint_t    tP;
 
18
    double      area=0.0;
 
19
 
 
20
        P = poly->ps;
 
21
        n = poly->pn;
 
22
    /* points or lines don't have a rotation */
 
23
    if (n > 2) {
 
24
        /* check CW or CCW by computing (twice the) area of poly */
 
25
        for (i=1; i < n-1; i++) {
 
26
            area += area2(P[0], P[i+1], P[i]);
 
27
        }
 
28
        /* if the area is -ve then the rotation needs to be reversed */
 
29
        /* the starting point is left unchanged */
 
30
        if (area < 0.0) {
 
31
                        for (i = 1, j = n-1; i < 1+n/2; i++, j--) {
 
32
                                tP = P[i];
 
33
                                P[i] = P[j];
 
34
                                P[j] = tP;
 
35
                        }
 
36
        }
 
37
    }
 
38
}