Graphviz 12.1.0~dev.20240716.0947
Loading...
Searching...
No Matches
makecw.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11/*
12 * Force the vertices of a polygon to be in CW order.
13 *
14 * Works for polygons with concavities.
15 * Does not work for twisted polygons.
16 *
17 * ellson@graphviz.org October 2nd, 1996
18 */
19
20#include "makecw.h"
21#include <pathplan/pathutil.h>
22#include <stddef.h>
23
25{
26 Ppoint_t *P;
27 Ppoint_t tP;
28 double area = 0.0;
29
30 P = poly->ps;
31 const size_t n = poly->pn;
32 /* points or lines don't have a rotation */
33 if (n > 2) {
34 /* check CW or CCW by computing (twice the) area of poly */
35 for (size_t i = 1; i < n - 1; i++) {
36 area += area2(P[0], P[i + 1], P[i]);
37 }
38 /* if the area is -ve then the rotation needs to be reversed */
39 /* the starting point is left unchanged */
40 if (area < 0.0) {
41 for (size_t i = 1, j = n - 1; i < 1 + n / 2; i++, j--) {
42 tP = P[i];
43 P[i] = P[j];
44 P[j] = tP;
45 }
46 }
47 }
48}
void make_CW(Ppoly_t *poly)
Definition makecw.c:24
PATHUTIL_API COORD area2(Ppoint_t, Ppoint_t, Ppoint_t)
Definition visibility.c:44