-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclipper.html
236 lines (229 loc) · 9.09 KB
/
clipper.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title> clipper - polygon clipping </title>
<script src="jquery.js"></script>
<script src="jquery-cookie.js"></script>
<script src="jquery-tablesorter.js"></script>
<script src="strftime.js"></script>
<script src="mustache.js"></script>
<script src="config.js"></script>
<script src="main.js"></script>
<link rel="stylesheet" type="text/css" href="templates/reset.css" />
<link rel="stylesheet" type="text/css" href="templates/hack.css" />
<link rel="stylesheet" type="text/css" id="lights_css" />
<script>
var DOCNAME = 'clipper'
var PROJECT = 'clipper'
//set the lights before rendering starts
set_lights()
</script>
</head>
<body>
<header>
<div class="container">
<div class="btn-container btn-lights-container">
<a href="#" class="btn btn-lights" id="lights">lights</a>
</div>
<div class="btn-container btn-home-container">
<a href="/" class="btn btn-home">luapower</a>
</div>
<table id="header_table">
<tr>
<td style="vertical-align: middle;" width="100%">
<h1> clipper </h1>
<h2> polygon clipping </h2>
</td>
<td style="vertical-align: middle;" align="right" style="height: 150px">
<table><tr><td>
<div class="doc" id="package_info_container">
<div id="package_info"> </div>
<div id="commit_log"> </div>
</div>
<a href="https://github.com/luapower/clipper" class="btn btn-rightside btn-github"><span class="icon"></span>View on GitHub</a>
</td></tr><tr><td>
<a href="https://github.com/luapower/clipper/tarball/master" class="btn btn-rightside">Download as .tar.gz</a>
</td></tr><tr><td>
<a href="https://github.com/luapower/clipper/zipball/master" class="btn btn-rightside">Download as .zip</a>
</td></tr></table>
</td>
</tr>
</table>
<div class="btn-container btn-discuss-container">
<a href="https://github.com/luapower/clipper/issues/new" target="_blank"
class="btn btn-rightside btn-discuss"><span class="icon"></span>Discuss</a>
</div>
</div>
</header>
<div class="bg-container">
<div class="bg-center-container">
<div class="bg bg-clipper" style="background-image: url('bg/clipper.png');"></div>
</div>
</div>
<div class="under-header">
<div class="container">
<div id="toc_container" class="toc_container doc"></div>
<button id=tab1_button class="tab_button hidden">Documentation</button>
<button id=tab2_button class="tab_button hidden">Package Info</button>
<div id="tabs_cointainer">
<div id="tab1_container">
<section class="doc">
<span id="module_info"></span>
<h2 id="local-clipper-requireclipper"><code>local clipper = require'clipper'</code></h2>
<p>A Lua+C+ffi binding of <a href="http://www.angusj.com/delphi/clipper.php">Clipper</a>, Angus Johnson's free polygon clipping library.</p>
<div class="figure">
<img src="screenshots/clipper_demo.png" alt="screenshot" /><p class="caption">screenshot</p>
</div>
<h2 id="features">Features</h2>
<ul>
<li>polygon clipping: <code>intersection</code>, <code>union</code>, <code>difference</code>, <code>xor</code></li>
<li>polygon simplificaion with <code>even_odd</code>, <code>non_zero</code>, <code>positive</code> and <code>negative</code> fill types</li>
<li>polygon offsetting with <code>square</code>, <code>round</code> and <code>miter</code> join types</li>
</ul>
<table>
<tbody>
<tr class="odd">
<td align="left"><code>clipper.polygon([n]) -> poly</code></td>
<td align="left">create a polygon object of size <code>n</code> (default 0)</td>
</tr>
<tr class="even">
<td align="left"><code>poly:size() -> n</code></td>
<td align="left">number of vertices</td>
</tr>
<tr class="odd">
<td align="left"><code>poly:add(x, y)</code></td>
<td align="left">add a vertex to the polygon</td>
</tr>
<tr class="even">
<td align="left"><code>poly:get(i).x -> n</code> <br> <code>poly:get(i).y -> n</code></td>
<td align="left">get vertex coordinates</td>
</tr>
<tr class="odd">
<td align="left"><code>poly:get(i).x = n</code> <br> <code>poly:get(i).y = n</code></td>
<td align="left">set vertex coordinates</td>
</tr>
<tr class="even">
<td align="left"><code>poly:simplify(['even_odd'|'non_zero'|'positive'|'negative']) -> polys</code></td>
<td align="left"><a href="http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Routines/SimplifyPolygon.htm">simplify a polygon</a></td>
</tr>
<tr class="odd">
<td align="left"><code>poly:clean([distance]) -> polys</code></td>
<td align="left"><a href="http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Routines/CleanPolygon.htm">clean a polygon</a></td>
</tr>
<tr class="even">
<td align="left"><code>poly:reverse()</code></td>
<td align="left">reverse the order (and hence orientation) of vertices</td>
</tr>
<tr class="odd">
<td align="left"><code>poly:orientation() -> true | false</code></td>
<td align="left">polygon orientation (true = clockwise)</td>
</tr>
<tr class="even">
<td align="left"><code>poly:area() -> n</code></td>
<td align="left">polygon area</td>
</tr>
<tr class="odd">
<td align="left"><strong>Polygon lists</strong></td>
<td align="left"></td>
</tr>
<tr class="even">
<td align="left"><code>clipper.polygons([n | poly1, poly2, ...]) -> polys</code></td>
<td align="left">create a polygon list</td>
</tr>
<tr class="odd">
<td align="left"><code>polys:size() -> n</code></td>
<td align="left">list size</td>
</tr>
<tr class="even">
<td align="left"><code>polys:add(poly)</code></td>
<td align="left">add a polygon to the end of the list</td>
</tr>
<tr class="odd">
<td align="left"><code>polys:get(i) -> poly</code></td>
<td align="left">get a polygon from the list</td>
</tr>
<tr class="even">
<td align="left"><code>polys:set(i, poly)</code></td>
<td align="left">set a polygon in the list</td>
</tr>
<tr class="odd">
<td align="left"><code>polys:simplify(['even_odd'|'non_zero'|'positive'|'negative']) -> polys</code></td>
<td align="left"><a href="http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Routines/SimplifyPolygons.htm">simplify polygons</a> (default is <code>'even_odd'</code>)</td>
</tr>
<tr class="even">
<td align="left"><code>polys:clean([distance]) -> polys</code></td>
<td align="left"><a href="http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Routines/CleanPolygons.htm">clean polygons</a> (default distance is <code>~= sqrt(2)</code>)</td>
</tr>
<tr class="odd">
<td align="left"><code>polys:reverse()</code></td>
<td align="left">reverse the order (and hence orientation) of vertices</td>
</tr>
<tr class="even">
<td align="left"><code>polys:offset(delta, ['square'|'round'|'miter'], [limit]) -> polys</code></td>
<td align="left">offset polygons (default is 'square', 0)</td>
</tr>
<tr class="odd">
<td align="left"><strong>Clipping</strong></td>
<td align="left"></td>
</tr>
<tr class="even">
<td align="left"><code>clipper.new() -> cl</code></td>
<td align="left">create a clipper object</td>
</tr>
<tr class="odd">
<td align="left"><code>cl:add_subject(poly | polys)</code></td>
<td align="left">add polygons to be clipped</td>
</tr>
<tr class="even">
<td align="left"><code>cl:add_clip(poly | polys)</code></td>
<td align="left">add polygons to be clipped against</td>
</tr>
<tr class="odd">
<td align="left"><code>cl:get_bounds() -> x1, y1, x2, y2</code></td>
<td align="left">bounding box of all the polygons in the clipper</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr class="odd">
<td align="left"><code>cl:execute(operation, [subj_fill_type], [clip_fill_type], [reverse]) -> polys</code></td>
</tr>
</tbody>
</table>
<p>Clip subject polygons against clip polygons, optionally setting the fill type for each polygon list and optionally reversing the order of the vertices.</p>
<ul>
<li><code>operation = 'intersection'|'union'|'difference'|'xor'</code></li>
<li><code>*_fill_type = 'even_odd'|'non_zero'|'positive'|'negative'</code></li>
<li><code>reverse = true | false</code></li>
</ul>
<h2 id="notes">Notes</h2>
<ul>
<li>input and output vertices are <code>int64_t</code> cdata, not Lua numbers; use simple scaling on the input and output points to preserve sub-pixel accuracy.</li>
<li>all objects are garbage collected.</li>
<li>adding a polygon to a polygon list copies the polygon and all its elements to the list so there's no need to keep a reference to the polygon afterwards.</li>
<li><code>poly:get(1)</code> returns a pointer to the beginning of the vertex array so pointer arithmetic and memcpy are allowed on it.</li>
</ul>
</section>
</div>
<div id="tab2_container" class="doc"></div>
</div>
</div>
<div class="container">
<footer>
<div id="disqus_thread"></div>
<div class="faint">[email protected] | <a href="http://unlicense.org/">public domain</a></div>
</footer>
</div>
</div>
<script type="text/x-mustache" id=info_tab_template>
<h3>Modules</h3>
<ul>
{{#module_array}}
<li>{{name}}</li>
{{/module_array}}
</ul>
</script>
</body>
</html>