This file is indexed.

/usr/include/gts.h is in libgts-dev 0.7.6+darcs121130-4.

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
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
/* GTS - Library for the manipulation of triangulated surfaces
 * Copyright (C) 1999 Stéphane Popinet
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __GTS_H__
#define __GTS_H__

#include <stdio.h>
#include <glib.h>
#ifndef NATIVE_WIN32
# include <gtsconfig.h>
#endif
#ifdef GTS_COMPILATION
# include "config.h"
#endif /* not GTS_COMPILATION */

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* Added based on glib.h by M J Loehr 01/01/01 */
/* GTS version.
 * we prefix variable declarations so they can
 * properly get exported in windows dlls.
 */
#ifdef NATIVE_WIN32
#  ifdef GTS_COMPILATION
#    define GTS_C_VAR __declspec(dllexport)
#  else /* not GTS_COMPILATION */
#    define GTS_C_VAR extern __declspec(dllimport)
#  endif /* not GTS_COMPILATION */
#else /* not NATIVE_WIN32 */
#  define GTS_C_VAR extern
#endif /* not NATIVE_WIN32 */

GTS_C_VAR const guint gts_major_version;
GTS_C_VAR const guint gts_minor_version;
GTS_C_VAR const guint gts_micro_version;
GTS_C_VAR const guint gts_interface_age;
GTS_C_VAR const guint gts_binary_age;

#define GTS_CHECK_VERSION(major,minor,micro)    \
    (gts_major_version > (major) || \
    (gts_major_version == (major) && gts_minor_version > (minor)) || \
    (gts_major_version == (major) && gts_minor_version == (minor) && \
     gts_micro_version >= (micro)))

#define GTS_COMMENTS  "#!"
#define GTS_MAINTAINER "popinet@users.sourceforge.net"

/* Class declarations for base types */

typedef struct _GtsObjectClassInfo     GtsObjectClassInfo;
typedef struct _GtsObject        GtsObject;
typedef struct _GtsObjectClass   GtsObjectClass;
typedef struct _GtsPoint         GtsPoint;
typedef struct _GtsPointClass    GtsPointClass;
typedef struct _GtsVertex        GtsVertex;
typedef struct _GtsVertexClass   GtsVertexClass;
typedef struct _GtsSegment       GtsSegment;
typedef struct _GtsSegmentClass  GtsSegmentClass;
typedef struct _GtsEdge          GtsEdge;
typedef struct _GtsEdgeClass     GtsEdgeClass;
typedef struct _GtsTriangle      GtsTriangle;
typedef struct _GtsTriangleClass GtsTriangleClass;
typedef struct _GtsFace          GtsFace;
typedef struct _GtsFaceClass     GtsFaceClass;
typedef struct _GtsBBox          GtsBBox;
typedef struct _GtsBBoxClass     GtsBBoxClass;
typedef struct _GtsSurface       GtsSurface;
typedef struct _GtsSurfaceClass  GtsSurfaceClass;

typedef void         (*GtsObjectClassInitFunc) (GtsObjectClass * objclass);
typedef void         (*GtsObjectInitFunc)      (GtsObject * obj);
typedef void         (*GtsArgSetFunc)          (GtsObject * obj);
typedef void         (*GtsArgGetFunc)          (GtsObject * obj);

typedef gdouble                  GtsVector[3];
typedef gdouble                  GtsVector4[4];
typedef GtsVector4               GtsMatrix;
/**
 * GtsKeyFunc:
 * @item: A pointer to an item to be stored in the heap.
 * @data: User data passed to gts_eheap_new().
 *
 * Returns: the value of the key for the given item.
 */
typedef gdouble                  (*GtsKeyFunc)    (gpointer item,
						   gpointer data);
typedef enum 
{ 
  GTS_OUT = -1,
  GTS_ON = 0,
  GTS_IN = 1
} GtsIntersect;

typedef struct _GtsColor         GtsColor;

struct _GtsColor {
  gfloat r, g, b;
};

typedef gint   (*GtsFunc)              (gpointer item,
					gpointer data);

/* misc.c */

typedef struct _GtsFile GtsFile;

typedef enum {
  GTS_NONE   = 1 << 8,
  GTS_INT    = 1 << 9,
  GTS_UINT   = 1 << 10,
  GTS_FLOAT  = 1 << 11,
  GTS_DOUBLE = 1 << 12,
  GTS_STRING = 1 << 13,
  GTS_FILE   = 1 << 14,
  GTS_ERROR  = 1 << 15,
  GTS_OBJ    = 1 << 16,
} GtsTokenType;

struct _GtsFile {
  FILE * fp;
  guint line, pos;
  GString * token;
  GtsTokenType type;
  gchar * error;

  guint curline, curpos;
  guint scope, scope_max;
  gint next_token;
  gchar * delimiters;
  gchar * comments;
  gchar * tokens;
  gchar * buf;
  size_t len;
};

typedef struct _GtsFileVariable GtsFileVariable;

struct _GtsFileVariable {
  GtsTokenType type;
  gchar name[30];
  gboolean unique;
  gpointer data;
  gboolean set;
  guint line, pos;
};

GtsFile *      gts_file_new               (FILE * fp);
GtsFile *      gts_file_new_from_string   (gchar * s);
GtsFile *      gts_file_new_from_buffer   (gchar * buf,
					   size_t len);
void           gts_file_verror            (GtsFile * f,
					   const gchar * format,
					   va_list args);
void           gts_file_error             (GtsFile * f,
					   const gchar * format,
					   ...);
gint           gts_file_getc              (GtsFile * f);
guint          gts_file_read              (GtsFile * f, 
					   gpointer ptr, 
					   guint size, 
					   guint nmemb);
gint           gts_file_getc_scope        (GtsFile * f);
void           gts_file_next_token        (GtsFile * f);
void           gts_file_first_token_after (GtsFile * f, 
					   GtsTokenType type);
void           gts_file_assign_start      (GtsFile * f, 
					   GtsFileVariable * vars);
GtsFileVariable * gts_file_assign_next    (GtsFile * f, 
					   GtsFileVariable * vars);
void           gts_file_assign_variables  (GtsFile * f, 
					   GtsFileVariable * vars);
void           gts_file_variable_error    (GtsFile * f, 
					   GtsFileVariable * vars,
					   const gchar * name,
					   const gchar * format,
					   ...);
void           gts_file_destroy           (GtsFile * f);

/* Objects: object.c */

#ifdef GTS_CHECK_CASTS
#  define GTS_OBJECT_CAST(obj, type, klass) ((type *) gts_object_check_cast (obj, klass))
#  define GTS_OBJECT_CLASS_CAST(objklass, type, klass) ((type *) gts_object_class_check_cast (objklass, klass))
#else  /* not GTS_CHECK_CASTS */
#  define GTS_OBJECT_CAST(obj, type, klass)             ((type *) (obj))
#  define GTS_OBJECT_CLASS_CAST(objklass, type, klass)  ((type *) (objklass))
#endif /* not GTS_CHECK_CASTS */

#define GTS_CLASS_NAME_LENGTH 40
#define GTS_OBJECT(obj)          GTS_OBJECT_CAST (obj,\
						  GtsObject,\
						  gts_object_class ())
#define GTS_OBJECT_CLASS(klass)  GTS_OBJECT_CLASS_CAST (klass,\
							GtsObjectClass,\
							gts_object_class())
#define GTS_IS_OBJECT(obj) (gts_object_is_from_class (obj,\
						      gts_object_class ()))

typedef enum
{
  GTS_DESTROYED         = 1 << 0,
  GTS_USER_FLAG         = 1 /* user flags start from here */
} GtsObjectFlags;

#define GTS_OBJECT_FLAGS(obj)             (GTS_OBJECT (obj)->flags)
#define GTS_OBJECT_DESTROYED(obj)         ((GTS_OBJECT_FLAGS (obj) & GTS_DESTROYED) != 0)
#define GTS_OBJECT_SET_FLAGS(obj,flag)	  G_STMT_START{ (GTS_OBJECT_FLAGS (obj) |= (flag)); }G_STMT_END
#define GTS_OBJECT_UNSET_FLAGS(obj,flag)  G_STMT_START{ (GTS_OBJECT_FLAGS (obj) &= ~(flag)); }G_STMT_END

struct _GtsObjectClassInfo {
  gchar name[GTS_CLASS_NAME_LENGTH];
  guint object_size;
  guint class_size;
  GtsObjectClassInitFunc class_init_func;
  GtsObjectInitFunc object_init_func;
  GtsArgSetFunc arg_set_func;
  GtsArgGetFunc arg_get_func;
};

struct _GtsObject {
  GtsObjectClass * klass;

  gpointer reserved;
  guint32 flags;
};

struct _GtsObjectClass {
  GtsObjectClassInfo info;
  GtsObjectClass * parent_class;

  void        (* clone)      (GtsObject *, GtsObject *);
  void        (* destroy)    (GtsObject *);
  void        (* read)       (GtsObject **, GtsFile *);
  void        (* write)      (GtsObject *, FILE *);
  GtsColor    (* color)      (GtsObject *);
  void        (* attributes) (GtsObject *, GtsObject *);
};

gpointer         gts_object_class_new      (GtsObjectClass * parent_class,
					    GtsObjectClassInfo * info);
GtsObjectClass * gts_object_class          (void);
gpointer         gts_object_check_cast     (gpointer object, 
					    gpointer klass);
gpointer         gts_object_class_check_cast (gpointer klass, 
					      gpointer from);

static inline
gpointer gts_object_is_from_class (gpointer object,
				   gpointer klass)
{
  GtsObjectClass * c;

  g_return_val_if_fail (klass != NULL, NULL);

  if (object == NULL)
    return NULL;

  c = ((GtsObject *) object)->klass;

  g_return_val_if_fail (c != NULL, NULL);

  while (c) {
    if (c == klass)
      return object;
    c = c->parent_class;
  }

  return NULL;
}

static inline
gpointer gts_object_class_is_from_class (gpointer klass,
					 gpointer from)
{
  GtsObjectClass * c;

  g_return_val_if_fail (klass != NULL, NULL);
  g_return_val_if_fail (from != NULL, NULL);

  c = (GtsObjectClass *) klass;
  while (c) {
    if (c == from)
      return klass;
    c = c->parent_class;
  }

  return NULL;
}

GtsObjectClass * gts_object_class_from_name     (const gchar * name);

GtsObject *      gts_object_new                 (GtsObjectClass * klass);
GtsObject *      gts_object_clone               (GtsObject * object);
void             gts_object_attributes          (GtsObject * object, 
						 GtsObject * from);
void             gts_object_init                (GtsObject * object, 
						 GtsObjectClass * klass);
void             gts_object_reset_reserved      (GtsObject * object);
void             gts_object_destroy             (GtsObject * object);
void             gts_finalize                   (void);

/* Ranges: surface.c */
typedef struct _GtsRange               GtsRange;

struct _GtsRange {
  gdouble min, max, sum, sum2, mean, stddev;
  guint n;
};

void gts_range_init         (GtsRange * r);
void gts_range_reset        (GtsRange * r);
void gts_range_add_value    (GtsRange * r, 
			     gdouble val);
void gts_range_update       (GtsRange * r);
void gts_range_print        (GtsRange * r, 
			     FILE * fptr);

/* Points: point.c */

#define GTS_IS_POINT(obj) (gts_object_is_from_class (obj,\
						     gts_point_class ()))
#define GTS_POINT(obj)              GTS_OBJECT_CAST (obj,\
						     GtsPoint,\
						     gts_point_class ())
#define GTS_POINT_CLASS(klass)      GTS_OBJECT_CLASS_CAST (klass,\
							   GtsPointClass,\
							   gts_point_class ())

struct _GtsPoint {
  GtsObject object;

  gdouble x, y, z; /* must be contiguous (cast to robust functions) */
};

struct _GtsPointClass {
  GtsObjectClass parent_class;
  gboolean binary;
};

GtsPointClass * gts_point_class                      (void);
GtsPoint *    gts_point_new                          (GtsPointClass * klass,
						      gdouble x, 
						      gdouble y, 
						      gdouble z);
