2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
32 *partition a polygon into a Y-monotone polygon:
33 * A polygon is Y-monotone if the boundary can be split into two polygon chains
34 *A and B such that each chain is Y-monotonic that is the intersection of any
35 *horizontal line intersects each chain has at most one connected componenets
36 * (empty, single point or a single line).
38 * A vertex is a cusp if both its ajacent vertices are either at or above v,
39 *or both at or below v. In addition, at least one of the ajacent verteces is
40 *strictly below or above v.
41 * A vertex is a relex vertex if the internals angle is strictly greater than
42 *180. In other words, if the signed area is negative:
43 *(x1, y1), (x2, y2), (x3, y3) are the three vertices along a polygon, the
44 *order is such that left hand side is inside the polygon. Then (x2,y2) is
46 * (x2-x1, y2-y1) cross (x3-x1, y3-y1) <0.
47 *A vertex is an interior cusp if it is a cusp and a reflex.
48 *A vertex is an exterior cusp if it is a cusp but not a reflex.
55 #include "directedLine.h"
57 /*whether an edge is below a vertex*/
58 Int
isBelow(directedLine
*v
, directedLine
*e
);
60 /*whether an edge is above a vertex*/
61 Int
isAbove(directedLine
*v
, directedLine
*e
);
67 Int
cuspType(directedLine
*v
);
69 /*used in trapezoidalization*/
70 typedef struct sweepRange
{
72 Int leftType
; /*either a vertex (leftType=0) or an edge (leftType =1) */
74 Int rightType
; /*either a vertex (rightType=0) or an edge (rightType =1) */
77 sweepRange
* sweepRangeMake(directedLine
* left
, Int leftType
,
78 directedLine
* right
, Int rightType
);
80 void sweepRangeDelete(sweepRange
* range
);
81 Int
sweepRangeEqual(sweepRange
* sr1
, sweepRange
* sr2
);
83 /*given a set of simple polygons where the interior
84 *is decided by left-hand principle,
85 *return a range (sight) for each vertex. This is called
88 void sweepY(Int nVertices
, directedLine
**sortedVerteces
, sweepRange
** ret_ranges
);
91 directedLine
* partitionY(directedLine
*polygons
, sampledLine
**retSampledLines
);
93 void findDiagonals(Int total_num_edges
, directedLine
** sortedVertices
, sweepRange
** ranges
, Int
& num_diagonals
, directedLine
** diagonal_vertices
);
95 directedLine
** DBGfindDiagonals(directedLine
*polygons
, Int
& num_diagonals
);