/usr/share/doc/libghc-opengl-doc/html/src/Graphics-Rendering-OpenGL-GLU-Tessellation.html is in libghc-opengl-doc 2.8.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
<title>Graphics/Rendering/OpenGL/GLU/Tessellation.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-2"></a><span class='hs-comment'>-- |</span>
<a name="line-3"></a><span class='hs-comment'>-- Module : Graphics.Rendering.OpenGL.GLU.Tessellation</span>
<a name="line-4"></a><span class='hs-comment'>-- Copyright : (c) Sven Panne 2002-2009</span>
<a name="line-5"></a><span class='hs-comment'>-- License : BSD-style (see the file libraries/OpenGL/LICENSE)</span>
<a name="line-6"></a><span class='hs-comment'>-- </span>
<a name="line-7"></a><span class='hs-comment'>-- Maintainer : sven.panne@aedion.de</span>
<a name="line-8"></a><span class='hs-comment'>-- Stability : stable</span>
<a name="line-9"></a><span class='hs-comment'>-- Portability : portable</span>
<a name="line-10"></a><span class='hs-comment'>--</span>
<a name="line-11"></a><span class='hs-comment'>-- This module corresponds to chapter 5 (Polygon Tessellation) of the GLU specs.</span>
<a name="line-12"></a><span class='hs-comment'>--</span>
<a name="line-13"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-14"></a>
<a name="line-15"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Rendering</span><span class='hs-varop'>.</span><span class='hs-conid'>OpenGL</span><span class='hs-varop'>.</span><span class='hs-conid'>GLU</span><span class='hs-varop'>.</span><span class='hs-conid'>Tessellation</span> <span class='hs-layout'>(</span>
<a name="line-16"></a> <span class='hs-comment'>-- * Polygon description</span>
<a name="line-17"></a> <span class='hs-conid'>AnnotatedVertex</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-conid'>ComplexContour</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-conid'>ComplexPolygon</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span>
<a name="line-18"></a>
<a name="line-19"></a> <span class='hs-comment'>-- * Combining vertices</span>
<a name="line-20"></a> <span class='hs-conid'>WeightedProperties</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-conid'>Combiner</span><span class='hs-layout'>,</span>
<a name="line-21"></a>
<a name="line-22"></a> <span class='hs-comment'>-- * Tessellation parameters</span>
<a name="line-23"></a> <span class='hs-conid'>TessWinding</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-conid'>Tolerance</span><span class='hs-layout'>,</span>
<a name="line-24"></a>
<a name="line-25"></a> <span class='hs-comment'>-- * Tessellator type</span>
<a name="line-26"></a> <span class='hs-conid'>Tessellator</span><span class='hs-layout'>,</span>
<a name="line-27"></a>
<a name="line-28"></a> <span class='hs-comment'>-- * Contour extraction</span>
<a name="line-29"></a> <span class='hs-conid'>SimpleContour</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-conid'>PolygonContours</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-varid'>extractContours</span><span class='hs-layout'>,</span>
<a name="line-30"></a>
<a name="line-31"></a> <span class='hs-comment'>-- * Triangulation</span>
<a name="line-32"></a> <span class='hs-conid'>TriangleVertex</span><span class='hs-layout'>,</span> <span class='hs-conid'>Triangle</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-conid'>Triangulation</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-varid'>triangulate</span><span class='hs-layout'>,</span>
<a name="line-33"></a>
<a name="line-34"></a> <span class='hs-comment'>-- * Tessellation into primitives</span>
<a name="line-35"></a> <span class='hs-conid'>Primitive</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-conid'>SimplePolygon</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-varid'>tessellate</span>
<a name="line-36"></a><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-37"></a>
<a name="line-38"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Monad</span> <span class='hs-layout'>(</span> <span class='hs-varid'>foldM_</span><span class='hs-layout'>,</span> <span class='hs-varid'>unless</span> <span class='hs-layout'>)</span>
<a name="line-39"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>IORef</span> <span class='hs-layout'>(</span> <span class='hs-varid'>newIORef</span><span class='hs-layout'>,</span> <span class='hs-varid'>readIORef</span><span class='hs-layout'>,</span> <span class='hs-varid'>writeIORef</span><span class='hs-layout'>,</span> <span class='hs-varid'>modifyIORef</span> <span class='hs-layout'>)</span>
<a name="line-40"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Maybe</span> <span class='hs-layout'>(</span> <span class='hs-varid'>fromJust</span><span class='hs-layout'>,</span> <span class='hs-varid'>fromMaybe</span> <span class='hs-layout'>)</span>
<a name="line-41"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>Marshal</span><span class='hs-varop'>.</span><span class='hs-conid'>Alloc</span> <span class='hs-layout'>(</span> <span class='hs-varid'>allocaBytes</span> <span class='hs-layout'>)</span>
<a name="line-42"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>Marshal</span><span class='hs-varop'>.</span><span class='hs-conid'>Array</span> <span class='hs-layout'>(</span> <span class='hs-varid'>peekArray</span><span class='hs-layout'>,</span> <span class='hs-varid'>pokeArray</span> <span class='hs-layout'>)</span>
<a name="line-43"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>Marshal</span><span class='hs-varop'>.</span><span class='hs-conid'>Pool</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Pool</span><span class='hs-layout'>,</span> <span class='hs-varid'>withPool</span><span class='hs-layout'>,</span> <span class='hs-varid'>pooledNew</span> <span class='hs-layout'>)</span>
<a name="line-44"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Ptr</span><span class='hs-layout'>,</span> <span class='hs-varid'>nullPtr</span><span class='hs-layout'>,</span> <span class='hs-varid'>plusPtr</span><span class='hs-layout'>,</span> <span class='hs-varid'>castPtr</span><span class='hs-layout'>,</span> <span class='hs-varid'>freeHaskellFunPtr</span> <span class='hs-layout'>)</span>
<a name="line-45"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>Storable</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Storable</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span> <span class='hs-layout'>)</span>
<a name="line-46"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Rendering</span><span class='hs-varop'>.</span><span class='hs-conid'>GLU</span><span class='hs-varop'>.</span><span class='hs-conid'>Raw</span>
<a name="line-47"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Rendering</span><span class='hs-varop'>.</span><span class='hs-conid'>OpenGL</span><span class='hs-varop'>.</span><span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>Core31</span>
<a name="line-48"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Rendering</span><span class='hs-varop'>.</span><span class='hs-conid'>OpenGL</span><span class='hs-varop'>.</span><span class='hs-conid'>GL</span><span class='hs-varop'>.</span><span class='hs-conid'>Tensor</span>
<a name="line-49"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Rendering</span><span class='hs-varop'>.</span><span class='hs-conid'>OpenGL</span><span class='hs-varop'>.</span><span class='hs-conid'>GL</span><span class='hs-varop'>.</span><span class='hs-conid'>EdgeFlag</span> <span class='hs-layout'>(</span> <span class='hs-varid'>unmarshalEdgeFlag</span> <span class='hs-layout'>)</span>
<a name="line-50"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Rendering</span><span class='hs-varop'>.</span><span class='hs-conid'>OpenGL</span><span class='hs-varop'>.</span><span class='hs-conid'>GL</span><span class='hs-varop'>.</span><span class='hs-conid'>Exception</span> <span class='hs-layout'>(</span> <span class='hs-varid'>bracket</span> <span class='hs-layout'>)</span>
<a name="line-51"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Rendering</span><span class='hs-varop'>.</span><span class='hs-conid'>OpenGL</span><span class='hs-varop'>.</span><span class='hs-conid'>GL</span><span class='hs-varop'>.</span><span class='hs-conid'>GLboolean</span> <span class='hs-layout'>(</span> <span class='hs-varid'>marshalGLboolean</span> <span class='hs-layout'>)</span>
<a name="line-52"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Rendering</span><span class='hs-varop'>.</span><span class='hs-conid'>OpenGL</span><span class='hs-varop'>.</span><span class='hs-conid'>GL</span><span class='hs-varop'>.</span><span class='hs-conid'>PrimitiveMode</span> <span class='hs-layout'>(</span> <span class='hs-varid'>unmarshalPrimitiveMode</span> <span class='hs-layout'>)</span>
<a name="line-53"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Rendering</span><span class='hs-varop'>.</span><span class='hs-conid'>OpenGL</span><span class='hs-varop'>.</span><span class='hs-conid'>GL</span><span class='hs-varop'>.</span><span class='hs-conid'>BeginEnd</span> <span class='hs-layout'>(</span>
<a name="line-54"></a> <span class='hs-conid'>PrimitiveMode</span><span class='hs-layout'>,</span> <span class='hs-conid'>EdgeFlag</span><span class='hs-layout'>(</span><span class='hs-conid'>BeginsInteriorEdge</span><span class='hs-layout'>)</span> <span class='hs-layout'>)</span>
<a name="line-55"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Rendering</span><span class='hs-varop'>.</span><span class='hs-conid'>OpenGL</span><span class='hs-varop'>.</span><span class='hs-conid'>GL</span><span class='hs-varop'>.</span><span class='hs-conid'>VertexSpec</span>
<a name="line-56"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Rendering</span><span class='hs-varop'>.</span><span class='hs-conid'>OpenGL</span><span class='hs-varop'>.</span><span class='hs-conid'>GL</span><span class='hs-varop'>.</span><span class='hs-conid'>QueryUtils</span>
<a name="line-57"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Rendering</span><span class='hs-varop'>.</span><span class='hs-conid'>OpenGL</span><span class='hs-varop'>.</span><span class='hs-conid'>GLU</span><span class='hs-varop'>.</span><span class='hs-conid'>ErrorsInternal</span>
<a name="line-58"></a>
<a name="line-59"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-60"></a>
<a name="line-61"></a><a name="TessWinding"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>TessWinding</span> <span class='hs-keyglyph'>=</span>
<a name="line-62"></a> <span class='hs-conid'>TessWindingOdd</span>
<a name="line-63"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>TessWindingNonzero</span>
<a name="line-64"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>TessWindingPositive</span>
<a name="line-65"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>TessWindingNegative</span>
<a name="line-66"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>TessWindingAbsGeqTwo</span>
<a name="line-67"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Eq</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span><span class='hs-layout'>,</span> <span class='hs-conid'>Show</span> <span class='hs-layout'>)</span>
<a name="line-68"></a>
<a name="line-69"></a><a name="marshalTessWinding"></a><span class='hs-definition'>marshalTessWinding</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessWinding</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>GLenum</span>
<a name="line-70"></a><span class='hs-definition'>marshalTessWinding</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>case</span> <span class='hs-varid'>x</span> <span class='hs-keyword'>of</span>
<a name="line-71"></a> <span class='hs-conid'>TessWindingOdd</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>glu_TESS_WINDING_ODD</span>
<a name="line-72"></a> <span class='hs-conid'>TessWindingNonzero</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>glu_TESS_WINDING_NONZERO</span>
<a name="line-73"></a> <span class='hs-conid'>TessWindingPositive</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>glu_TESS_WINDING_POSITIVE</span>
<a name="line-74"></a> <span class='hs-conid'>TessWindingNegative</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>glu_TESS_WINDING_NEGATIVE</span>
<a name="line-75"></a> <span class='hs-conid'>TessWindingAbsGeqTwo</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>glu_TESS_WINDING_ABS_GEQ_TWO</span>
<a name="line-76"></a>
<a name="line-77"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-78"></a>
<a name="line-79"></a><span class='hs-comment'>-- | The basic building block in tessellation is a 3D vertex with an associated</span>
<a name="line-80"></a><span class='hs-comment'>-- property, e.g. color, texture coordinates, etc.</span>
<a name="line-81"></a>
<a name="line-82"></a><a name="AnnotatedVertex"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>AnnotatedVertex</span> <span class='hs-layout'>(</span><span class='hs-conid'>Vertex3</span> <span class='hs-conid'>GLdouble</span><span class='hs-layout'>)</span> <span class='hs-varid'>v</span>
<a name="line-83"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Eq</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-layout'>)</span>
<a name="line-84"></a>
<a name="line-85"></a><a name="offsetOfProperty"></a><span class='hs-definition'>offsetOfProperty</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span>
<a name="line-86"></a><span class='hs-definition'>offsetOfProperty</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>alignOffset</span> <span class='hs-varid'>v</span> <span class='hs-layout'>(</span><span class='hs-num'>3</span> <span class='hs-varop'>*</span> <span class='hs-varid'>sizeOf</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span>
<a name="line-87"></a> <span class='hs-keyword'>where</span> <span class='hs-conid'>AnnotatedVertex</span> <span class='hs-layout'>(</span><span class='hs-conid'>Vertex3</span> <span class='hs-varid'>x</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>undefined</span>
<a name="line-88"></a>
<a name="line-89"></a><a name="alignOffset"></a><span class='hs-definition'>alignOffset</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Storable</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span>
<a name="line-90"></a><span class='hs-definition'>alignOffset</span> <span class='hs-varid'>x</span> <span class='hs-varid'>offset</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>n</span> <span class='hs-comment'>-</span> <span class='hs-layout'>(</span><span class='hs-varid'>n</span> <span class='hs-varop'>`mod`</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span>
<a name="line-91"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>alignment</span> <span class='hs-varid'>x</span>
<a name="line-92"></a> <span class='hs-varid'>n</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>a</span> <span class='hs-varop'>+</span> <span class='hs-varid'>offset</span> <span class='hs-comment'>-</span> <span class='hs-num'>1</span>
<a name="line-93"></a>
<a name="line-94"></a><a name="instance%20Storable%20(AnnotatedVertex%20v)"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Storable</span> <span class='hs-layout'>(</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-95"></a>
<a name="line-96"></a> <span class='hs-varid'>sizeOf</span> <span class='hs-keyglyph'>~</span><span class='hs-layout'>(</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-layout'>(</span><span class='hs-conid'>Vertex3</span> <span class='hs-varid'>x</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-97"></a> <span class='hs-varid'>alignOffset</span> <span class='hs-varid'>x</span> <span class='hs-layout'>(</span><span class='hs-varid'>sizeOf</span> <span class='hs-varid'>v</span> <span class='hs-varop'>+</span> <span class='hs-varid'>offsetOfProperty</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-98"></a>
<a name="line-99"></a> <span class='hs-varid'>alignment</span> <span class='hs-keyglyph'>~</span><span class='hs-layout'>(</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-layout'>(</span><span class='hs-conid'>Vertex3</span> <span class='hs-varid'>x</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-100"></a> <span class='hs-varid'>alignment</span> <span class='hs-varid'>x</span>
<a name="line-101"></a>
<a name="line-102"></a> <span class='hs-varid'>peek</span> <span class='hs-varid'>ptr</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-103"></a> <span class='hs-varid'>x</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>peekElemOff</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span> <span class='hs-num'>0</span>
<a name="line-104"></a> <span class='hs-varid'>y</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>peekElemOff</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span> <span class='hs-num'>1</span>
<a name="line-105"></a> <span class='hs-varid'>z</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>peekElemOff</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span> <span class='hs-num'>2</span>
<a name="line-106"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>dummyElement</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>v</span>
<a name="line-107"></a> <span class='hs-varid'>dummyElement</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>undefined</span>
<a name="line-108"></a> <span class='hs-varid'>v</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>peekByteOff</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>offsetOfProperty</span> <span class='hs-layout'>(</span><span class='hs-varid'>dummyElement</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-109"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-conid'>AnnotatedVertex</span> <span class='hs-layout'>(</span><span class='hs-conid'>Vertex3</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-varid'>z</span><span class='hs-layout'>)</span> <span class='hs-varid'>v</span>
<a name="line-110"></a>
<a name="line-111"></a> <span class='hs-varid'>poke</span> <span class='hs-varid'>ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-layout'>(</span><span class='hs-conid'>Vertex3</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-varid'>z</span><span class='hs-layout'>)</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-112"></a> <span class='hs-varid'>pokeElemOff</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span> <span class='hs-num'>0</span> <span class='hs-varid'>x</span>
<a name="line-113"></a> <span class='hs-varid'>pokeElemOff</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span> <span class='hs-num'>1</span> <span class='hs-varid'>y</span>
<a name="line-114"></a> <span class='hs-varid'>pokeElemOff</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span> <span class='hs-num'>2</span> <span class='hs-varid'>z</span>
<a name="line-115"></a> <span class='hs-varid'>pokeByteOff</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>offsetOfProperty</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-varid'>v</span>
<a name="line-116"></a>
<a name="line-117"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-118"></a>
<a name="line-119"></a><span class='hs-comment'>-- | A complex contour, which can be self-intersecting and\/or concave.</span>
<a name="line-120"></a>
<a name="line-121"></a><a name="ComplexContour"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>ComplexContour</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>ComplexContour</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>v</span><span class='hs-keyglyph'>]</span>
<a name="line-122"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Eq</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-layout'>)</span>
<a name="line-123"></a>
<a name="line-124"></a><a name="sizeOfComplexContour"></a><span class='hs-definition'>sizeOfComplexContour</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>ComplexContour</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span>
<a name="line-125"></a><span class='hs-definition'>sizeOfComplexContour</span> <span class='hs-layout'>(</span><span class='hs-conid'>ComplexContour</span> <span class='hs-varid'>vs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-126"></a> <span class='hs-varid'>length</span> <span class='hs-varid'>vs</span> <span class='hs-varop'>*</span> <span class='hs-varid'>sizeOf</span> <span class='hs-layout'>(</span><span class='hs-varid'>head</span> <span class='hs-varid'>vs</span><span class='hs-layout'>)</span>
<a name="line-127"></a>
<a name="line-128"></a><a name="pokeComplexContour"></a><span class='hs-definition'>pokeComplexContour</span> <span class='hs-keyglyph'>::</span>
<a name="line-129"></a> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>ComplexContour</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ComplexContour</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-130"></a><span class='hs-definition'>pokeComplexContour</span> <span class='hs-varid'>ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>ComplexContour</span> <span class='hs-varid'>vs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-131"></a> <span class='hs-varid'>pokeArray</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span> <span class='hs-varid'>vs</span>
<a name="line-132"></a>
<a name="line-133"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-134"></a>
<a name="line-135"></a><span class='hs-comment'>-- | A complex (possibly concave) polygon, represented by one or more complex</span>
<a name="line-136"></a><span class='hs-comment'>-- and possibly intersecting contours.</span>
<a name="line-137"></a>
<a name="line-138"></a><a name="ComplexPolygon"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>ComplexPolygon</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>ComplexPolygon</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>ComplexContour</span> <span class='hs-varid'>v</span><span class='hs-keyglyph'>]</span>
<a name="line-139"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Eq</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-layout'>)</span>
<a name="line-140"></a>
<a name="line-141"></a><a name="sizeOfComplexPolygon"></a><span class='hs-definition'>sizeOfComplexPolygon</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>ComplexPolygon</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span>
<a name="line-142"></a><span class='hs-definition'>sizeOfComplexPolygon</span> <span class='hs-layout'>(</span><span class='hs-conid'>ComplexPolygon</span> <span class='hs-varid'>complexContours</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-143"></a> <span class='hs-varid'>sum</span> <span class='hs-layout'>(</span><span class='hs-varid'>map</span> <span class='hs-varid'>sizeOfComplexContour</span> <span class='hs-varid'>complexContours</span><span class='hs-layout'>)</span>
<a name="line-144"></a>
<a name="line-145"></a><a name="pokeComplexPolygon"></a><span class='hs-definition'>pokeComplexPolygon</span> <span class='hs-keyglyph'>::</span>
<a name="line-146"></a> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>ComplexPolygon</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ComplexPolygon</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-147"></a><span class='hs-definition'>pokeComplexPolygon</span> <span class='hs-varid'>ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>ComplexPolygon</span> <span class='hs-varid'>complexContours</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-148"></a> <span class='hs-varid'>foldM_</span> <span class='hs-varid'>pokeAndAdvance</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span> <span class='hs-varid'>complexContours</span> <span class='hs-varop'>>></span> <span class='hs-varid'>return</span> <span class='hs-conid'>()</span>
<a name="line-149"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>pokeAndAdvance</span> <span class='hs-varid'>p</span> <span class='hs-varid'>complexContour</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-150"></a> <span class='hs-varid'>pokeComplexContour</span> <span class='hs-varid'>p</span> <span class='hs-varid'>complexContour</span>
<a name="line-151"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-varid'>p</span> <span class='hs-varop'>`plusPtr`</span> <span class='hs-varid'>sizeOfComplexContour</span> <span class='hs-varid'>complexContour</span>
<a name="line-152"></a>
<a name="line-153"></a><a name="withComplexPolygon"></a><span class='hs-definition'>withComplexPolygon</span> <span class='hs-keyglyph'>::</span>
<a name="line-154"></a> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>ComplexPolygon</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>ComplexPolygon</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
<a name="line-155"></a><span class='hs-definition'>withComplexPolygon</span> <span class='hs-varid'>complexPolygon</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span>
<a name="line-156"></a> <span class='hs-varid'>allocaBytes</span> <span class='hs-layout'>(</span><span class='hs-varid'>sizeOfComplexPolygon</span> <span class='hs-varid'>complexPolygon</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>ptr</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-157"></a> <span class='hs-varid'>pokeComplexPolygon</span> <span class='hs-varid'>ptr</span> <span class='hs-varid'>complexPolygon</span>
<a name="line-158"></a> <span class='hs-varid'>f</span> <span class='hs-varid'>ptr</span>
<a name="line-159"></a>
<a name="line-160"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-161"></a>
<a name="line-162"></a><span class='hs-comment'>-- | Four vertex properties (cf. 'AnnotatedVertex') with associated weigths</span>
<a name="line-163"></a><span class='hs-comment'>-- summing up to 1.0.</span>
<a name="line-164"></a>
<a name="line-165"></a><a name="WeightedProperties"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>WeightedProperties</span> <span class='hs-varid'>v</span>
<a name="line-166"></a> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>WeightedProperties</span> <span class='hs-layout'>(</span><span class='hs-conid'>GLfloat</span><span class='hs-layout'>,</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-167"></a> <span class='hs-layout'>(</span><span class='hs-conid'>GLfloat</span><span class='hs-layout'>,</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-168"></a> <span class='hs-layout'>(</span><span class='hs-conid'>GLfloat</span><span class='hs-layout'>,</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-169"></a> <span class='hs-layout'>(</span><span class='hs-conid'>GLfloat</span><span class='hs-layout'>,</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-170"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Eq</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-layout'>)</span>
<a name="line-171"></a>
<a name="line-172"></a><span class='hs-comment'>-- | A function combining given vertex properties into a property for a newly</span>
<a name="line-173"></a><span class='hs-comment'>-- generated vertex</span>
<a name="line-174"></a>
<a name="line-175"></a><a name="Combiner"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>Combiner</span> <span class='hs-varid'>v</span>
<a name="line-176"></a> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Vertex3</span> <span class='hs-conid'>GLdouble</span>
<a name="line-177"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>WeightedProperties</span> <span class='hs-varid'>v</span>
<a name="line-178"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>v</span>
<a name="line-179"></a>
<a name="line-180"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-181"></a>
<a name="line-182"></a><span class='hs-comment'>-- | The relative tolerance under which two vertices can be combined (see</span>
<a name="line-183"></a><span class='hs-comment'>-- 'Combiner'). Multiplication with the largest coordinate magnitude of all</span>
<a name="line-184"></a><span class='hs-comment'>-- polygon vertices yields the maximum distance between two mergeable vertices.</span>
<a name="line-185"></a><span class='hs-comment'>--</span>
<a name="line-186"></a><span class='hs-comment'>-- Note that merging is optional and the tolerance is only a hint.</span>
<a name="line-187"></a>
<a name="line-188"></a><a name="Tolerance"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>Tolerance</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>GLdouble</span>
<a name="line-189"></a>
<a name="line-190"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-191"></a>
<a name="line-192"></a><span class='hs-comment'>-- | A general tessellator type.</span>
<a name="line-193"></a><span class='hs-comment'>--</span>
<a name="line-194"></a><span class='hs-comment'>-- Before tessellation of a complex polygon, all its vertices are projected into</span>
<a name="line-195"></a><span class='hs-comment'>-- a plane perpendicular to the given normal. If the given normal is</span>
<a name="line-196"></a><span class='hs-comment'>-- @Normal3 0 0 0@, a fitting plane of all vertices is used.</span>
<a name="line-197"></a>
<a name="line-198"></a><a name="Tessellator"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>Tessellator</span> <span class='hs-varid'>p</span> <span class='hs-varid'>v</span>
<a name="line-199"></a> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>TessWinding</span>
<a name="line-200"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Tolerance</span>
<a name="line-201"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Normal3</span> <span class='hs-conid'>GLdouble</span>
<a name="line-202"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Combiner</span> <span class='hs-varid'>v</span>
<a name="line-203"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ComplexPolygon</span> <span class='hs-varid'>v</span>
<a name="line-204"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-layout'>(</span><span class='hs-varid'>p</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-205"></a>
<a name="line-206"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-207"></a>
<a name="line-208"></a><span class='hs-comment'>-- | A simple, non-self-intersecting contour</span>
<a name="line-209"></a>
<a name="line-210"></a><a name="SimpleContour"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>SimpleContour</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>SimpleContour</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>v</span><span class='hs-keyglyph'>]</span>
<a name="line-211"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Eq</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-layout'>)</span>
<a name="line-212"></a>
<a name="line-213"></a><span class='hs-comment'>-- | The contours of a complex polygon, represented by one or more</span>
<a name="line-214"></a><span class='hs-comment'>-- non-intersecting simple contours</span>
<a name="line-215"></a>
<a name="line-216"></a><a name="PolygonContours"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>PolygonContours</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>PolygonContours</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>SimpleContour</span> <span class='hs-varid'>v</span><span class='hs-keyglyph'>]</span>
<a name="line-217"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Eq</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-layout'>)</span>
<a name="line-218"></a>
<a name="line-219"></a><a name="extractContours"></a><span class='hs-definition'>extractContours</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Tessellator</span> <span class='hs-conid'>PolygonContours</span> <span class='hs-varid'>v</span>
<a name="line-220"></a><span class='hs-definition'>extractContours</span> <span class='hs-varid'>windingRule</span> <span class='hs-varid'>tolerance</span> <span class='hs-varid'>theNormal</span> <span class='hs-varid'>combiner</span> <span class='hs-varid'>complexPoly</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-221"></a>
<a name="line-222"></a> <span class='hs-varid'>vertices</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newIORef</span> <span class='hs-conid'>[]</span>
<a name="line-223"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>addVertex</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>modifyIORef</span> <span class='hs-varid'>vertices</span> <span class='hs-layout'>(</span><span class='hs-varid'>v</span><span class='hs-conop'>:</span><span class='hs-layout'>)</span>
<a name="line-224"></a>
<a name="line-225"></a> <span class='hs-varid'>contours</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newIORef</span> <span class='hs-conid'>[]</span>
<a name="line-226"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>finishContour</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-227"></a> <span class='hs-varid'>vs</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>readIORef</span> <span class='hs-varid'>vertices</span>
<a name="line-228"></a> <span class='hs-varid'>writeIORef</span> <span class='hs-varid'>vertices</span> <span class='hs-conid'>[]</span>
<a name="line-229"></a> <span class='hs-varid'>modifyIORef</span> <span class='hs-varid'>contours</span> <span class='hs-layout'>(</span><span class='hs-conid'>SimpleContour</span> <span class='hs-layout'>(</span><span class='hs-varid'>reverse</span> <span class='hs-varid'>vs</span><span class='hs-layout'>)</span> <span class='hs-conop'>:</span><span class='hs-layout'>)</span>
<a name="line-230"></a>
<a name="line-231"></a> <span class='hs-varid'>getContours</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span><span class='hs-conid'>PolygonContours</span> <span class='hs-varop'>.</span> <span class='hs-varid'>reverse</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>readIORef</span> <span class='hs-varid'>contours</span><span class='hs-layout'>)</span>
<a name="line-232"></a>
<a name="line-233"></a> <span class='hs-varid'>withTessellatorObj</span> <span class='hs-layout'>(</span><span class='hs-conid'>PolygonContours</span> <span class='hs-conid'>[]</span><span class='hs-layout'>)</span><span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>tessObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-234"></a> <span class='hs-varid'>setTessellatorProperties</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>windingRule</span> <span class='hs-varid'>tolerance</span> <span class='hs-varid'>theNormal</span> <span class='hs-conid'>True</span>
<a name="line-235"></a> <span class='hs-varid'>withVertexCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>addVertex</span> <span class='hs-varop'>$</span>
<a name="line-236"></a> <span class='hs-varid'>withEndCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>finishContour</span> <span class='hs-varop'>$</span>
<a name="line-237"></a> <span class='hs-varid'>checkForError</span> <span class='hs-varid'>tessObj</span> <span class='hs-varop'>$</span>
<a name="line-238"></a> <span class='hs-varid'>withCombineCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>combiner</span> <span class='hs-varop'>$</span> <span class='hs-keyword'>do</span>
<a name="line-239"></a> <span class='hs-varid'>defineComplexPolygon</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>complexPoly</span>
<a name="line-240"></a> <span class='hs-varid'>getContours</span>
<a name="line-241"></a>
<a name="line-242"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-243"></a>
<a name="line-244"></a><span class='hs-comment'>-- | A triangle vertex with additional information about the edge it begins</span>
<a name="line-245"></a>
<a name="line-246"></a><a name="TriangleVertex"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>TriangleVertex</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>AnnotatedVertex</span> <span class='hs-layout'>(</span><span class='hs-varid'>v</span><span class='hs-layout'>,</span><span class='hs-conid'>EdgeFlag</span><span class='hs-layout'>)</span>
<a name="line-247"></a>
<a name="line-248"></a><span class='hs-comment'>-- | A triangle, represented by three triangle vertices</span>
<a name="line-249"></a>
<a name="line-250"></a><a name="Triangle"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>Triangle</span> <span class='hs-varid'>v</span>
<a name="line-251"></a> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Triangle</span> <span class='hs-layout'>(</span><span class='hs-conid'>TriangleVertex</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-conid'>TriangleVertex</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-conid'>TriangleVertex</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-252"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Eq</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-layout'>)</span>
<a name="line-253"></a>
<a name="line-254"></a><span class='hs-comment'>-- | A triangulation of a complex polygon</span>
<a name="line-255"></a>
<a name="line-256"></a><a name="Triangulation"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>Triangulation</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Triangulation</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Triangle</span> <span class='hs-varid'>v</span><span class='hs-keyglyph'>]</span>
<a name="line-257"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Eq</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-layout'>)</span>
<a name="line-258"></a>
<a name="line-259"></a><a name="triangulate"></a><span class='hs-definition'>triangulate</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Tessellator</span> <span class='hs-conid'>Triangulation</span> <span class='hs-varid'>v</span>
<a name="line-260"></a><span class='hs-definition'>triangulate</span> <span class='hs-varid'>windingRule</span> <span class='hs-varid'>tolerance</span> <span class='hs-varid'>theNormal</span> <span class='hs-varid'>combiner</span> <span class='hs-varid'>complexPoly</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-261"></a>
<a name="line-262"></a> <span class='hs-varid'>edgeFlagState</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newIORef</span> <span class='hs-conid'>BeginsInteriorEdge</span>
<a name="line-263"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>registerEdgeFlag</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>writeIORef</span> <span class='hs-varid'>edgeFlagState</span>
<a name="line-264"></a>
<a name="line-265"></a> <span class='hs-varid'>vertices</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newIORef</span> <span class='hs-conid'>[]</span>
<a name="line-266"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>addVertex</span> <span class='hs-layout'>(</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>xyz</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-267"></a> <span class='hs-varid'>ef</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>readIORef</span> <span class='hs-varid'>edgeFlagState</span>
<a name="line-268"></a> <span class='hs-varid'>modifyIORef</span> <span class='hs-varid'>vertices</span> <span class='hs-layout'>(</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>xyz</span> <span class='hs-layout'>(</span><span class='hs-varid'>v</span><span class='hs-layout'>,</span><span class='hs-varid'>ef</span><span class='hs-layout'>)</span> <span class='hs-conop'>:</span><span class='hs-layout'>)</span>
<a name="line-269"></a>
<a name="line-270"></a> <span class='hs-varid'>getTriangulation</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-271"></a> <span class='hs-varid'>vs</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>readIORef</span> <span class='hs-varid'>vertices</span>
<a name="line-272"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Triangulation</span> <span class='hs-layout'>(</span><span class='hs-varid'>collectTriangles</span> <span class='hs-layout'>(</span><span class='hs-varid'>reverse</span> <span class='hs-varid'>vs</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-273"></a>
<a name="line-274"></a> <span class='hs-varid'>withTessellatorObj</span> <span class='hs-layout'>(</span><span class='hs-conid'>Triangulation</span> <span class='hs-conid'>[]</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>tessObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-275"></a> <span class='hs-varid'>setTessellatorProperties</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>windingRule</span> <span class='hs-varid'>tolerance</span> <span class='hs-varid'>theNormal</span> <span class='hs-conid'>False</span>
<a name="line-276"></a> <span class='hs-varid'>withEdgeFlagCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>registerEdgeFlag</span> <span class='hs-varop'>$</span>
<a name="line-277"></a> <span class='hs-varid'>withVertexCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>addVertex</span> <span class='hs-varop'>$</span>
<a name="line-278"></a> <span class='hs-varid'>checkForError</span> <span class='hs-varid'>tessObj</span> <span class='hs-varop'>$</span>
<a name="line-279"></a> <span class='hs-varid'>withCombineCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>combiner</span> <span class='hs-varop'>$</span> <span class='hs-keyword'>do</span>
<a name="line-280"></a> <span class='hs-varid'>defineComplexPolygon</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>complexPoly</span>
<a name="line-281"></a> <span class='hs-varid'>getTriangulation</span>
<a name="line-282"></a>
<a name="line-283"></a><a name="collectTriangles"></a><span class='hs-definition'>collectTriangles</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>TriangleVertex</span> <span class='hs-varid'>v</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Triangle</span> <span class='hs-varid'>v</span><span class='hs-keyglyph'>]</span>
<a name="line-284"></a><span class='hs-definition'>collectTriangles</span> <span class='hs-conid'>[]</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>[]</span>
<a name="line-285"></a><span class='hs-definition'>collectTriangles</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-conop'>:</span><span class='hs-varid'>b</span><span class='hs-conop'>:</span><span class='hs-varid'>c</span><span class='hs-conop'>:</span><span class='hs-varid'>rest</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Triangle</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-varid'>c</span> <span class='hs-conop'>:</span> <span class='hs-varid'>collectTriangles</span> <span class='hs-varid'>rest</span>
<a name="line-286"></a><span class='hs-definition'>collectTriangles</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>error</span> <span class='hs-str'>"triangles left"</span>
<a name="line-287"></a>
<a name="line-288"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-289"></a>
<a name="line-290"></a><a name="Primitive"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>Primitive</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Primitive</span> <span class='hs-conid'>PrimitiveMode</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>v</span><span class='hs-keyglyph'>]</span>
<a name="line-291"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Eq</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-layout'>)</span>
<a name="line-292"></a>
<a name="line-293"></a><a name="SimplePolygon"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>SimplePolygon</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>SimplePolygon</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Primitive</span> <span class='hs-varid'>v</span><span class='hs-keyglyph'>]</span>
<a name="line-294"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Eq</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-layout'>)</span>
<a name="line-295"></a>
<a name="line-296"></a><a name="tessellate"></a><span class='hs-definition'>tessellate</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Tessellator</span> <span class='hs-conid'>SimplePolygon</span> <span class='hs-varid'>v</span>
<a name="line-297"></a><span class='hs-definition'>tessellate</span> <span class='hs-varid'>windingRule</span> <span class='hs-varid'>tolerance</span> <span class='hs-varid'>theNormal</span> <span class='hs-varid'>combiner</span> <span class='hs-varid'>complexPoly</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-298"></a>
<a name="line-299"></a> <span class='hs-varid'>beginModeState</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newIORef</span> <span class='hs-varid'>undefined</span>
<a name="line-300"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>setPrimitiveMode</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>writeIORef</span> <span class='hs-varid'>beginModeState</span>
<a name="line-301"></a>
<a name="line-302"></a> <span class='hs-varid'>vertices</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newIORef</span> <span class='hs-conid'>[]</span>
<a name="line-303"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>addVertex</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>modifyIORef</span> <span class='hs-varid'>vertices</span> <span class='hs-layout'>(</span><span class='hs-varid'>v</span><span class='hs-conop'>:</span><span class='hs-layout'>)</span>
<a name="line-304"></a>
<a name="line-305"></a> <span class='hs-varid'>primitives</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newIORef</span> <span class='hs-conid'>[]</span>
<a name="line-306"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>finishPrimitive</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-307"></a> <span class='hs-varid'>beginMode</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>readIORef</span> <span class='hs-varid'>beginModeState</span>
<a name="line-308"></a> <span class='hs-varid'>vs</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>readIORef</span> <span class='hs-varid'>vertices</span>
<a name="line-309"></a> <span class='hs-varid'>writeIORef</span> <span class='hs-varid'>vertices</span> <span class='hs-conid'>[]</span>
<a name="line-310"></a> <span class='hs-varid'>modifyIORef</span> <span class='hs-varid'>primitives</span> <span class='hs-layout'>(</span><span class='hs-conid'>Primitive</span> <span class='hs-varid'>beginMode</span> <span class='hs-layout'>(</span><span class='hs-varid'>reverse</span> <span class='hs-varid'>vs</span><span class='hs-layout'>)</span> <span class='hs-conop'>:</span><span class='hs-layout'>)</span>
<a name="line-311"></a>
<a name="line-312"></a> <span class='hs-varid'>getSimplePolygon</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span><span class='hs-conid'>SimplePolygon</span> <span class='hs-varop'>.</span> <span class='hs-varid'>reverse</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>readIORef</span> <span class='hs-varid'>primitives</span><span class='hs-layout'>)</span>
<a name="line-313"></a>
<a name="line-314"></a> <span class='hs-varid'>withTessellatorObj</span> <span class='hs-layout'>(</span><span class='hs-conid'>SimplePolygon</span> <span class='hs-conid'>[]</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>tessObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-315"></a> <span class='hs-varid'>setTessellatorProperties</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>windingRule</span> <span class='hs-varid'>tolerance</span> <span class='hs-varid'>theNormal</span> <span class='hs-conid'>False</span>
<a name="line-316"></a> <span class='hs-varid'>withBeginCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>setPrimitiveMode</span> <span class='hs-varop'>$</span>
<a name="line-317"></a> <span class='hs-varid'>withVertexCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>addVertex</span> <span class='hs-varop'>$</span>
<a name="line-318"></a> <span class='hs-varid'>withEndCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>finishPrimitive</span> <span class='hs-varop'>$</span>
<a name="line-319"></a> <span class='hs-varid'>checkForError</span> <span class='hs-varid'>tessObj</span> <span class='hs-varop'>$</span>
<a name="line-320"></a> <span class='hs-varid'>withCombineCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>combiner</span> <span class='hs-varop'>$</span> <span class='hs-keyword'>do</span>
<a name="line-321"></a> <span class='hs-varid'>defineComplexPolygon</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>complexPoly</span>
<a name="line-322"></a> <span class='hs-varid'>getSimplePolygon</span>
<a name="line-323"></a>
<a name="line-324"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-325"></a><span class='hs-comment'>-- chapter 5.1: The Tessellation Object</span>
<a name="line-326"></a>
<a name="line-327"></a><a name="TessellatorObj"></a><span class='hs-comment'>-- an opaque pointer to a tessellator object</span>
<a name="line-328"></a><a name="TessellatorObj"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Ptr</span> <span class='hs-conid'>GLUtesselator</span>
<a name="line-329"></a>
<a name="line-330"></a><a name="isNullTesselatorObj"></a><span class='hs-definition'>isNullTesselatorObj</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-331"></a><span class='hs-definition'>isNullTesselatorObj</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>nullPtr</span> <span class='hs-varop'>==</span><span class='hs-layout'>)</span>
<a name="line-332"></a>
<a name="line-333"></a><a name="withTessellatorObj"></a><span class='hs-definition'>withTessellatorObj</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
<a name="line-334"></a><span class='hs-definition'>withTessellatorObj</span> <span class='hs-varid'>failureValue</span> <span class='hs-varid'>action</span> <span class='hs-keyglyph'>=</span>
<a name="line-335"></a> <span class='hs-varid'>bracket</span> <span class='hs-varid'>gluNewTess</span> <span class='hs-varid'>safeDeleteTess</span>
<a name="line-336"></a> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>tessObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>if</span> <span class='hs-varid'>isNullTesselatorObj</span> <span class='hs-varid'>tessObj</span>
<a name="line-337"></a> <span class='hs-keyword'>then</span> <span class='hs-keyword'>do</span> <span class='hs-varid'>recordOutOfMemory</span>
<a name="line-338"></a> <span class='hs-varid'>return</span> <span class='hs-varid'>failureValue</span>
<a name="line-339"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>action</span> <span class='hs-varid'>tessObj</span><span class='hs-layout'>)</span>
<a name="line-340"></a>
<a name="line-341"></a><a name="safeDeleteTess"></a><span class='hs-definition'>safeDeleteTess</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-342"></a><span class='hs-definition'>safeDeleteTess</span> <span class='hs-varid'>tessObj</span> <span class='hs-keyglyph'>=</span>
<a name="line-343"></a> <span class='hs-varid'>unless</span> <span class='hs-layout'>(</span><span class='hs-varid'>isNullTesselatorObj</span> <span class='hs-varid'>tessObj</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-varid'>gluDeleteTess</span> <span class='hs-varid'>tessObj</span>
<a name="line-344"></a>
<a name="line-345"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-346"></a><span class='hs-comment'>-- chapter 5.2: Polygon Definition (polygons)</span>
<a name="line-347"></a>
<a name="line-348"></a><a name="defineComplexPolygon"></a><span class='hs-definition'>defineComplexPolygon</span> <span class='hs-keyglyph'>::</span>
<a name="line-349"></a> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ComplexPolygon</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-350"></a><span class='hs-definition'>defineComplexPolygon</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>cp</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>ComplexPolygon</span> <span class='hs-varid'>complexContours</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-351"></a> <span class='hs-varid'>withComplexPolygon</span> <span class='hs-varid'>cp</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>ptr</span> <span class='hs-keyglyph'>-></span>
<a name="line-352"></a> <span class='hs-varid'>tessBeginEndPolygon</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>nullPtr</span> <span class='hs-varop'>$</span>
<a name="line-353"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>loop</span> <span class='hs-keyword'>_</span> <span class='hs-conid'>[]</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>return</span> <span class='hs-conid'>()</span>
<a name="line-354"></a> <span class='hs-varid'>loop</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-varid'>c</span><span class='hs-conop'>:</span><span class='hs-varid'>cs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span> <span class='hs-varid'>defineComplexContour</span> <span class='hs-varid'>tessObj</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>p</span><span class='hs-layout'>)</span> <span class='hs-varid'>c</span>
<a name="line-355"></a> <span class='hs-varid'>loop</span> <span class='hs-layout'>(</span><span class='hs-varid'>p</span> <span class='hs-varop'>`plusPtr`</span> <span class='hs-varid'>sizeOfComplexContour</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-varid'>cs</span>
<a name="line-356"></a> <span class='hs-keyword'>in</span> <span class='hs-varid'>loop</span> <span class='hs-varid'>ptr</span> <span class='hs-varid'>complexContours</span>
<a name="line-357"></a>
<a name="line-358"></a><a name="tessBeginEndPolygon"></a><span class='hs-definition'>tessBeginEndPolygon</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Ptr</span> <span class='hs-varid'>p</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
<a name="line-359"></a><span class='hs-definition'>tessBeginEndPolygon</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>ptr</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-360"></a> <span class='hs-varid'>gluTessBeginPolygon</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>ptr</span>
<a name="line-361"></a> <span class='hs-varid'>res</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>f</span>
<a name="line-362"></a> <span class='hs-varid'>gluTessEndPolygon</span> <span class='hs-varid'>tessObj</span>
<a name="line-363"></a> <span class='hs-varid'>return</span> <span class='hs-varid'>res</span>
<a name="line-364"></a>
<a name="line-365"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-366"></a><span class='hs-comment'>-- chapter 5.2: Polygon Definition (contours)</span>
<a name="line-367"></a>
<a name="line-368"></a><a name="defineComplexContour"></a><span class='hs-definition'>defineComplexContour</span> <span class='hs-keyglyph'>::</span>
<a name="line-369"></a> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span>
<a name="line-370"></a> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>ComplexContour</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ComplexContour</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-371"></a><span class='hs-definition'>defineComplexContour</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>ComplexContour</span> <span class='hs-varid'>annotatedVertices</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-372"></a> <span class='hs-varid'>tessBeginEndContour</span> <span class='hs-varid'>tessObj</span> <span class='hs-varop'>$</span>
<a name="line-373"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>loop</span> <span class='hs-keyword'>_</span> <span class='hs-conid'>[]</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>return</span> <span class='hs-conid'>()</span>
<a name="line-374"></a> <span class='hs-varid'>loop</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-varid'>v</span><span class='hs-conop'>:</span><span class='hs-varid'>vs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span> <span class='hs-varid'>defineVertex</span> <span class='hs-varid'>tessObj</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>p</span><span class='hs-layout'>)</span>
<a name="line-375"></a> <span class='hs-varid'>loop</span> <span class='hs-layout'>(</span><span class='hs-varid'>p</span> <span class='hs-varop'>`plusPtr`</span> <span class='hs-varid'>sizeOf</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-varid'>vs</span>
<a name="line-376"></a> <span class='hs-keyword'>in</span> <span class='hs-varid'>loop</span> <span class='hs-varid'>ptr</span> <span class='hs-varid'>annotatedVertices</span>
<a name="line-377"></a>
<a name="line-378"></a><a name="tessBeginEndContour"></a><span class='hs-definition'>tessBeginEndContour</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
<a name="line-379"></a><span class='hs-definition'>tessBeginEndContour</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-380"></a> <span class='hs-varid'>gluTessBeginContour</span> <span class='hs-varid'>tessObj</span>
<a name="line-381"></a> <span class='hs-varid'>res</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>f</span>
<a name="line-382"></a> <span class='hs-varid'>gluTessEndContour</span> <span class='hs-varid'>tessObj</span>
<a name="line-383"></a> <span class='hs-varid'>return</span> <span class='hs-varid'>res</span>
<a name="line-384"></a>
<a name="line-385"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-386"></a><span class='hs-comment'>-- chapter 5.2: Polygon Definition (vertices)</span>
<a name="line-387"></a>
<a name="line-388"></a><a name="defineVertex"></a><span class='hs-definition'>defineVertex</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-389"></a><span class='hs-definition'>defineVertex</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>ptr</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>gluTessVertex</span> <span class='hs-varid'>tessObj</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span> <span class='hs-varid'>ptr</span>
<a name="line-390"></a>
<a name="line-391"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-392"></a><span class='hs-comment'>-- chapter 5.3: Callbacks (begin)</span>
<a name="line-393"></a>
<a name="line-394"></a><a name="BeginCallback"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>BeginCallback</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>PrimitiveMode</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-395"></a>
<a name="line-396"></a><a name="withBeginCallback"></a><span class='hs-definition'>withBeginCallback</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>BeginCallback</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
<a name="line-397"></a><span class='hs-definition'>withBeginCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>beginCallback</span> <span class='hs-varid'>action</span> <span class='hs-keyglyph'>=</span>
<a name="line-398"></a> <span class='hs-varid'>bracket</span> <span class='hs-layout'>(</span><span class='hs-varid'>makeTessBeginCallback</span> <span class='hs-layout'>(</span><span class='hs-varid'>beginCallback</span> <span class='hs-varop'>.</span> <span class='hs-varid'>unmarshalPrimitiveMode</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-399"></a> <span class='hs-varid'>freeHaskellFunPtr</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>callbackPtr</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-400"></a> <span class='hs-varid'>gluTessCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>glu_TESS_BEGIN</span> <span class='hs-varid'>callbackPtr</span>
<a name="line-401"></a> <span class='hs-varid'>action</span>
<a name="line-402"></a>
<a name="line-403"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-404"></a><span class='hs-comment'>-- chapter 5.3: Callbacks (edgeFlag)</span>
<a name="line-405"></a>
<a name="line-406"></a><a name="EdgeFlagCallback"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>EdgeFlagCallback</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>EdgeFlag</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-407"></a>
<a name="line-408"></a><a name="withEdgeFlagCallback"></a><span class='hs-definition'>withEdgeFlagCallback</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>EdgeFlagCallback</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
<a name="line-409"></a><span class='hs-definition'>withEdgeFlagCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>edgeFlagCallback</span> <span class='hs-varid'>action</span> <span class='hs-keyglyph'>=</span>
<a name="line-410"></a> <span class='hs-varid'>bracket</span> <span class='hs-layout'>(</span><span class='hs-varid'>makeTessEdgeFlagCallback</span> <span class='hs-layout'>(</span><span class='hs-varid'>edgeFlagCallback</span> <span class='hs-varop'>.</span> <span class='hs-varid'>unmarshalEdgeFlag</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-411"></a> <span class='hs-varid'>freeHaskellFunPtr</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>callbackPtr</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-412"></a> <span class='hs-varid'>gluTessCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>glu_TESS_EDGE_FLAG</span> <span class='hs-varid'>callbackPtr</span>
<a name="line-413"></a> <span class='hs-varid'>action</span>
<a name="line-414"></a>
<a name="line-415"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-416"></a><span class='hs-comment'>-- chapter 5.3: Callbacks (vertex)</span>
<a name="line-417"></a>
<a name="line-418"></a><a name="VertexCallback"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>VertexCallback</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-419"></a>
<a name="line-420"></a><a name="withVertexCallback"></a><span class='hs-definition'>withVertexCallback</span> <span class='hs-keyglyph'>::</span>
<a name="line-421"></a> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>VertexCallback</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
<a name="line-422"></a><span class='hs-definition'>withVertexCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>vertexCallback</span> <span class='hs-varid'>action</span> <span class='hs-keyglyph'>=</span>
<a name="line-423"></a> <span class='hs-varid'>bracket</span> <span class='hs-layout'>(</span><span class='hs-varid'>makeTessVertexCallback</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>p</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>peek</span> <span class='hs-varid'>p</span> <span class='hs-varop'>>>=</span> <span class='hs-varid'>vertexCallback</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-424"></a> <span class='hs-varid'>freeHaskellFunPtr</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>callbackPtr</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-425"></a> <span class='hs-varid'>gluTessCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>glu_TESS_VERTEX</span> <span class='hs-varid'>callbackPtr</span>
<a name="line-426"></a> <span class='hs-varid'>action</span>
<a name="line-427"></a>
<a name="line-428"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-429"></a><span class='hs-comment'>-- chapter 5.3: Callbacks (end)</span>
<a name="line-430"></a>
<a name="line-431"></a><a name="EndCallback"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>EndCallback</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-432"></a>
<a name="line-433"></a><a name="withEndCallback"></a><span class='hs-definition'>withEndCallback</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>EndCallback</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
<a name="line-434"></a><span class='hs-definition'>withEndCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>endCallback</span> <span class='hs-varid'>action</span> <span class='hs-keyglyph'>=</span>
<a name="line-435"></a> <span class='hs-varid'>bracket</span> <span class='hs-layout'>(</span><span class='hs-varid'>makeTessEndCallback</span> <span class='hs-varid'>endCallback</span><span class='hs-layout'>)</span> <span class='hs-varid'>freeHaskellFunPtr</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>callbackPtr</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-436"></a> <span class='hs-varid'>gluTessCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>glu_TESS_END</span> <span class='hs-varid'>callbackPtr</span>
<a name="line-437"></a> <span class='hs-varid'>action</span>
<a name="line-438"></a>
<a name="line-439"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-440"></a><span class='hs-comment'>-- chapter 5.3: Callbacks (error)</span>
<a name="line-441"></a>
<a name="line-442"></a><a name="ErrorCallback"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>ErrorCallback</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>GLenum</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-443"></a>
<a name="line-444"></a><a name="withErrorCallback"></a><span class='hs-definition'>withErrorCallback</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ErrorCallback</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
<a name="line-445"></a><span class='hs-definition'>withErrorCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>errorCallback</span> <span class='hs-varid'>action</span> <span class='hs-keyglyph'>=</span>
<a name="line-446"></a> <span class='hs-varid'>bracket</span> <span class='hs-layout'>(</span><span class='hs-varid'>makeTessErrorCallback</span> <span class='hs-varid'>errorCallback</span><span class='hs-layout'>)</span>
<a name="line-447"></a> <span class='hs-varid'>freeHaskellFunPtr</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>callbackPtr</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-448"></a> <span class='hs-varid'>gluTessCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>glu_TESS_ERROR</span> <span class='hs-varid'>callbackPtr</span>
<a name="line-449"></a> <span class='hs-varid'>action</span>
<a name="line-450"></a>
<a name="line-451"></a><a name="checkForError"></a><span class='hs-definition'>checkForError</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
<a name="line-452"></a><span class='hs-definition'>checkForError</span> <span class='hs-varid'>tessObj</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>withErrorCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>recordErrorCode</span>
<a name="line-453"></a>
<a name="line-454"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-455"></a><span class='hs-comment'>-- chapter 5.3: Callbacks (combine)</span>
<a name="line-456"></a>
<a name="line-457"></a><a name="CombineCallback"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>CombineCallback</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span>
<a name="line-458"></a> <span class='hs-conid'>Ptr</span> <span class='hs-conid'>GLdouble</span>
<a name="line-459"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-460"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Ptr</span> <span class='hs-conid'>GLfloat</span>
<a name="line-461"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-462"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-463"></a>
<a name="line-464"></a><a name="withCombineCallback"></a><span class='hs-definition'>withCombineCallback</span> <span class='hs-keyglyph'>::</span>
<a name="line-465"></a> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Combiner</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
<a name="line-466"></a><span class='hs-definition'>withCombineCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>combiner</span> <span class='hs-varid'>action</span> <span class='hs-keyglyph'>=</span>
<a name="line-467"></a> <span class='hs-varid'>withPool</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>vertexPool</span> <span class='hs-keyglyph'>-></span>
<a name="line-468"></a> <span class='hs-varid'>bracket</span> <span class='hs-layout'>(</span><span class='hs-varid'>makeTessCombineCallback</span> <span class='hs-layout'>(</span><span class='hs-varid'>combineProperties</span> <span class='hs-varid'>vertexPool</span> <span class='hs-varid'>combiner</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-469"></a> <span class='hs-varid'>freeHaskellFunPtr</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>callbackPtr</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-470"></a> <span class='hs-varid'>gluTessCallback</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>glu_TESS_COMBINE</span> <span class='hs-varid'>callbackPtr</span>
<a name="line-471"></a> <span class='hs-varid'>action</span>
<a name="line-472"></a>
<a name="line-473"></a><a name="combineProperties"></a><span class='hs-comment'>-- NOTE: SGI's tesselator has a bug, sometimes passing NULL for the last two</span>
<a name="line-474"></a><span class='hs-comment'>-- vertices instead of valid vertex data, so we have to work around this. We</span>
<a name="line-475"></a><span class='hs-comment'>-- just pass the first vertex in these cases, which is OK, because the</span>
<a name="line-476"></a><span class='hs-comment'>-- corresponding weight is 0.</span>
<a name="line-477"></a><span class='hs-definition'>combineProperties</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Pool</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Combiner</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>CombineCallback</span> <span class='hs-varid'>v</span>
<a name="line-478"></a><span class='hs-definition'>combineProperties</span> <span class='hs-varid'>pool</span> <span class='hs-varid'>combiner</span> <span class='hs-varid'>newVertexPtr</span> <span class='hs-varid'>propertyPtrs</span> <span class='hs-varid'>weights</span> <span class='hs-varid'>result</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-479"></a> <span class='hs-varid'>newVertex</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>peek</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>newVertexPtr</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>Vertex3</span> <span class='hs-conid'>GLdouble</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-480"></a> <span class='hs-keyglyph'>[</span><span class='hs-varid'>v0</span><span class='hs-layout'>,</span> <span class='hs-varid'>v1</span><span class='hs-layout'>,</span> <span class='hs-varid'>v2</span><span class='hs-layout'>,</span> <span class='hs-varid'>v3</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>mapM</span> <span class='hs-layout'>(</span><span class='hs-varid'>getProperty</span> <span class='hs-varid'>propertyPtrs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>0</span><span class='hs-keyglyph'>..</span><span class='hs-num'>3</span><span class='hs-keyglyph'>]</span>
<a name="line-481"></a> <span class='hs-keyglyph'>[</span><span class='hs-varid'>w0</span><span class='hs-layout'>,</span> <span class='hs-varid'>w1</span><span class='hs-layout'>,</span> <span class='hs-varid'>w2</span><span class='hs-layout'>,</span> <span class='hs-varid'>w3</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>peekArray</span> <span class='hs-num'>4</span> <span class='hs-varid'>weights</span>
<a name="line-482"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>defaultProperty</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fromJust</span> <span class='hs-varid'>v0</span>
<a name="line-483"></a> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fromMaybe</span> <span class='hs-varid'>defaultProperty</span>
<a name="line-484"></a> <span class='hs-varid'>wp</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>WeightedProperties</span> <span class='hs-layout'>(</span><span class='hs-varid'>w0</span><span class='hs-layout'>,</span> <span class='hs-varid'>f</span> <span class='hs-varid'>v0</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>w1</span><span class='hs-layout'>,</span> <span class='hs-varid'>f</span> <span class='hs-varid'>v1</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>w2</span><span class='hs-layout'>,</span> <span class='hs-varid'>f</span> <span class='hs-varid'>v2</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>w3</span><span class='hs-layout'>,</span> <span class='hs-varid'>f</span> <span class='hs-varid'>v3</span><span class='hs-layout'>)</span>
<a name="line-485"></a> <span class='hs-varid'>av</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>newVertex</span> <span class='hs-layout'>(</span><span class='hs-varid'>combiner</span> <span class='hs-varid'>newVertex</span> <span class='hs-varid'>wp</span><span class='hs-layout'>)</span>
<a name="line-486"></a> <span class='hs-varid'>poke</span> <span class='hs-varid'>result</span> <span class='hs-varop'>=<<</span> <span class='hs-varid'>pooledNew</span> <span class='hs-varid'>pool</span> <span class='hs-varid'>av</span>
<a name="line-487"></a>
<a name="line-488"></a><a name="getProperty"></a><span class='hs-definition'>getProperty</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-layout'>(</span><span class='hs-conid'>Maybe</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-489"></a><span class='hs-definition'>getProperty</span> <span class='hs-varid'>propertyPtrs</span> <span class='hs-varid'>n</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>peekElemOff</span> <span class='hs-varid'>propertyPtrs</span> <span class='hs-varid'>n</span> <span class='hs-varop'>>>=</span>
<a name="line-490"></a> <span class='hs-varid'>maybeNullPtr</span> <span class='hs-layout'>(</span><span class='hs-varid'>return</span> <span class='hs-conid'>Nothing</span><span class='hs-layout'>)</span> <span class='hs-varid'>peekProperty</span>
<a name="line-491"></a>
<a name="line-492"></a><a name="peekProperty"></a><span class='hs-definition'>peekProperty</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Storable</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Ptr</span> <span class='hs-layout'>(</span><span class='hs-conid'>AnnotatedVertex</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-layout'>(</span><span class='hs-conid'>Maybe</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-493"></a><span class='hs-definition'>peekProperty</span> <span class='hs-varid'>ptr</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-494"></a> <span class='hs-conid'>AnnotatedVertex</span> <span class='hs-keyword'>_</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>peek</span> <span class='hs-varid'>ptr</span>
<a name="line-495"></a> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-conid'>Just</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-496"></a>
<a name="line-497"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-498"></a><span class='hs-comment'>-- chapter 5.4: Control over Tessellation</span>
<a name="line-499"></a>
<a name="line-500"></a><a name="setTessellatorProperties"></a><span class='hs-definition'>setTessellatorProperties</span> <span class='hs-keyglyph'>::</span>
<a name="line-501"></a> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>TessWinding</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Tolerance</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Normal3</span> <span class='hs-conid'>GLdouble</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-502"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-503"></a><span class='hs-definition'>setTessellatorProperties</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>windingRule</span> <span class='hs-varid'>tolerance</span> <span class='hs-varid'>theNormal</span> <span class='hs-varid'>boundaryOnly</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-504"></a> <span class='hs-varid'>setWindingRule</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>windingRule</span>
<a name="line-505"></a> <span class='hs-varid'>setTolerance</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>tolerance</span>
<a name="line-506"></a> <span class='hs-varid'>setNormal</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>theNormal</span>
<a name="line-507"></a> <span class='hs-varid'>setBoundaryOnly</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>boundaryOnly</span>
<a name="line-508"></a>
<a name="line-509"></a><a name="setWindingRule"></a><span class='hs-definition'>setWindingRule</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>TessWinding</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-510"></a><span class='hs-definition'>setWindingRule</span> <span class='hs-varid'>tessObj</span> <span class='hs-keyglyph'>=</span>
<a name="line-511"></a> <span class='hs-varid'>gluTessProperty</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>glu_TESS_WINDING_RULE</span> <span class='hs-varop'>.</span> <span class='hs-varid'>fromIntegral</span> <span class='hs-varop'>.</span> <span class='hs-varid'>marshalTessWinding</span>
<a name="line-512"></a>
<a name="line-513"></a><a name="setBoundaryOnly"></a><span class='hs-definition'>setBoundaryOnly</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-514"></a><span class='hs-definition'>setBoundaryOnly</span> <span class='hs-varid'>tessObj</span> <span class='hs-keyglyph'>=</span>
<a name="line-515"></a> <span class='hs-varid'>gluTessProperty</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>glu_TESS_BOUNDARY_ONLY</span> <span class='hs-varop'>.</span> <span class='hs-varid'>marshalGLboolean</span>
<a name="line-516"></a>
<a name="line-517"></a><a name="setTolerance"></a><span class='hs-definition'>setTolerance</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Tolerance</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-518"></a><span class='hs-definition'>setTolerance</span> <span class='hs-varid'>tessObj</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>gluTessProperty</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>glu_TESS_TOLERANCE</span>
<a name="line-519"></a>
<a name="line-520"></a><a name="setNormal"></a><span class='hs-definition'>setNormal</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TessellatorObj</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Normal3</span> <span class='hs-conid'>GLdouble</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-521"></a><span class='hs-definition'>setNormal</span> <span class='hs-varid'>tessObj</span> <span class='hs-layout'>(</span><span class='hs-conid'>Normal3</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-varid'>z</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>gluTessNormal</span> <span class='hs-varid'>tessObj</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-varid'>z</span>
</pre></body>
</html>
|