void          gts_point_set                          (GtsPoint * p, 
						      gdouble x, 
						      gdouble y, 
						      gdouble z);
#define       gts_point_is_in_rectangle(p, p1, p2)   ((p)->x >= (p1)->x &&\
						      (p)->x <= (p2)->x &&\
						      (p)->y >= (p1)->y &&\
						      (p)->y <= (p2)->y &&\
						      (p)->z >= (p1)->z &&\
						      (p)->z <= (p2)->z)
GtsPoint *    gts_segment_triangle_intersection      (GtsSegment * s,
						      GtsTriangle * t,
						      gboolean boundary,
						      GtsPointClass * klass);
void          gts_point_transform                    (GtsPoint * p, 
						      GtsMatrix * m);
gdouble       gts_point_distance                     (GtsPoint * p1,
						      GtsPoint * p2);
gdouble       gts_point_distance2                    (GtsPoint * p1,
						      GtsPoint * p2);
gdouble       gts_point_orientation_3d               (GtsPoint * p1,
						      GtsPoint * p2,
						      GtsPoint * p3,
						      GtsPoint * p4);
gint          gts_point_orientation_3d_sos           (GtsPoint * p1,
						      GtsPoint * p2,
						      GtsPoint * p3,
						      GtsPoint * p4);
GtsIntersect  gts_point_is_in_triangle               (GtsPoint * p,
						      GtsTriangle * t);
gdouble       gts_point_in_circle                    (GtsPoint * p, 
						      GtsPoint * p1,
						      GtsPoint * p2,
						      GtsPoint * p3);
gdouble       gts_point_in_sphere                    (GtsPoint * p, 
						      GtsPoint * p1,
						      GtsPoint * p2,
						      GtsPoint * p3,
						      GtsPoint * p4);
gdouble       gts_point_in_triangle_circle           (GtsPoint * p, 
						      GtsTriangle * t);
gdouble       gts_point_orientation                  (GtsPoint * p1,
						      GtsPoint * p2,
						      GtsPoint * p3);
gint          gts_point_orientation_sos              (GtsPoint * p1,
						      GtsPoint * p2,
						      GtsPoint * p3);
gdouble       gts_point_segment_distance2            (GtsPoint * p, 
						      GtsSegment * s);
gdouble       gts_point_segment_distance             (GtsPoint * p, 
						      GtsSegment * s);
void          gts_point_segment_closest              (GtsPoint * p, 
						      GtsSegment * s,
						      GtsPoint * closest);
gdouble       gts_point_triangle_distance2           (GtsPoint * p, 
						      GtsTriangle * t);
gdouble       gts_point_triangle_distance            (GtsPoint * p, 
						      GtsTriangle * t);
void          gts_point_triangle_closest             (GtsPoint * p,
						      GtsTriangle * t,
						      GtsPoint * closest);
gboolean      gts_point_is_inside_surface            (GtsPoint * p, 
						      GNode * tree,
						      gboolean is_open);

/* Vertices: vertex.c */

#define GTS_IS_VERTEX(obj)   (gts_object_is_from_class (obj,\
							gts_vertex_class ()))
#define GTS_VERTEX(obj)             GTS_OBJECT_CAST (obj,\
						     GtsVertex,\
						     gts_vertex_class ())
#define GTS_VERTEX_CLASS(klass)     GTS_OBJECT_CLASS_CAST (klass,\
							   GtsVertexClass,\
							   gts_vertex_class ())
struct _GtsVertex {
  GtsPoint p;
  
  GSList * segments;
};

struct _GtsVertexClass {
  GtsPointClass parent_class;

  void        (* intersection_attributes) (GtsVertex *, 
					   GtsObject *, 
					   GtsObject *);
};

GTS_C_VAR 
gboolean      gts_allow_floating_vertices;

GtsVertexClass * gts_vertex_class          (void);
GtsVertex *   gts_vertex_new               (GtsVertexClass * klass,
					    gdouble x,
					    gdouble y,
					    gdouble z);
void          gts_vertex_replace           (GtsVertex * v, 
					    GtsVertex * with);
gboolean      gts_vertex_is_unattached     (GtsVertex * v);
GtsSegment *  gts_vertices_are_connected   (GtsVertex * v1,
					    GtsVertex * v2);
GSList *      gts_vertex_triangles         (GtsVertex * v,
					    GSList * list);
GSList *      gts_vertex_faces             (GtsVertex * v,
					    GtsSurface * surface,
					    GSList * list);
GSList *      gts_vertex_neighbors         (GtsVertex * v, 
					    GSList * list,
					    GtsSurface * surface);
GSList *      gts_vertices_from_segments   (GSList * segments);
gboolean      gts_vertex_is_boundary       (GtsVertex * v, 
					    GtsSurface * surface);
GList *       gts_vertices_merge           (GList * vertices, 
					    gdouble epsilon,
					    gboolean (* check) (GtsVertex *, GtsVertex *));
GSList *      gts_vertex_fan_oriented      (GtsVertex * v, 
					    GtsSurface * surface);
guint         gts_vertex_is_contact        (GtsVertex * v, gboolean sever);

/* GtsVertexNormal: Header */

typedef struct _GtsVertexNormal         GtsVertexNormal;

struct _GtsVertexNormal {
  /*< private >*/
  GtsVertex parent;

  /*< public >*/
  GtsVector n;
};

#define GTS_VERTEX_NORMAL(obj)            GTS_OBJECT_CAST (obj,\
					         GtsVertexNormal,\
					         gts_vertex_normal_class ())
#define GTS_IS_VERTEX_NORMAL(obj)         (gts_object_is_from_class (obj,\
						 gts_vertex_normal_class ()))

GtsVertexClass * gts_vertex_normal_class  (void);

/* GtsColorVertex: Header */

typedef struct _GtsColorVertex         GtsColorVertex;

struct _GtsColorVertex {
  /*< private >*/
  GtsVertex parent;

  /*< public >*/
  GtsColor c;
};

#define GTS_COLOR_VERTEX(obj)            GTS_OBJECT_CAST (obj,\
					         GtsColorVertex,\
					         gts_color_vertex_class ())
#define GTS_IS_COLOR_VERTEX(obj)         (gts_object_is_from_class (obj,\
						 gts_color_vertex_class ()))

GtsVertexClass * gts_color_vertex_class  (void);

/* Segments: segment.c */

#define GTS_IS_SEGMENT(obj) (gts_object_is_from_class (obj,\
						       gts_segment_class ()))
#define GTS_SEGMENT(obj)          GTS_OBJECT_CAST (obj,\
						   GtsSegment,\
						   gts_segment_class ())
#define GTS_SEGMENT_CLASS(klass)  GTS_OBJECT_CLASS_CAST (klass,\
							 GtsSegmentClass,\
							 gts_segment_class ())

struct _GtsSegment {
  GtsObject object;

  GtsVertex * v1;
  GtsVertex * v2;
};

struct _GtsSegmentClass {
  GtsObjectClass parent_class;
};

GtsSegmentClass * gts_segment_class                  (void);
GtsSegment *  gts_segment_new                        (GtsSegmentClass * klass,
						      GtsVertex * v1, 
						      GtsVertex * v2);
#define       gts_segment_connect(s, e1, e2)         (((s)->v1 == e1 &&\
                                                       (s)->v2 == e2) || \
                                                      ((s)->v1 == e2 &&\
                                                       (s)->v2 == e1))
#define       gts_segments_are_identical(s1, s2)     (((s1)->v1 == (s2)->v1 &&\
						       (s1)->v2 == (s2)->v2)\
						      ||\
						      ((s1)->v1 == (s2)->v2 &&\
						       (s1)->v2 == (s2)->v1))
#define       gts_segments_touch(s1, s2)             ((s1)->v1 == (s2)->v1 ||\
						      (s1)->v1 == (s2)->v2 ||\
						      (s1)->v2 == (s2)->v1 ||\
						      (s1)->v2 == (s2)->v2)
GtsIntersect  gts_segments_are_intersecting          (GtsSegment * s1,
						      GtsSegment * s2);
GtsSegment *  gts_segment_is_duplicate               (GtsSegment * s);
GtsVertex *   gts_segment_midvertex                  (GtsSegment * s,
						      GtsVertexClass * klass);
GSList *      gts_segments_from_vertices             (GSList * vertices);
gboolean      gts_segment_is_ok                      (GtsSegment * s);

/* Edges: edge.c */

#define GTS_IS_EDGE(obj)  (gts_object_is_from_class (obj,\
						     gts_edge_class ()))
#define GTS_EDGE(obj)            GTS_OBJECT_CAST (obj,\
						  GtsEdge,\
						  gts_edge_class ())
#define GTS_EDGE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
							GtsEdgeClass,\
							gts_edge_class ())

struct _GtsEdge {
  GtsSegment segment;

  GSList * triangles;
};

struct _GtsEdgeClass {
  GtsSegmentClass parent_class;
};

GTS_C_VAR 
gboolean      gts_allow_floating_edges;

GtsEdgeClass * gts_edge_class                     (void);
GtsEdge *     gts_edge_new                        (GtsEdgeClass * klass,
						   GtsVertex * v1,
						   GtsVertex * v2);
/**
 * gts_edge_is_unattached:
 * @s: a #GtsEdge.
 *
 * Evaluates to %TRUE if no triangles uses @s as an edge, %FALSE otherwise.
 */
#define       gts_edge_is_unattached(s) ((s)->triangles == NULL ? TRUE : FALSE)
GtsFace *     gts_edge_has_parent_surface         (GtsEdge * e, 
						   GtsSurface * surface);
GtsFace *     gts_edge_has_any_parent_surface     (GtsEdge * e);
GtsFace *     gts_edge_is_boundary                (GtsEdge * e, 
						   GtsSurface * surface);
void          gts_edge_replace                    (GtsEdge * e,
						   GtsEdge * with);
GSList *      gts_edges_from_vertices             (GSList * vertices,
						   GtsSurface * parent);
guint         gts_edge_face_number                (GtsEdge * e,
						   GtsSurface * s);
gboolean      gts_edge_collapse_is_valid          (GtsEdge * e);
gboolean      gts_edge_collapse_creates_fold      (GtsEdge * e, 
						   GtsVertex * v,
						   gdouble max);
GtsEdge *     gts_edge_is_duplicate               (GtsEdge * e);
GList *       gts_edges_merge                     (GList * edges);
gboolean      gts_edge_belongs_to_tetrahedron     (GtsEdge * e);
guint         gts_edge_is_contact                 (GtsEdge * e);
void          gts_edge_swap                       (GtsEdge * e, 
						   GtsSurface * s);
gboolean      gts_edge_manifold_faces             (GtsEdge * e, 
						   GtsSurface * s,
						   GtsFace ** f1, 
						   GtsFace ** f2);

/* Triangles: triangle.c */

#define GTS_IS_TRIANGLE(obj) (gts_object_is_from_class (obj,\
							gts_triangle_class ()))
#define GTS_TRIANGLE(obj)         GTS_OBJECT_CAST (obj,\
						   GtsTriangle,\
						   gts_triangle_class ())
#define GTS_TRIANGLE_CLASS(klass) GTS_OBJECT_CLASS_CAST (klass,\
							 GtsTriangleClass,\
							 gts_triangle_class ())

struct _GtsTriangle {
  GtsObject object;

  GtsEdge * e1;
  GtsEdge * e2;
  GtsEdge * e3;
};

struct _GtsTriangleClass {
  GtsObjectClass parent_class;
};

GtsTriangleClass * gts_triangle_class        (void);
void        gts_triangle_set                 (GtsTriangle * triangle, 
					      GtsEdge * e1, 
					      GtsEdge * e2,
					      GtsEdge * e3);
GtsTriangle * gts_triangle_new               (GtsTriangleClass * klass, 
					      GtsEdge * e1, 
					      GtsEdge * e2,
					      GtsEdge * e3);
