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