#define     gts_triangle_vertex(t) (GTS_SEGMENT (GTS_TRIANGLE (t)->e1)->v1 ==\
                                    GTS_SEGMENT (GTS_TRIANGLE (t)->e2)->v1 || \
                                    GTS_SEGMENT (GTS_TRIANGLE (t)->e1)->v2 ==\
                                    GTS_SEGMENT (GTS_TRIANGLE (t)->e2)->v1 ? \
                                    GTS_SEGMENT (GTS_TRIANGLE (t)->e2)->v2 :\
                                    GTS_SEGMENT (GTS_TRIANGLE (t)->e2)->v1)
GtsVertex *   gts_triangle_vertex_opposite  (GtsTriangle * t, 
					     GtsEdge * e);
GtsEdge *     gts_triangle_edge_opposite    (GtsTriangle * t, 
					     GtsVertex * v);
gdouble       gts_triangles_angle           (GtsTriangle * t1,
					     GtsTriangle * t2);
gboolean      gts_triangles_are_compatible  (GtsTriangle * t1, 
					     GtsTriangle * t2,
					     GtsEdge * e);
gdouble       gts_triangle_area             (GtsTriangle * t);
gdouble       gts_triangle_perimeter        (GtsTriangle * t);
gdouble       gts_triangle_quality          (GtsTriangle * t);
void          gts_triangle_normal           (GtsTriangle * t, 
					     gdouble * x, 
					     gdouble * y, 
					     gdouble * z);
gdouble       gts_triangle_orientation      (GtsTriangle * t);
void          gts_triangle_revert           (GtsTriangle * t);
GSList *      gts_triangles_from_edges      (GSList * edges);
void          gts_triangle_vertices_edges   (GtsTriangle * t, 
					     GtsEdge * e,
					     GtsVertex ** v1, 
					     GtsVertex ** v2, 
					     GtsVertex ** v3,
					     GtsEdge ** e1,
					     GtsEdge ** e2,
					     GtsEdge ** e3);
GtsTriangle * gts_triangle_enclosing        (GtsTriangleClass * klass,
					     GSList * points, 
					     gdouble scale);
guint         gts_triangle_neighbor_number  (GtsTriangle * t);
GSList *      gts_triangle_neighbors        (GtsTriangle * t);
GtsEdge *     gts_triangles_common_edge     (GtsTriangle * t1,
					     GtsTriangle * t2);
GtsTriangle * gts_triangle_is_duplicate     (GtsTriangle * t);
GtsTriangle * gts_triangle_use_edges        (GtsEdge * e1,
					     GtsEdge * e2,
					     GtsEdge * e3);
gboolean      gts_triangle_is_ok            (GtsTriangle * t);
void          gts_triangle_vertices         (GtsTriangle * t,
					     GtsVertex ** v1,
					     GtsVertex ** v2,
					     GtsVertex ** v3);
GtsPoint *    gts_triangle_circumcircle_center (GtsTriangle * t,
						GtsPointClass * point_class);
gboolean      gts_triangles_are_folded      (GSList * triangles,
					     GtsVertex * A, GtsVertex * B,
					     gdouble max);
GtsObject *   gts_triangle_is_stabbed       (GtsTriangle * t,
					     GtsPoint * p,
					     gdouble * orientation);
void          gts_triangle_interpolate_height (GtsTriangle * t, 
					       GtsPoint * p);

/* Faces: face.c */

#define GTS_IS_FACE(obj) (gts_object_is_from_class (obj,\
						    gts_face_class ()))
#define GTS_FACE(obj)          GTS_OBJECT_CAST (obj,\
						GtsFace,\
						gts_face_class ())
#define GTS_FACE_CLASS(klass)  GTS_OBJECT_CLASS_CAST (klass,\
						      GtsFaceClass,\
						      gts_face_class ())

struct _GtsFace {
  GtsTriangle triangle;

  GSList * surfaces;
};

struct _GtsFaceClass {
  GtsTriangleClass parent_class;
};

GTS_C_VAR 
gboolean      gts_allow_floating_faces;

GtsFaceClass * gts_face_class                       (void);
GtsFace *     gts_face_new                          (GtsFaceClass * klass,
						     GtsEdge * e1,
						     GtsEdge * e2,
						     GtsEdge * e3);
gboolean      gts_face_has_parent_surface           (GtsFace * f,
						     GtsSurface * s);
GSList *      gts_faces_from_edges                  (GSList * edges, 
						     GtsSurface * s);
guint         gts_face_neighbor_number              (GtsFace * f, 
						     GtsSurface * s);
GSList *      gts_face_neighbors                    (GtsFace * f, 
						     GtsSurface * s);
void          gts_face_foreach_neighbor             (GtsFace * f, 
						     GtsSurface * s, 
						     GtsFunc func,
						     gpointer data);
gboolean      gts_face_is_compatible                (GtsFace * f, 
						     GtsSurface * s);

/* Matrices: matrix.c */

#define       gts_vector_cross(C,A,B) ((C)[0] = (A)[1]*(B)[2] - (A)[2]*(B)[1],\
			               (C)[1] = (A)[2]*(B)[0] - (A)[0]*(B)[2],\
			               (C)[2] = (A)[0]*(B)[1] - (A)[1]*(B)[0])

#define       gts_vector_init(v, p1, p2)   ((v)[0] = (p2)->x - (p1)->x,\
					    (v)[1] = (p2)->y - (p1)->y,\
					    (v)[2] = (p2)->z - (p1)->z)
#define       gts_vector_scalar(v1, v2)    ((v1)[0]*(v2)[0] +\
					    (v1)[1]*(v2)[1] +\
					    (v1)[2]*(v2)[2])
#define       gts_vector_norm(v)   (sqrt ((v)[0]*(v)[0] +\
                                          (v)[1]*(v)[1] +\
                                          (v)[2]*(v)[2]))
#define       gts_vector_normalize(v) {\
  gdouble __gts_n = gts_vector_norm (v);\
  if (__gts_n > 0.) {\
    (v)[0] /= __gts_n;\
    (v)[1] /= __gts_n;\
    (v)[2] /= __gts_n;\
  }\
}
GtsMatrix * gts_matrix_new (gdouble a00, gdouble a01, gdouble a02, gdouble a03,
			    gdouble a10, gdouble a11, gdouble a12, gdouble a13,
			    gdouble a20, gdouble a21, gdouble a22, gdouble a23,
			    gdouble a30, gdouble a31, gdouble a32, gdouble a33);
void gts_matrix_assign (GtsMatrix * m,
			gdouble a00, gdouble a01, gdouble a02, gdouble a03,
			gdouble a10, gdouble a11, gdouble a12, gdouble a13,
			gdouble a20, gdouble a21, gdouble a22, gdouble a23,
			gdouble a30, gdouble a31, gdouble a32, gdouble a33);
GtsMatrix *   gts_matrix_projection                  (GtsTriangle * t);
GtsMatrix *   gts_matrix_transpose                   (GtsMatrix * m);
gdouble       gts_matrix_determinant                 (GtsMatrix * m);
GtsMatrix *   gts_matrix_inverse                     (GtsMatrix * m);
GtsMatrix *   gts_matrix3_inverse                    (GtsMatrix * m);
void          gts_matrix_print                       (GtsMatrix * m, 
						      FILE * fptr);
guint         gts_matrix_compatible_row              (GtsMatrix * A,
						      GtsVector b,
						      guint n,
						      GtsVector A1,
						      gdouble b1);
guint         gts_matrix_quadratic_optimization      (GtsMatrix * A,
						      GtsVector b,
						      guint n,
						      GtsMatrix * H,
						      GtsVector c);
GtsMatrix *   gts_matrix_product                     (GtsMatrix * m1, 
						      GtsMatrix * m2);
GtsMatrix *   gts_matrix_zero                        (GtsMatrix * m);
GtsMatrix *   gts_matrix_identity                    (GtsMatrix * m);
GtsMatrix *   gts_matrix_scale                       (GtsMatrix * m, 
						      GtsVector s);
GtsMatrix *   gts_matrix_translate                   (GtsMatrix * m, 
						      GtsVector t);
GtsMatrix *   gts_matrix_rotate                      (GtsMatrix * m,
						      GtsVector r,
						      gdouble angle);
void          gts_matrix_destroy                     (GtsMatrix * m);
void          gts_vector_print                       (GtsVector v,
						      FILE * fptr);
void          gts_vector4_print                      (GtsVector4 v, 
						      FILE * fptr);

/* Kdtrees: kdtree.c */

#define       gts_kdtree_destroy(tree)               g_node_destroy(tree)

GNode *       gts_kdtree_new                         (GPtrArray * points,
						      int (*compare)
						      (const void *, 
						       const void *));
GSList *      gts_kdtree_range                       (GNode * tree,
						      GtsBBox * bbox,
						      int (*compare)
						      (const void *, 
						      const void *));

/* Bboxtrees: bbtree.c */

/**
 * GtsBBTreeTraverseFunc:
 * @bb1: a #GtsBBox.
 * @bb2: another #GtsBBox.
 * @data: user data passed to the function.
 *
 * User function called for each pair of overlapping bounding
 * boxes. See gts_bb_tree_traverse_overlapping().
 */
typedef void   (*GtsBBTreeTraverseFunc)          (GtsBBox * bb1,
						  GtsBBox * bb2,
						  gpointer data);
/**
 * GtsBBoxDistFunc:
 * @p: a #GtsPoint.
 * @bounded: an object bounded by a #GtsBBox.
 *
 * User function returning the (minimum) distance between the object
 * defined by @bounded and point @p.
 *
 * Returns: the distance between @p and @bounded.
 */
typedef gdouble (*GtsBBoxDistFunc)               (GtsPoint * p,
						  gpointer bounded);
/**
 * GtsBBoxClosestFunc:
 * @p: a #GtsPoint.
 * @bounded: an object bounded by a #GtsBBox.
 * 
 * User function returning a #GtsPoint belonging to the object defined
 * by @bounded and closest to @p.
 *
 * Returns: a #GtsPoint.
 */
typedef GtsPoint * (*GtsBBoxClosestFunc)         (GtsPoint * p,
						  gpointer bounded);

/**
 * GTS_IS_BBOX:
 * @obj: a #GtsObject.
 *
 * Evaluates to %TRUE if @obj is a #GtsBBox, %FALSE otherwise.
 */
#define GTS_IS_BBOX(obj)  (gts_object_is_from_class (obj,\
						     gts_bbox_class ()))
/**
 * GTS_BBOX:
 * @obj: a #GtsObject.
 *
 * Casts @obj to #GtsBBox.
 */
#define GTS_BBOX(obj)         GTS_OBJECT_CAST (obj,\
					       GtsBBox,\
					       gts_bbox_class ())
/**
 * GTS_BBOX_CLASS:
 * @klass: a descendant of #GtsBBoxClass.
 *
 * Casts @klass to #GtsBBoxClass.
 */
#define GTS_BBOX_CLASS(klass) GTS_OBJECT_CLASS_CAST (klass,\
						     GtsBBoxClass,\
						     gts_bbox_class ())

struct _GtsBBox {
  GtsObject object;
  gpointer bounded;
  gdouble x1, y1, z1;
  gdouble x2, y2, z2;
};

struct _GtsBBoxClass {
  GtsObjectClass parent_class;
};

GtsBBoxClass * gts_bbox_class                (void);
GtsBBox *  gts_bbox_new                      (GtsBBoxClass * klass,
					      gpointer bounded,
					      gdouble x1, 
					      gdouble y1, 
					      gdouble z1,
					      gdouble x2, 
					      gdouble y2, 
					      gdouble z2);
void       gts_bbox_set                      (GtsBBox * bbox,
					      gpointer bounded,
					      gdouble x1, 
					      gdouble y1, 
					      gdouble z1,
					      gdouble x2, 
					      gdouble y2, 
					      gdouble z2);
GtsBBox *  gts_bbox_segment                  (GtsBBoxClass * klass,
					      GtsSegment * s);
GtsBBox *  gts_bbox_triangle                 (GtsBBoxClass * klass,
					      GtsTriangle * t);
GtsBBox *  gts_bbox_surface                  (GtsBBoxClass * klass, 
					      GtsSurface * surface);
GtsBBox *  gts_bbox_bboxes                   (GtsBBoxClass * klass,
					      GSList * bboxes);
GtsBBox *  gts_bbox_points                   (GtsBBoxClass * klass,
					      GSList * points);
/**
 * gts_bbox_point_is_inside:
 * @bbox: a #GtsBBox.
 * @p: a #GtsPoint.
 *
 * Evaluates to %TRUE if @p is inside (or on the boundary) of @bbox, %FALSE otherwise.
 */
#define    gts_bbox_point_is_inside(bbox, p) ((p)->x >= (bbox)->x1 &&\
					     (p)->y >= (bbox)->y1 &&\
                                             (p)->z >= (bbox)->z1 &&\
                                             (p)->x <= (bbox)->x2 &&\
					     (p)->y <= (bbox)->y2 &&\
                                             (p)->z <= (bbox)->z2)
gboolean   gts_bboxes_are_overlapping        (GtsBBox * bb1, 
					      GtsBBox * bb2);
void       gts_bbox_draw                     (GtsBBox * bb, 
					      FILE * fptr);
gdouble    gts_bbox_diagonal2                (GtsBBox * bb);
void       gts_bbox_point_distance2          (GtsBBox * bb, 
					      GtsPoint * p,
					      gdouble * min,
					      gdouble * max);
gboolean   gts_bbox_is_stabbed               (GtsBBox * bb, 
					      GtsPoint * p);
gboolean   gts_bbox_overlaps_triangle        (GtsBBox * bb,
					      GtsTriangle * t);
gboolean   gts_bbox_overlaps_segment         (GtsBBox * bb, 
					      GtsSegment * s);

GNode *    gts_bb_tree_new                   (GSList * bboxes);
GNode *    gts_bb_tree_surface               (GtsSurface * s);
GSList *   gts_bb_tree_stabbed               (GNode * tree, 
					      GtsPoint * p);
GSList *   gts_bb_tree_overlap               (GNode * tree, 
					      GtsBBox * bbox);
gboolean   gts_bb_tree_is_overlapping        (GNode * tree, 
					      GtsBBox * bbox);
void       gts_bb_tree_traverse_overlapping  (GNode * tree1, 
					      GNode * tree2,
					      GtsBBTreeTraverseFunc func,
					      gpointer data);
void       gts_bb_tree_draw                  (GNode * tree, 
					      guint depth, 
					      FILE * fptr);
GSList *   gts_bb_tree_point_closest_bboxes  (GNode * tree, 
					      GtsPoint * p);
gdouble    gts_bb_tree_point_distance        (GNode * tree, 
					      GtsPoint * p,
					      GtsBBoxDistFunc distance,
					      GtsBBox ** bbox);
GtsPoint * gts_bb_tree_point_closest         (GNode * tree, 
					      GtsPoint * p,
					      GtsBBoxClosestFunc closest,
					      gdouble * distance);
void       gts_bb_tree_segment_distance      (GNode * tree, 
					      GtsSegment * s,
					      GtsBBoxDistFunc distance,
					      gdouble delta,
					      GtsRange * range);
void       gts_bb_tree_triangle_distance     (GNode * tree, 
					      GtsTriangle * t,
					      GtsBBoxDistFunc distance,
					      gdouble delta,
					      GtsRange * range);
void       gts_bb_tree_surface_distance      (GNode * tree,
					      GtsSurface * s,
					      GtsBBoxDistFunc distance,
					      gdouble delta,
					      GtsRange * range);
void       gts_bb_tree_surface_boundary_distance 
                                             (GNode * tree,
					      GtsSurface * s,
					      GtsBBoxDistFunc distance,
					      gdouble delta,
					      GtsRange * range);
void       gts_bb_tree_destroy               (GNode * tree, 
					      gboolean free_leaves);

/* Surfaces: surface.c */

typedef struct _GtsSurfaceStats        GtsSurfaceStats;
typedef struct _GtsSurfaceQualityStats GtsSurfaceQualityStats;
typedef GtsVertex * (*GtsRefineFunc)   (GtsEdge * e,
					GtsVertexClass * klass,
					gpointer data);
typedef GtsVertex * (*GtsCoarsenFunc)  (GtsEdge * e,
					GtsVertexClass * klass,
					gpointer data);
typedef gboolean    (*GtsStopFunc)     (gdouble cost,
					guint nedge,
					gpointer data);

struct _GtsSurfaceStats {
  guint n_faces;
  guint n_incompatible_faces;
  guint n_duplicate_faces;
  guint n_duplicate_edges;
  guint n_boundary_edges;
  guint n_non_manifold_edges;
  GtsRange edges_per_vertex, faces_per_edge;
  GtsSurface * parent;
};

struct _GtsSurfaceQualityStats {
  GtsRange face_quality;
  GtsRange face_area;
  GtsRange edge_length;
  GtsRange edge_angle;
  GtsSurface * parent;
};

struct _GtsSurface {
  GtsObject object;

#ifdef USE_SURFACE_BTREE
  GTree * faces;
#else /* not USE_SURFACE_BTREE */
  GHashTable * faces;
#endif /* not USE_SURFACE_BTREE */
  GtsFaceClass * face_class;
  GtsEdgeClass * edge_class;
  GtsVertexClass * vertex_class;
  gboolean keep_faces;
};

struct _GtsSurfaceClass {
  GtsObjectClass parent_class;

  void (* add_face)    (GtsSurface *, GtsFace *);
  void (* remove_face) (GtsSurface *, GtsFace *);
};

#define GTS_IS_SURFACE(obj) (gts_object_is_from_class (obj,\
						       gts_surface_class ()))
#define GTS_SURFACE(obj)         GTS_OBJECT_CAST (obj,\
						  GtsSurface,\
						  gts_surface_class ())
#define GTS_SURFACE_CLASS(klass) GTS_OBJECT_CLASS_CAST (klass,\
							GtsSurfaceClass,\
							gts_surface_class ())

GtsSurfaceClass * gts_surface_class        (void);
GtsSurface * gts_surface_new               (GtsSurfaceClass * klass,
					    GtsFaceClass * face_class,
					    GtsEdgeClass * edge_class,
					    GtsVertexClass * vertex_class);
void         gts_surface_add_face          (GtsSurface * s, 
					    GtsFace * f);
void         gts_surface_remove_face       (GtsSurface * s, 
					    GtsFace * f);
guint        gts_surface_read              (GtsSurface * surface,
					    GtsFile * f);
gdouble      gts_surface_area              (GtsSurface * s);
void         gts_surface_stats             (GtsSurface * s, 
					    GtsSurfaceStats * stats);
void         gts_surface_quality_stats     (GtsSurface * s, 
					    GtsSurfaceQualityStats * stats);
void         gts_surface_print_stats       (GtsSurface * s, 
					    FILE * fptr);
void         gts_surface_write             (GtsSurface * s, 
					    FILE * fptr);
void         gts_surface_write_oogl        (GtsSurface * s, 
					    FILE * fptr);
void         gts_surface_write_vtk         (GtsSurface * s, 
					    FILE * fptr);
void         gts_surface_write_oogl_boundary (GtsSurface * s, 
					      FILE * fptr);
void         gts_surface_foreach_vertex    (GtsSurface * s, 
					    GtsFunc func, 
					    gpointer data);
void         gts_surface_foreach_edge      (GtsSurface * s, 
					    GtsFunc func, 
					    gpointer data);
void         gts_surface_foreach_face      (GtsSurface * s,
					    GtsFunc func, 
					    gpointer data);
guint        gts_surface_foreach_face_remove (GtsSurface * s,
					      GtsFunc func, 
					      gpointer data);
typedef struct _GtsSurfaceTraverse GtsSurfaceTraverse;
GtsSurfaceTraverse * gts_surface_traverse_new (GtsSurface * s,
					       GtsFace * f);
GtsFace *    gts_surface_traverse_next     (GtsSurfaceTraverse * t,
					    guint * level);
void         gts_surface_traverse_destroy  (GtsSurfaceTraverse * t);
void         gts_surface_refine            (GtsSurface * surface,
					    GtsKeyFunc cost_func,
					    gpointer cost_data,
					    GtsRefineFunc refine_func,
					    gpointer refine_data,
					    GtsStopFunc stop_func,
					    gpointer stop_data);
gboolean     gts_edge_collapse_is_valid    (GtsEdge * e);
void         gts_surface_coarsen           (GtsSurface * surface,
					    GtsKeyFunc cost_func,
					    gpointer cost_data,
					    GtsCoarsenFunc coarsen_func,
					    gpointer coarsen_data,
					    GtsStopFunc stop_func,
					    gpointer stop_data,
					    gdouble minangle);
gboolean     gts_coarsen_stop_number       (gdouble cost, 
					    guint nedge, 
					    guint * min_number);
gboolean     gts_coarsen_stop_cost         (gdouble cost, 
					    guint nedge, 
					    gdouble * max_cost);
void         gts_surface_tessellate        (GtsSurface * s,
					    GtsRefineFunc refine_func,
					    gpointer refine_data);
GtsSurface * gts_surface_generate_sphere   (GtsSurface * s,
					    guint geodesation_order);
GtsSurface * gts_surface_copy              (GtsSurface * s1,
					    GtsSurface * s2);
void         gts_surface_merge             (GtsSurface * s, 
					    GtsSurface * with);
gboolean     gts_surface_is_manifold       (GtsSurface * s);
gboolean     gts_surface_is_closed         (GtsSurface * s);
gboolean     gts_surface_is_orientable     (GtsSurface * s);
gdouble      gts_surface_volume            (GtsSurface * s);
gdouble      gts_surface_center_of_mass    (GtsSurface * s,
					    GtsVector cm);
gdouble      gts_surface_center_of_area    (GtsSurface * s,
					    GtsVector cm);
guint        gts_surface_vertex_number     (GtsSurface * s);
guint        gts_surface_edge_number       (GtsSurface * s);
guint        gts_surface_face_number       (GtsSurface * s);
void         gts_surface_distance          (GtsSurface * s1, 
					    GtsSurface * s2, 
					    gdouble delta,
					    GtsRange * face_range, 
					    GtsRange * boundary_range);
GSList *     gts_surface_boundary          (GtsSurface * surface);
GSList *     gts_surface_split             (GtsSurface * s);

/* Discrete differential operators: curvature.c */

gboolean gts_vertex_mean_curvature_normal  (GtsVertex * v, 
					    GtsSurface * s, 
					    GtsVector Kh);
gboolean gts_vertex_gaussian_curvature     (GtsVertex * v, 
					    GtsSurface * s, 
					    gdouble * Kg);
void     gts_vertex_principal_curvatures   (gdouble Kh, 
					    gdouble Kg, 
					    gdouble * K1, 
					    gdouble * K2);
void     gts_vertex_principal_directions   (GtsVertex * v, 
					    GtsSurface * s, 
					    GtsVector Kh,
                                            gdouble Kg,
					    GtsVector e1, 
					    GtsVector e2);

/* Volume optimization: vopt.c */
typedef struct _GtsVolumeOptimizedParams   GtsVolumeOptimizedParams;

struct _GtsVolumeOptimizedParams {
  gdouble volume_weight;
  gdouble boundary_weight;
  gdouble shape_weight;
};

GtsVertex *  gts_volume_optimized_vertex   (GtsEdge * edge,
					    GtsVertexClass * klass,
					    GtsVolumeOptimizedParams * params);
gdouble      gts_volume_optimized_cost     (GtsEdge * e,
					    GtsVolumeOptimizedParams * params);

/* Boolean operations: boolean.c */

GSList *     gts_surface_intersection      (GtsSurface * s1,
					    GtsSurface * s2,
					    GNode * faces_tree1,
					    GNode * faces_tree2);

typedef struct _GtsSurfaceInter         GtsSurfaceInter;
typedef struct _GtsSurfaceInterClass    GtsSurfaceInterClass;
/**
 * GtsBooleanOperation:
 * @GTS_1_OUT_2: identifies the part of the first surface which lies
 * outside the second surface.
 * @GTS_1_IN_2: identifies the part of the first surface which lies
 * inside the second surface.
 * @GTS_2_OUT_1: identifies the part of the second surface which lies
 * outside the first surface.
 * @GTS_2_IN_1: identifies the part of the second surface which lies
 * inside the first surface.
 */
typedef enum { GTS_1_OUT_2, 
	       GTS_1_IN_2, 
	       GTS_2_OUT_1, 
	       GTS_2_IN_1 }             GtsBooleanOperation;

/**
 * GTS_IS_SURFACE_INTER:
 * @obj: a #GtsObject.
 *
 * Evaluates to %TRUE if @obj is a #GtsSurfaceInter, %FALSE otherwise.
 */
#define GTS_IS_SURFACE_INTER(obj) (gts_object_is_from_class (obj,\
					      gts_surface_inter_class ()))
/**
 * GTS_SURFACE_INTER:
 * @obj: a descendant of #GtsSurfaceInter.
 *
 * Casts @obj to #GtsSurfaceInter.
 */
#define GTS_SURFACE_INTER(obj)         GTS_OBJECT_CAST (obj,\
						  GtsSurfaceInter,\
						  gts_surface_inter_class ())
/**
 * GTS_SURFACE_INTER_CLASS:
 * @klass: a descendant of #GtsSurfaceInterClass.
 *
 * Casts @klass to #GtsSurfaceInterClass.
 */
#define GTS_SURFACE_INTER_CLASS(klass) GTS_OBJECT_CLASS_CAST (klass,\
						 GtsSurfaceInterClass,\
						 gts_surface_inter_class ())

struct _GtsSurfaceInter {
  GtsObject object;

  GtsSurface * s1;
  GtsSurface * s2;
  GSList * edges;
};

struct _GtsSurfaceInterClass {
  GtsObjectClass parent_class;
};

GtsSurfaceInterClass *
gts_surface_inter_class          (void);
GtsSurfaceInter *
gts_surface_inter_new            (GtsSurfaceInterClass * klass,
				  GtsSurface * s1,
				  GtsSurface * s2,
				  GNode * faces_tree1,
				  GNode * faces_tree2,
				  gboolean is_open1,
				  gboolean is_open2);
gboolean 
gts_surface_inter_check          (GtsSurfaceInter * si,
				  gboolean * closed);
void 
gts_surface_inter_boolean        (GtsSurfaceInter * si, 
				  GtsSurface * surface,
				  GtsBooleanOperation op);
gboolean gts_surface_foreach_intersecting_face (GtsSurface * s,
					    GtsBBTreeTraverseFunc func,
					    gpointer data);
GtsSurface * 
gts_surface_is_self_intersecting (GtsSurface * s);

/* Binary Heap: heap.c */

typedef struct _GtsHeap         GtsHeap;

GtsHeap *    gts_heap_new          (GCompareFunc compare_func);
void         gts_heap_insert       (GtsHeap * heap, gpointer p);
gpointer     gts_heap_remove_top   (GtsHeap * heap);
gpointer     gts_heap_top          (GtsHeap * heap);
void         gts_heap_thaw         (GtsHeap * heap);
void         gts_heap_foreach      (GtsHeap * heap, 
				    GFunc func,
				    gpointer user_data);
void         gts_heap_freeze       (GtsHeap * heap);
guint        gts_heap_size         (GtsHeap * heap);
void         gts_heap_destroy      (GtsHeap * heap);

/* Extended Binary Heap: eheap.c */

typedef struct _GtsEHeap         GtsEHeap;
typedef struct _GtsEHeapPair     GtsEHeapPair;

/**
 * _GtsEHeapPair:
 * @data: Points to the item stored in the heap.
 * @key: Value of the key for this item.
 * @pos: Private field.
 */
struct _GtsEHeapPair {
  gpointer data;
  gdouble key;
  guint pos;
};

GtsEHeap *     gts_eheap_new          (GtsKeyFunc key_func,
				       gpointer data);
GtsEHeapPair * gts_eheap_insert       (GtsEHeap * heap, 
				       gpointer p);
GtsEHeapPair * gts_eheap_insert_with_key (GtsEHeap * heap, 
					  gpointer p, 
					  gdouble key);
gpointer       gts_eheap_remove_top   (GtsEHeap * heap,
				       gdouble * key);
gpointer       gts_eheap_top          (GtsEHeap * heap, 
				       gdouble * key);
void           gts_eheap_thaw         (GtsEHeap * heap);
void           gts_eheap_foreach      (GtsEHeap * heap, 
				       GFunc func,
				       gpointer data);
gpointer       gts_eheap_remove       (GtsEHeap * heap, 
				       GtsEHeapPair * p);
void           gts_eheap_decrease_key (GtsEHeap * heap,
				       GtsEHeapPair * p,
				       gdouble new_key);
void           gts_eheap_freeze       (GtsEHeap * heap);
guint          gts_eheap_size         (GtsEHeap * heap);
void           gts_eheap_update       (GtsEHeap * heap);
gdouble        gts_eheap_key          (GtsEHeap * heap,
				       gpointer p);
void           gts_eheap_randomized   (GtsEHeap * heap, 
				       gboolean randomized);
void           gts_eheap_destroy      (GtsEHeap * heap);

/* FIFO queues: fifo.c */

typedef struct _GtsFifo GtsFifo;

GtsFifo *      gts_fifo_new           (void);
void           gts_fifo_write         (GtsFifo * fifo, 
				       FILE * fp);
void           gts_fifo_push          (GtsFifo * fifo, 
				       gpointer data);
gpointer       gts_fifo_pop           (GtsFifo * fifo);
gpointer       gts_fifo_top           (GtsFifo * fifo);
guint          gts_fifo_size          (GtsFifo * fifo);
gboolean       gts_fifo_is_empty      (GtsFifo * fifo);
void           gts_fifo_foreach       (GtsFifo * fifo, 
				       GtsFunc func, 
				       gpointer data);
void           gts_fifo_reverse       (GtsFifo * fifo);
void           gts_fifo_destroy       (GtsFifo * fifo);

/* Progressive surfaces */

/* split.c */

typedef struct _GtsSplit      GtsSplit;
typedef struct _GtsSplitClass GtsSplitClass;
typedef struct _GtsSplitCFace GtsSplitCFace;

struct _GtsSplit {
  GtsObject object;

  GtsVertex * v;
  GtsObject * v1;
  GtsObject * v2;
  GtsSplitCFace * cfaces;
  guint ncf;
};

struct _GtsSplitClass {
  GtsObjectClass parent_class;
};

#define GTS_IS_SPLIT(obj)    (gts_object_is_from_class (obj,\
							gts_split_class ()))
#define GTS_SPLIT(obj)              GTS_OBJECT_CAST (obj,\
						     GtsSplit,\
						     gts_split_class ())
#define GTS_SPLIT_CLASS(klass)      GTS_OBJECT_CLASS_CAST (klass,\
						     GtsSplitClass,\
						     gts_split_class ())
#define GTS_SPLIT_V1(vs)            (GTS_IS_SPLIT ((vs)->v1) ?\
				     GTS_SPLIT ((vs)->v1)->v :\
				     GTS_VERTEX ((vs)->v1))
#define GTS_SPLIT_V2(vs)            (GTS_IS_SPLIT ((vs)->v2) ?\
				     GTS_SPLIT ((vs)->v2)->v :\
				     GTS_VERTEX ((vs)->v2))

GtsSplitClass *  gts_split_class          (void);
GtsSplit *       gts_split_new            (GtsSplitClass * klass,
					   GtsVertex * v,
					   GtsObject * o1,
					   GtsObject * o2);
void             gts_split_collapse       (GtsSplit * vs,
					   GtsEdgeClass * klass,
					   GtsEHeap * heap);
void             gts_split_expand         (GtsSplit * vs, 
					   GtsSurface * s,
					   GtsEdgeClass * klass);
typedef gboolean (*GtsSplitTraverseFunc)  (GtsSplit * vs,
					   gpointer data);
void             gts_split_traverse       (GtsSplit * root,
					   GTraverseType        order,
					   gint                 depth,
					   GtsSplitTraverseFunc func,
					   gpointer             data);
guint            gts_split_height         (GtsSplit * root);

/* psurface.c */

typedef struct _GtsPSurface         GtsPSurface;
typedef struct _GtsPSurfaceClass    GtsPSurfaceClass;

struct _GtsPSurface {
  GtsObject object;

  GtsSurface * s;
  GPtrArray * split;
  GtsSplitClass * split_class;
  guint pos, min;

  GPtrArray * vertices;
  GPtrArray * faces;
};

struct _GtsPSurfaceClass {
  GtsObjectClass parent_class;
};

#define GTS_IS_PSURFACE(obj) (gts_object_is_from_class (obj,\
							gts_psurface_class ()))
#define GTS_PSURFACE(obj)           GTS_OBJECT_CAST (obj,\
						     GtsPSurface,\
						     gts_psurface_class ())
#define GTS_PSURFACE_CLASS(klass)     GTS_OBJECT_CLASS_CAST (klass,\
						     GtsPSurfaceClass,\
						     gts_psurface_class ())
#define GTS_PSURFACE_IS_CLOSED(ps)  (!(ps)->vertices)

GtsPSurfaceClass * gts_psurface_class         (void);
GtsPSurface * gts_psurface_new                (GtsPSurfaceClass * klass,
					       GtsSurface * surface,
					       GtsSplitClass * split_class,
					       GtsKeyFunc cost_func,
					       gpointer cost_data,
					       GtsCoarsenFunc coarsen_func,
					       gpointer coarsen_data,
					       GtsStopFunc stop_func,
					       gpointer stop_data,
					       gdouble minangle);
GtsSplit *    gts_psurface_add_vertex         (GtsPSurface * ps);
GtsSplit *    gts_psurface_remove_vertex      (GtsPSurface * ps);
guint         gts_psurface_max_vertex_number  (GtsPSurface * ps);
guint         gts_psurface_min_vertex_number  (GtsPSurface * ps);
void          gts_psurface_set_vertex_number  (GtsPSurface * ps, 
					       guint n);
guint         gts_psurface_get_vertex_number  (GtsPSurface * ps);
void          gts_psurface_write              (GtsPSurface * ps,
					       FILE * fptr);
GtsPSurface * gts_psurface_open               (GtsPSurfaceClass * klass,
					       GtsSurface * s,
					       GtsSplitClass * split_class,
					       GtsFile * f);
GtsSplit *    gts_psurface_read_vertex        (GtsPSurface * ps, 
					       GtsFile * fp);
void          gts_psurface_close              (GtsPSurface * ps);
void          gts_psurface_foreach_vertex     (GtsPSurface * ps, 
					       GtsFunc func, 
					       gpointer data);

/* hsurface.c */

typedef struct _GtsHSplit        GtsHSplit;
typedef struct _GtsHSplitClass   GtsHSplitClass;
typedef struct _GtsHSurface      GtsHSurface;
typedef struct _GtsHSurfaceClass GtsHSurfaceClass;

struct _GtsHSplit {
  GtsSplit split;

  GtsEHeapPair * index;
  GtsHSplit * parent;
  guint nchild;
};

struct _GtsHSplitClass {
  GtsSplitClass parent_class;
};

#define GTS_IS_HSPLIT(obj) (gts_object_is_from_class (obj,\
						      gts_hsplit_class ()))
#define GTS_HSPLIT(obj)           GTS_OBJECT_CAST (obj,\
						   GtsHSplit,\
						   gts_hsplit_class ())
#define GTS_HSPLIT_CLASS(klass)     GTS_OBJECT_CLASS_CAST (klass,\
						   GtsHSplitClass,\
						   gts_hsplit_class ())

GtsHSplitClass * gts_hsplit_class             (void);
GtsHSplit *   gts_hsplit_new                  (GtsHSplitClass * klass, 
					       GtsSplit * vs);
void          gts_hsplit_collapse             (GtsHSplit * hs,
					       GtsHSurface * hsurface);
void          gts_hsplit_expand               (GtsHSplit * hs,
					       GtsHSurface * hsurface);
void          gts_hsplit_force_expand         (GtsHSplit * hs,
					       GtsHSurface * hsurface);

struct _GtsHSurface {
  GtsObject object;

  GtsSurface * s;
  GSList * roots;
  GtsEHeap * expandable;
  GtsEHeap * collapsable;
  GPtrArray * split;
  guint nvertex;
};

struct _GtsHSurfaceClass {
  GtsObjectClass parent_class;
};

#define GTS_IS_HSURFACE(obj) (gts_object_is_from_class (obj,\
							gts_hsurface_class ()))
#define GTS_HSURFACE(obj)           GTS_OBJECT_CAST (obj,\
						     GtsHSurface,\
						     gts_hsurface_class ())
#define GTS_HSURFACE_CLASS(klass)   GTS_OBJECT_CLASS_CAST (klass,\
						     GtsHSurfaceClass,\
						     gts_hsurface_class ())

GtsHSurfaceClass * gts_hsurface_class    (void);
GtsHSurface * gts_hsurface_new           (GtsHSurfaceClass * klass,
					  GtsHSplitClass *   hsplit_class,
					  GtsPSurface *      psurface,
					  GtsKeyFunc         expand_key,
					  gpointer           expand_data,
					  GtsKeyFunc         collapse_key,
					  gpointer           collapse_data);
void          gts_hsurface_traverse      (GtsHSurface *        hsurface,
					  GTraverseType        order,
					  gint                 depth,
					  GtsSplitTraverseFunc func,
					  gpointer             data);
void          gts_hsurface_foreach       (GtsHSurface *        hsurface,
					  GTraverseType        order,
					  GtsFunc              func,
					  gpointer             data);
guint         gts_hsurface_height        (GtsHSurface *        hsurface);

/* Constrained Delaunay triangulation: cdt.c */

/**
 * GTS_IS_CONSTRAINT:
 * @obj: a #GtsObject.
 *
 * Evaluates to %TRUE if @obj is a #GtsConstraint, %FALSE otherwise.
 */
#define GTS_IS_CONSTRAINT(obj)      (gts_object_is_from_class (obj,\
						    gts_constraint_class ()))
/**
 * GTS_CONSTRAINT:
 * @obj: a descendant of #GtsConstraint.
 *
 * Casts @obj to #GtsConstraint.
 */
#define GTS_CONSTRAINT(obj)          GTS_OBJECT_CAST (obj,\
						  GtsConstraint,\
						  gts_constraint_class ())
/**
 * GTS_CONSTRAINT_CLASS:
 * @klass: a desscendant of #GtsConstraintClass.
 *
 * Casts @klass to #GtsConstraintClass.
 */
#define GTS_CONSTRAINT_CLASS(klass)  GTS_OBJECT_CLASS_CAST (klass,\
						  GtsConstraintClass,\
						  gts_constraint_class ())

typedef struct _GtsConstraint        GtsConstraint;
typedef struct _GtsConstraintClass   GtsConstraintClass;

GtsConstraintClass * gts_constraint_class        (void);

GtsFace *            gts_point_locate            (GtsPoint * p, 
						  GtsSurface * surface,
						  GtsFace * guess);
GtsVertex *          gts_delaunay_add_vertex_to_face (GtsSurface * surface, 
						      GtsVertex * v,
						      GtsFace * f);
GtsVertex *          gts_delaunay_add_vertex     (GtsSurface * surface, 
						  GtsVertex * v,
						  GtsFace * guess);
void                 gts_delaunay_remove_vertex  (GtsSurface * surface, 
						  GtsVertex * v);
GtsFace *            gts_delaunay_check          (GtsSurface * surface);
GSList *             gts_delaunay_add_constraint (GtsSurface * surface,
						  GtsConstraint * c);
void                 gts_delaunay_remove_hull    (GtsSurface * surface);

/* GtsListFace: Header */

typedef struct _GtsListFace         GtsListFace;

struct _GtsListFace {
  /*< private >*/
  GtsFace parent;

  /*< public >*/
  GSList * points;
};

#define GTS_LIST_FACE(obj)            GTS_OBJECT_CAST (obj,\
					         GtsListFace,\
					         gts_list_face_class ())
#define GTS_IS_LIST_FACE(obj)         (gts_object_is_from_class (obj,\
						 gts_list_face_class ()))

GtsFaceClass *       gts_list_face_class         (void);

/* Constrained Delaunay refinement: refine.c */

typedef gboolean   (* GtsEncroachFunc)           (GtsVertex * v,
						  GtsEdge * e,
						  GtsSurface * s,
						  gpointer data);

gboolean             gts_vertex_encroaches_edge  (GtsVertex * v, 
						  GtsEdge * e);
GtsVertex *          gts_edge_is_encroached      (GtsEdge * e,
						  GtsSurface * s,
						  GtsEncroachFunc encroaches,
						  gpointer data);
guint                gts_delaunay_conform        (GtsSurface * surface,
						  gint steiner_max,
						  GtsEncroachFunc encroaches,
						  gpointer data);
guint                gts_delaunay_refine         (GtsSurface * surface,
						  gint steiner_max,
						  GtsEncroachFunc encroaches,
						  gpointer encroach_data,
						  GtsKeyFunc cost,
						  gpointer cost_data);

/* Isosurfaces (marching cubes): iso.c */

typedef struct _GtsGridPlane     GtsGridPlane;
typedef struct _GtsIsoSlice      GtsIsoSlice;
typedef struct _GtsCartesianGrid GtsCartesianGrid;

struct _GtsGridPlane {
  GtsPoint ** p;
  guint nx, ny;
};

struct _GtsCartesianGrid {
  guint nx, ny, nz;
  gdouble x, dx, y, dy, z, dz;
};

typedef void (*GtsIsoCartesianFunc)         (gdouble ** a,
					     GtsCartesianGrid g,
					     guint i,
					     gpointer data);

GtsGridPlane * gts_grid_plane_new           (guint nx, 
					     guint ny);
void           gts_grid_plane_destroy       (GtsGridPlane * g);
GtsIsoSlice *  gts_iso_slice_new            (guint nx, guint ny);
void           gts_iso_slice_fill           (GtsIsoSlice * slice,
					     GtsGridPlane * plane1,
					     GtsGridPlane * plane2,
					     gdouble ** f1,
					     gdouble ** f2,
					     gdouble iso,
					     GtsVertexClass * klass);
void           gts_iso_slice_fill_cartesian (GtsIsoSlice * slice,
					     GtsCartesianGrid g,
					     gdouble ** f1,
					     gdouble ** f2,
					     gdouble iso,
					     GtsVertexClass * klass);
void           gts_iso_slice_destroy        (GtsIsoSlice * slice);
void           gts_isosurface_slice         (GtsIsoSlice * slice1,
					     GtsIsoSlice * slice2,
					     GtsSurface * surface);
void           gts_isosurface_cartesian     (GtsSurface * surface,
					     GtsCartesianGrid g,
					     GtsIsoCartesianFunc f,
					     gpointer data,
					     gdouble iso);

/* Isosurfaces (marching tetrahedra): isotetra.c */

void           gts_isosurface_tetra         (GtsSurface * surface,
					     GtsCartesianGrid g,
					     GtsIsoCartesianFunc f,
					     gpointer data,
					     gdouble iso);
void           gts_isosurface_tetra_bcl     (GtsSurface * surface,
					     GtsCartesianGrid g,
					     GtsIsoCartesianFunc f,
					     gpointer data,
					     gdouble iso);
void           gts_isosurface_tetra_bounded (GtsSurface * surface,
					     GtsCartesianGrid g,
					     GtsIsoCartesianFunc f,
					     gpointer data,
					     gdouble iso);

/* Named vertices, edges and triangles: named.c */

#define GTS_NAME_LENGTH             40

#define GTS_NVERTEX(obj)            GTS_OBJECT_CAST (obj,\
						     GtsNVertex,\
						     gts_nvertex_class ())
#define GTS_NVERTEX_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
							   GtsNVertexClass,\
							   gts_nvertex_class())
#define GTS_IS_NVERTEX(obj)         (gts_object_is_from_class (obj,\
				       gts_nvertex_class ()))

typedef struct _GtsNVertex          GtsNVertex;
typedef struct _GtsNVertexClass     GtsNVertexClass;

struct _GtsNVertex {
  GtsVertex parent;
  char name[GTS_NAME_LENGTH];
};

struct _GtsNVertexClass {
  GtsVertexClass parent_class;
};

GtsNVertexClass * gts_nvertex_class        (void);

#define GTS_NEDGE(obj)            GTS_OBJECT_CAST (obj,\
						   GtsNEdge,\
						   gts_nedge_class ())
#define GTS_NEDGE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
							 GtsNEdgeClass,\
							 gts_nedge_class())
#define GTS_IS_NEDGE(obj)         (gts_object_is_from_class (obj,\
				       gts_nedge_class ()))

typedef struct _GtsNEdge          GtsNEdge;
typedef struct _GtsNEdgeClass     GtsNEdgeClass;

struct _GtsNEdge {
  GtsEdge parent;
  char name[GTS_NAME_LENGTH];
};

struct _GtsNEdgeClass {
  GtsEdgeClass parent_class;
};

GtsNEdgeClass *   gts_nedge_class        (void);

#define GTS_NFACE(obj)            GTS_OBJECT_CAST (obj,\
						   GtsNFace,\
						   gts_nface_class ())
#define GTS_NFACE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
							 GtsNFaceClass,\
							 gts_nface_class())
#define GTS_IS_NFACE(obj)         (gts_object_is_from_class (obj,\
				       gts_nface_class ()))

typedef struct _GtsNFace          GtsNFace;
typedef struct _GtsNFaceClass     GtsNFaceClass;

struct _GtsNFace {
  GtsFace parent;
  char name[GTS_NAME_LENGTH];
};

struct _GtsNFaceClass {
  GtsFaceClass parent_class;
};

GtsNFaceClass *       gts_nface_class        (void);

/* Cluster object for out-of-core simplification: oocs.c */

#define GTS_CLUSTER(obj)            GTS_OBJECT_CAST (obj,\
					           GtsCluster,\
					           gts_cluster_class ())
#define GTS_CLUSTER_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsClusterClass,\
						         gts_cluster_class())
#define GTS_IS_CLUSTER(obj)         (gts_object_is_from_class (obj,\
						   gts_cluster_class ()))
     
typedef struct _GtsCluster         GtsCluster;
typedef struct _GtsClusterClass    GtsClusterClass;
typedef struct _GtsClusterId       GtsClusterId;

struct _GtsClusterId {
  guint x, y, z;
};

struct _GtsCluster {
  GtsObject parent;

  GtsClusterId id;
  GtsVertex * v;
  guint n;
};

struct _GtsClusterClass {
  GtsObjectClass parent_class;

  void (* add) (GtsCluster * c, GtsPoint * p, gpointer data);
  void (* update) (GtsCluster * c);
};

GtsClusterClass * gts_cluster_class                (void);
GtsCluster *      gts_cluster_new                  (GtsClusterClass * klass,
						    GtsClusterId id,
						    GtsVertexClass * vklass);
void              gts_cluster_add                  (GtsCluster * c, 
						    GtsPoint * p,
						    gpointer data);
void              gts_cluster_update               (GtsCluster * c);

/* Cluster group object for out-of-core simplification: oocs.c */

#define GTS_CLUSTER_GRID(obj)            GTS_OBJECT_CAST (obj,\
					           GtsClusterGrid,\
					           gts_cluster_grid_class ())
#define GTS_CLUSTER_GRID_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						   GtsClusterGridClass,\
						   gts_cluster_grid_class())
#define GTS_IS_CLUSTER_GRID(obj)         (gts_object_is_from_class (obj,\
						   gts_cluster_grid_class ()))
     
typedef struct _GtsClusterGrid         GtsClusterGrid;
typedef struct _GtsClusterGridClass    GtsClusterGridClass;

struct _GtsClusterGrid {
  GtsObject parent;

  GtsSurface * surface;
  GtsBBox * bbox;
  GtsVector size;

  GtsClusterClass * cluster_class;
  GHashTable * clusters;
};

struct _GtsClusterGridClass {
  GtsObjectClass parent_class;
};

GtsClusterGridClass * gts_cluster_grid_class (void);
GtsClusterGrid *      gts_cluster_grid_new   (GtsClusterGridClass * klass,
					      GtsClusterClass * cluster_class,
					      GtsSurface * s,
					      GtsBBox * bbox,
					      gdouble delta);
void           gts_cluster_grid_add_triangle (GtsClusterGrid * cluster_grid,
					      GtsPoint * p1,
					      GtsPoint * p2,
					      GtsPoint * p3,
					      gpointer data);
GtsRange       gts_cluster_grid_update       (GtsClusterGrid * cluster_grid);

/* Triangle strip generation: stripe.c */
GSList *       gts_surface_strip             (GtsSurface * s);

/* GtsContainee: container.c */

typedef struct _GtsContainee         GtsContainee;
typedef struct _GtsContaineeClass    GtsContaineeClass;
typedef struct _GtsContainer         GtsContainer;
typedef struct _GtsContainerClass    GtsContainerClass;

struct _GtsContainee {
  GtsObject object;
};

struct _GtsContaineeClass {
  GtsObjectClass parent_class;

  void     (* add_container)    (GtsContainee *, GtsContainer *);
  void     (* remove_container) (GtsContainee *, GtsContainer *);
  void     (* foreach)          (GtsContainee *, GtsFunc, gpointer);
  gboolean (* is_contained)     (GtsContainee *, GtsContainer *);
  void     (* replace)          (GtsContainee *, GtsContainee *);
};

#define GTS_CONTAINEE(obj)            GTS_OBJECT_CAST (obj,\
					           GtsContainee,\
					           gts_containee_class ())
#define GTS_CONTAINEE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsContaineeClass,\
						         gts_containee_class())
#define GTS_IS_CONTAINEE(obj)         (gts_object_is_from_class (obj,\
						   gts_containee_class ()))
     
GtsContaineeClass * gts_containee_class        (void);
GtsContainee *      gts_containee_new          (GtsContaineeClass * klass);
gboolean            gts_containee_is_contained (GtsContainee * item, 
						GtsContainer * c);
void                gts_containee_replace      (GtsContainee * item,
						GtsContainee * with);

/* GtsSListContainee: container.c */

typedef struct _GtsSListContainee         GtsSListContainee;
typedef struct _GtsSListContaineeClass    GtsSListContaineeClass;

struct _GtsSListContainee {
  GtsContainee containee;

  GSList * containers;
};

struct _GtsSListContaineeClass {
  GtsContaineeClass parent_class;
};

#define GTS_SLIST_CONTAINEE(obj)            GTS_OBJECT_CAST (obj,\
					           GtsSListContainee,\
					           gts_slist_containee_class ())
#define GTS_SLIST_CONTAINEE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsSListContaineeClass,\
						         gts_slist_containee_class())
#define GTS_IS_SLIST_CONTAINEE(obj)         (gts_object_is_from_class (obj,\
						   gts_slist_containee_class ()))
     
GtsSListContaineeClass * gts_slist_containee_class   (void);

/* GtsContainer: container.c */

struct _GtsContainer {
  GtsSListContainee object;
};

struct _GtsContainerClass {
  GtsSListContaineeClass parent_class;

  void  (* add)     (GtsContainer *, GtsContainee *);
  void  (* remove)  (GtsContainer *, GtsContainee *);
  void  (* foreach) (GtsContainer *, GtsFunc, gpointer);
  guint (* size)    (GtsContainer *);
};

#define GTS_CONTAINER(obj)            GTS_OBJECT_CAST (obj,\
					           GtsContainer,\
					           gts_container_class ())
#define GTS_CONTAINER_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsContainerClass,\
						         gts_container_class())
#define GTS_IS_CONTAINER(obj)         (gts_object_is_from_class (obj,\
						   gts_container_class ()))
     
GtsContainerClass * gts_container_class     (void);
GtsContainer *      gts_container_new       (GtsContainerClass * klass);
void                gts_container_add       (GtsContainer * c,
					     GtsContainee * item);
void                gts_container_remove    (GtsContainer * c,
					     GtsContainee * item);
void                gts_container_foreach   (GtsContainer * c,
					     GtsFunc func,
					     gpointer data);
guint               gts_container_size      (GtsContainer * c);

/* GtsHashContainer: container.c */

typedef struct _GtsHashContainer         GtsHashContainer;
typedef struct _GtsHashContainerClass    GtsHashContainerClass;

struct _GtsHashContainer {
  GtsContainer c;

  GHashTable * items;
  gboolean frozen;
};

struct _GtsHashContainerClass {
  GtsContainerClass parent_class;
};

#define GTS_HASH_CONTAINER(obj)            GTS_OBJECT_CAST (obj,\
					           GtsHashContainer,\
					           gts_hash_container_class ())
#define GTS_HASH_CONTAINER_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsHashContainerClass,\
						         gts_hash_container_class())
#define GTS_IS_HASH_CONTAINER(obj)         (gts_object_is_from_class (obj,\
						   gts_hash_container_class ()))
     
GtsHashContainerClass * gts_hash_container_class (void);

/* GtsSListContainer: container.c */

typedef struct _GtsSListContainer         GtsSListContainer;
typedef struct _GtsSListContainerClass    GtsSListContainerClass;

struct _GtsSListContainer {
  GtsContainer c;

  GSList * items;
  gboolean frozen;
};

struct _GtsSListContainerClass {
  GtsContainerClass parent_class;
};

#define GTS_SLIST_CONTAINER(obj)            GTS_OBJECT_CAST (obj,\
					           GtsSListContainer,\
					           gts_slist_container_class ())
#define GTS_SLIST_CONTAINER_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsSListContainerClass,\
						         gts_slist_container_class())
#define GTS_IS_SLIST_CONTAINER(obj)         (gts_object_is_from_class (obj,\
						   gts_slist_container_class ()))
     
GtsSListContainerClass * gts_slist_container_class (void);

/* GtsGNode: graph.c */

typedef struct _GtsGNode         GtsGNode;
typedef struct _GtsGNodeClass    GtsGNodeClass;
typedef struct _GtsGraph         GtsGraph;
typedef struct _GtsGraphClass    GtsGraphClass;

struct _GtsGNode {
  GtsSListContainer container;

  guint level;
};

struct _GtsGNodeClass {
  GtsSListContainerClass parent_class;

  gfloat (* weight) (GtsGNode *);
  void   (* write)  (GtsGNode *, FILE *);
};

#define GTS_GNODE(obj)            GTS_OBJECT_CAST (obj,\
					           GtsGNode,\
					           gts_gnode_class ())
#define GTS_GNODE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsGNodeClass,\
						         gts_gnode_class())
#define GTS_IS_GNODE(obj)         (gts_object_is_from_class (obj,\
						   gts_gnode_class ()))
#define GTS_GNODE_NEIGHBOR(n,e)   (GTS_GEDGE (e)->n1 == n ? GTS_GEDGE (e)->n2 : GTS_GEDGE (e)->n2 == n ? GTS_GEDGE (e)->n1 : NULL)
     
GtsGNodeClass * gts_gnode_class                (void);
GtsGNode *      gts_gnode_new                  (GtsGNodeClass * klass);
void            gts_gnode_foreach_neighbor     (GtsGNode * n, 
						GtsGraph * g,
						GtsFunc func,
						gpointer data);
void            gts_gnode_foreach_edge         (GtsGNode * n,
						GtsGraph * g,
						GtsFunc func,
						gpointer data);
guint           gts_gnode_degree               (GtsGNode * n,
						GtsGraph * g);
gfloat          gts_gnode_move_cost            (GtsGNode * n,
						GtsGraph * src,
						GtsGraph * dst);
gfloat          gts_gnode_weight               (GtsGNode * n);

GTS_C_VAR
gboolean        gts_allow_floating_gnodes;

/* GtsNGNode: graph.c */

typedef struct _GtsNGNode         GtsNGNode;
typedef struct _GtsNGNodeClass    GtsNGNodeClass;

struct _GtsNGNode {
  GtsGNode node;

  guint id;
};

struct _GtsNGNodeClass {
  GtsGNodeClass parent_class;
};

#define GTS_NGNODE(obj)            GTS_OBJECT_CAST (obj,\
					           GtsNGNode,\
					           gts_ngnode_class ())
#define GTS_NGNODE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsNGNodeClass,\
						         gts_ngnode_class())
#define GTS_IS_NGNODE(obj)         (gts_object_is_from_class (obj,\
						   gts_ngnode_class ()))
     
GtsNGNodeClass * gts_ngnode_class                (void);
GtsNGNode *      gts_ngnode_new                  (GtsNGNodeClass * klass,
						  guint id);

/* GtsWGNode: graph.c */

typedef struct _GtsWGNode         GtsWGNode;
typedef struct _GtsWGNodeClass    GtsWGNodeClass;

struct _GtsWGNode {
  GtsGNode node;
  
  gfloat weight;
};

struct _GtsWGNodeClass {
  GtsGNodeClass parent_class;
};

#define GTS_WGNODE(obj)            GTS_OBJECT_CAST (obj,\
					           GtsWGNode,\
					           gts_wgnode_class ())
#define GTS_WGNODE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsWGNodeClass,\
						         gts_wgnode_class())
#define GTS_IS_WGNODE(obj)         (gts_object_is_from_class (obj,\
						   gts_wgnode_class ()))
     
GtsWGNodeClass * gts_wgnode_class                (void);
GtsWGNode *      gts_wgnode_new                  (GtsWGNodeClass * klass,
						  gfloat weight);

/* GtsPNode */

typedef struct _GtsPNode         GtsPNode;
typedef struct _GtsPNodeClass    GtsPNodeClass;

struct _GtsPNode {
  GtsGNode node;

  gpointer data;
};

struct _GtsPNodeClass {
  GtsGNodeClass parent_class;
};

#define GTS_PNODE(obj)            GTS_OBJECT_CAST (obj,\
					           GtsPNode,\
					           gts_pnode_class ())
#define GTS_PNODE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsPNodeClass,\
						         gts_pnode_class())
#define GTS_IS_PNODE(obj)         (gts_object_is_from_class (obj,\
						   gts_pnode_class ()))
     
GtsPNodeClass * gts_pnode_class                (void);
GtsPNode *      gts_pnode_new                  (GtsPNodeClass * klass,
						gpointer data);

/* GtsFNode */

typedef struct _GtsFNode         GtsFNode;
typedef struct _GtsFNodeClass    GtsFNodeClass;

struct _GtsFNode {
  GtsGNode node;

  GtsFace * f;
};

struct _GtsFNodeClass {
  GtsGNodeClass parent_class;
};

#define GTS_FNODE(obj)            GTS_OBJECT_CAST (obj,\
					           GtsFNode,\
					           gts_fnode_class ())
#define GTS_FNODE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsFNodeClass,\
						         gts_fnode_class())
#define GTS_IS_FNODE(obj)         (gts_object_is_from_class (obj,\
						   gts_fnode_class ()))
     
GtsFNodeClass * gts_fnode_class                (void);
GtsFNode *      gts_fnode_new                  (GtsFNodeClass * klass,
						GtsFace * f);

/* GtsGEdge: graph.c */

typedef struct _GtsGEdge         GtsGEdge;
typedef struct _GtsGEdgeClass    GtsGEdgeClass;

struct _GtsGEdge {
  GtsContainee containee;

  GtsGNode * n1;
  GtsGNode * n2;
};

struct _GtsGEdgeClass {
  GtsContaineeClass parent_class;

  GtsGEdge * (* link)   (GtsGEdge * e, GtsGNode * n1, GtsGNode * n2);
  gfloat     (* weight) (GtsGEdge * e);
  void       (* write)  (GtsGEdge * e, FILE * fp);
};

#define GTS_GEDGE(obj)            GTS_OBJECT_CAST (obj,\
					           GtsGEdge,\
					           gts_gedge_class ())
#define GTS_GEDGE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsGEdgeClass,\
						         gts_gedge_class())
#define GTS_IS_GEDGE(obj)         (gts_object_is_from_class (obj,\
						   gts_gedge_class ()))
     
GtsGEdgeClass * gts_gedge_class                (void);
GtsGEdge *      gts_gedge_new                  (GtsGEdgeClass * klass,
						GtsGNode * n1,
						GtsGNode * n2);
gfloat          gts_gedge_weight               (GtsGEdge * e);
#define         gts_gedge_connects(e, a1, a2)\
   (((e)->n1 == a1 && (e)->n2 == a2) || ((e)->n1 == a2 && (e)->n2 == a1)) 

/* GtsPGEdge: graph.c */

typedef struct _GtsPGEdge         GtsPGEdge;
typedef struct _GtsPGEdgeClass    GtsPGEdgeClass;

struct _GtsPGEdge {
  GtsGEdge gedge;

  gpointer data;
};

struct _GtsPGEdgeClass {
  GtsGEdgeClass parent_class;
};

#define GTS_PGEDGE(obj)            GTS_OBJECT_CAST (obj,\
					           GtsPGEdge,\
					           gts_pgedge_class ())
#define GTS_PGEDGE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsPGEdgeClass,\
						         gts_pgedge_class())
#define GTS_IS_PGEDGE(obj)         (gts_object_is_from_class (obj,\
						   gts_pgedge_class ()))
     
GtsPGEdgeClass * gts_pgedge_class                (void);
GtsPGEdge *      gts_pgedge_new                  (GtsPGEdgeClass * klass,
						  GtsGNode * n1,
						  GtsGNode * n2,
						  gpointer data);

/* GtsWGEdge: graph.c */

typedef struct _GtsWGEdge         GtsWGEdge;
typedef struct _GtsWGEdgeClass    GtsWGEdgeClass;

struct _GtsWGEdge {
  GtsGEdge gedge;

  gfloat weight;
};

struct _GtsWGEdgeClass {
  GtsGEdgeClass parent_class;
};

#define GTS_WGEDGE(obj)            GTS_OBJECT_CAST (obj,\
					           GtsWGEdge,\
					           gts_wgedge_class ())
#define GTS_WGEDGE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsWGEdgeClass,\
						         gts_wgedge_class())
#define GTS_IS_WGEDGE(obj)         (gts_object_is_from_class (obj,\
						   gts_wgedge_class ()))
     
GtsWGEdgeClass * gts_wgedge_class                (void);
GtsWGEdge *      gts_wgedge_new                  (GtsWGEdgeClass * klass,
						  GtsGNode * n1,
						  GtsGNode * n2,
						  gfloat weight);

/* GtsGraph: graph.c */

struct _GtsGraph {
  GtsHashContainer object;

  GtsGraphClass * graph_class;
  GtsGNodeClass * node_class;
  GtsGEdgeClass * edge_class;
};

struct _GtsGraphClass {
  GtsHashContainerClass parent_class;

  gfloat (* weight) (GtsGraph *);
};

#define GTS_GRAPH(obj)            GTS_OBJECT_CAST (obj,\
					           GtsGraph,\
					           gts_graph_class ())
#define GTS_GRAPH_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsGraphClass,\
						         gts_graph_class())
#define GTS_IS_GRAPH(obj)         (gts_object_is_from_class (obj,\
						   gts_graph_class ()))
     
GtsGraphClass * gts_graph_class                  (void);
GtsGraph *      gts_graph_new                    (GtsGraphClass * klass,
						  GtsGNodeClass * node_class,
						  GtsGEdgeClass * edge_class);
void            gts_graph_print_stats            (GtsGraph * g,
						  FILE * fp);
typedef struct _GtsGraphTraverse GtsGraphTraverse;
typedef enum   { GTS_BREADTH_FIRST
               }   GtsTraverseType;
GtsGraphTraverse * gts_graph_traverse_new        (GtsGraph * g, 
						  GtsGNode * n,
						  GtsTraverseType type,
						  gboolean reinit);
GtsGNode *         gts_graph_traverse_next       (GtsGraphTraverse * t);
GtsGNode *         gts_graph_traverse_what_next  (GtsGraphTraverse * t);
void               gts_graph_traverse_destroy    (GtsGraphTraverse * t);
void               gts_graph_foreach_edge        (GtsGraph * g,
						  GtsFunc func,
						  gpointer data);
gfloat             gts_graph_weight              (GtsGraph * g);
guint              gts_graph_distance_sum        (GtsGraph * g, 
						  GtsGNode * center);
GtsGNode *         gts_graph_farthest            (GtsGraph * g, 
						  GSList * gnodes);
guint              gts_graph_edges_cut           (GtsGraph * g);
gfloat             gts_graph_edges_cut_weight    (GtsGraph * g);
void               gts_graph_write               (GtsGraph * g, 
						  FILE * fp);
void               gts_graph_write_dot           (GtsGraph * g, 
						  FILE * fp);
GtsGraph *         gts_graph_read                (GtsFile * fp);
guint              gts_graph_read_jostle         (GtsGraph * g, 
						  GtsFile * fp);

/* GtsWGraph: graph.c */

typedef struct _GtsWGraph      GtsWGraph;
typedef struct _GtsWGraphClass GtsWGraphClass;

struct _GtsWGraph {
  GtsGraph graph;

  gfloat weight;
};

struct _GtsWGraphClass {
  GtsGraphClass parent_class;
};

#define GTS_WGRAPH(obj)            GTS_OBJECT_CAST (obj,\
					           GtsWGraph,\
					           gts_wgraph_class ())
#define GTS_WGRAPH_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsWGraphClass,\
						         gts_wgraph_class())
#define GTS_IS_WGRAPH(obj)         (gts_object_is_from_class (obj,\
						   gts_wgraph_class ()))
     
GtsWGraphClass * gts_wgraph_class                (void);
gfloat           gts_wgraph_weight_max           (GtsWGraph * wg);

/* Surface graph: graph.c */

GtsGraph *       gts_surface_graph_new           (GtsGraphClass * klass,
						  GtsSurface * s);
GtsSurface *     gts_surface_graph_surface       (GtsGraph * surface_graph,
						  GtsSurface * s);

/* Segments graph: graph.c */

GtsGraph *       gts_segments_graph_new          (GtsGraphClass * klass,
						  GSList * segments);

/* GtsGNodeSplit: pgraph.c */

typedef struct _GtsGNodeSplit         GtsGNodeSplit;
typedef struct _GtsGNodeSplitClass    GtsGNodeSplitClass;

struct _GtsGNodeSplit {
  GtsObject object;

  GtsGNode * n;
  GtsObject * n1;
  GtsObject * n2;
};

struct _GtsGNodeSplitClass {
  GtsObjectClass parent_class;
};

#define GTS_GNODE_SPLIT(obj)            GTS_OBJECT_CAST (obj,\
					           GtsGNodeSplit,\
					           gts_gnode_split_class ())
#define GTS_GNODE_SPLIT_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsGNodeSplitClass,\
						         gts_gnode_split_class())
#define GTS_IS_GNODE_SPLIT(obj)         (gts_object_is_from_class (obj,\
						   gts_gnode_split_class ()))
#define GTS_GNODE_SPLIT_N1(ns) (GTS_IS_GNODE_SPLIT ((ns)->n1) ? GTS_GNODE_SPLIT ((ns)->n1)->n : GTS_GNODE ((ns)->n1))
#define GTS_GNODE_SPLIT_N2(ns) (GTS_IS_GNODE_SPLIT ((ns)->n2) ? GTS_GNODE_SPLIT ((ns)->n2)->n : GTS_GNODE ((ns)->n2))
     
GtsGNodeSplitClass * gts_gnode_split_class    (void);
GtsGNodeSplit *      gts_gnode_split_new      (GtsGNodeSplitClass * klass,
					       GtsGNode * n,
					       GtsObject * n1,
					       GtsObject * n2);
void                 gts_gnode_split_collapse (GtsGNodeSplit * ns,
					       GtsGraph * g,
					       GtsWGEdgeClass * klass);
void                 gts_gnode_split_expand   (GtsGNodeSplit * ns,
					       GtsGraph * g);

/* GtsPGraph: pgraph.c */

typedef struct _GtsPGraph         GtsPGraph;
typedef struct _GtsPGraphClass    GtsPGraphClass;

struct _GtsPGraph {
  GtsObject object;

  GtsGraph * g;
  GPtrArray * split;
  GArray * levels;
  GtsGNodeSplitClass * split_class;
  GtsWGEdgeClass * edge_class;
  guint pos, min, level;
};

struct _GtsPGraphClass {
  GtsObjectClass parent_class;
};

#define GTS_PGRAPH(obj)            GTS_OBJECT_CAST (obj,\
					           GtsPGraph,\
					           gts_pgraph_class ())
#define GTS_PGRAPH_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
						         GtsPGraphClass,\
						         gts_pgraph_class())
#define GTS_IS_PGRAPH(obj)         (gts_object_is_from_class (obj,\
						   gts_pgraph_class ()))
     
GtsPGraphClass * gts_pgraph_class            (void);
GtsPGraph *      gts_pgraph_new              (GtsPGraphClass * klass,
					      GtsGraph * g,
					      GtsGNodeSplitClass * split_class,
					      GtsWGNodeClass * node_class,
					      GtsWGEdgeClass * edge_class,
					      guint min);
GtsGNodeSplit *  gts_pgraph_add_node         (GtsPGraph * pg);
GtsGNodeSplit *  gts_pgraph_remove_node      (GtsPGraph * pg);
void             gts_pgraph_set_node_number  (GtsPGraph *pg,
					      guint n);
guint            gts_pgraph_get_node_number  (GtsPGraph *pg);
guint            gts_pgraph_min_node_number  (GtsPGraph *pg);
guint            gts_pgraph_max_node_number  (GtsPGraph *pg);
void             gts_pgraph_foreach_node     (GtsPGraph *pg,
					      GtsFunc func,
					      gpointer data);
gboolean         gts_pgraph_down             (GtsPGraph * pg,
					      GtsFunc func,
					      gpointer data);
/* Graph partition: partition.c */

GSList *         gts_graph_bubble_partition           (GtsGraph * g, 
						       guint np, 
						       guint niter,
						       GtsFunc step_info,
						       gpointer data);
guint            gts_graph_partition_edges_cut        (GSList * partition);
gfloat           gts_graph_partition_edges_cut_weight (GSList * partition);
void             gts_graph_partition_print_stats      (GSList * partition,
						       FILE * fp);
gfloat           gts_graph_partition_balance          (GSList * partition);
GSList *         gts_graph_partition_clone            (GSList * partition);
GSList *         gts_graph_recursive_bisection        (GtsWGraph * wg,
						       guint n,
						       guint ntry,
						       guint mmax,
						       guint nmin,
						       gfloat imbalance);
void             gts_graph_partition_destroy          (GSList * partition);

/* Graph bisection: partition.c */

typedef struct _GtsGraphBisection GtsGraphBisection;

struct _GtsGraphBisection {
  GtsGraph * g;
  GtsGraph * g1;
  GtsGraph * g2;
  GHashTable * bg1;
  GHashTable * bg2;
};

gboolean            gts_graph_bisection_check      (GtsGraphBisection * bg);
GtsGraphBisection * gts_graph_ggg_bisection        (GtsGraph * g, 
						    guint ntry);
GtsGraphBisection * gts_graph_bfgg_bisection       (GtsGraph * g, 
						    guint ntry);
gdouble             gts_graph_bisection_kl_refine  (GtsGraphBisection * bg,
						    guint mmax);
gdouble             gts_graph_bisection_bkl_refine (GtsGraphBisection * bg,
						    guint mmax,
						    gfloat imbalance);
GtsGraphBisection * gts_graph_bisection_new        (GtsWGraph * wg,
						    guint ntry,
						    guint mmax,
						    guint nmin,
						    gfloat imbalance);
void                gts_graph_bisection_destroy    (GtsGraphBisection * bg,
						    gboolean destroy_graphs);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __GTS_H__ */