tg-sys 0.1.1

unsafe low-level bindings to the `tg` geometry library
Documentation
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
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
<!--- AUTOMATICALLY GENERATED: DO NOT EDIT --->

# TG C API

C API for the TG geometry library.

This document provides a detailed description of the functions and types in the
[tg.h](../tg.h) and [tg.c](../tg.c) source files for the TG library.

For a more general overview please see the project 
[README](https://github.com/tidwall/tg). 

## Table of contents

- [Programing notes]#programing-notes
- [Structs]#structs
- [Objects]#objects
- [Enums]#enums
- [Geometry constructors]#geometry-constructors
- [Geometry accessors]#geometry-accessors
- [Geometry predicates]#geometry-predicates
- [Geometry parsing]#geometry-predicates
- [Geometry writing]#geometry-writing
- [Geometry with alternative dimensions]#geometry-with-alternative-dimensions
- [Point functions]#point-functions
- [Segment functions]#segment-functions
- [Rectangle functions]#rectangle-functions
- [Ring functions]#ring-functions
- [Line functions]#line-functions
- [Polygon functions]#polygon-functions
- [Global environment]#global-environment

## Programing notes

#### Pure functions

TG library functions are thread-safe, reentrant, and (mostly) without side
effects.
The exception being with the use of malloc by some functions like
[geometry constructors](#geometry-constructors).
In those cases, it's the programmer's responsibiilty to check the return value
before continuing.

```c
struct tg_geom *geom = tg_geom_new_point(-112, 33);
if (!geom) {
    // System is out of memory.
}
```

#### Fast cloning

The cloning of geometries, as with [tg_geom_clone()](#tg_geom_clone), are
O(1) operations that use implicit sharing through an atomic reference counter.
Geometry constructors like [tg_geom_new_polygon()](#tg_geom_new_polygon) will
use this method under the hood to maintain references of its inputs.

While this may only be an implementation detail, it's important for the
programmer to understand how TG uses memory and object references.

For example:

```c
struct tg_geom *geom = tg_geom_new_polygon(exterior, holes, nholes);
```

Above, a new geometry "geom" was created and includes a cloned reference to the 
[tg_ring](#tg_ring) "exterior" and all of the holes.

Providing `TG_NOATOMICS` to the compiler will disable the use of atomics and 
instead use non-atomic reference counters.

```
cc -DTG_NOATOMICS tg.c ...
```

Alternatively, the [tg_geom_copy()](#tg_geom_copy) method is available to perform a deep copy of the
geometry.

#### Avoid memory leaks

To avoid memory leaks, call [tg_geom_free()](#tg_geom_free) on geometries
created from [geometry constructors](#geometry-constructors), 
[geometry parsers](#geometry-parsing), [tg_geom_clone()](#tg_geom_clone), and [tg_geom_copy()](#tg_geom_copy).

In other words, for every `tg_geom_new_*()`, `tg_geom_parse_*()`, 
`tg_geom_clone()`, and `tg_geom_copy()` there should be (eventually and exactly)
one `tg_geom_free()`.

#### Upcasting

The TG object types [tg_line](#tg_line), [tg_ring](#tg_ring), and 
[tg_poly](#tg_poly) can be safely upcasted to a [tg_geom](#tg_geom) with no
cost at runtime.

```c
struct tg_geom *geom1 = (struct tg_geom*)line; // Cast tg_line to tg_geom
struct tg_geom *geom2 = (struct tg_geom*)ring; // Cast tg_ring to tg_geom
struct tg_geom *geom3 = (struct tg_geom*)poly; // Cast tg_poly to tg_geom
```

This allows for exposing all [tg_geom](#tg_geom) functions to the other
object types.

In addition, the [tg_ring](#tg_ring) type can also cast to a
[tg_poly](#tg_poly).

```c
struct tg_poly *poly = (struct tg_poly*)ring; // Cast tg_ring to tg_poly
```

*Do not downcast. It's not generally safe to cast from a tg_geom to other
types.*
## Structs

- [tg_point]#structtg__point
- [tg_segment]#structtg__segment
- [tg_rect]#structtg__rect
## Objects

- [tg_ring]#structtg__ring
- [tg_line]#structtg__line
- [tg_poly]#structtg__poly
- [tg_geom]#structtg__geom
## Enums

- [tg_geom_type]#tg_8h_1a041ea24bc56bb85748f965415a3bd864
- [tg_index]#tg_8h_1a0dab409fed835315465fcb47a9a926c7


<a name='group___geometry_constructors'></a>
## Geometry constructors

Functions for creating and freeing geometries. 



- [tg_geom_new_point()]#group___geometry_constructors_1ga5ed750d9db318f6677f85b53e5b2ab2c
- [tg_geom_new_linestring()]#group___geometry_constructors_1ga2f22a237852eee8821cdf2db95b3c094
- [tg_geom_new_polygon()]#group___geometry_constructors_1gac6d59362c7ec1971eca36b0ee4089409
- [tg_geom_new_multipoint()]#group___geometry_constructors_1ga52fc0309986b70f9bb0622c65f801f92
- [tg_geom_new_multilinestring()]#group___geometry_constructors_1gaccfd80de48f1e5c7de38cbf515d3bf9f
- [tg_geom_new_multipolygon()]#group___geometry_constructors_1gad57b01099788e21a5103cd8293f4e364
- [tg_geom_new_geometrycollection()]#group___geometry_constructors_1ga39569ef55606b8d54ed7cf14a4382bdd
- [tg_geom_clone()]#group___geometry_constructors_1ga76f55846aa97188b1840b9ad07dae000
- [tg_geom_copy()]#group___geometry_constructors_1ga389a890d60908d3e2b448a0e2b3d558e
- [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae


<a name='group___geometry_accessors'></a>
## Geometry accessors

Functions for accessing various information about geometries, such as getting the geometry type or extracting underlying components or coordinates. 



- [tg_geom_typeof()]#group___geometry_accessors_1ga7a2e146938fab50268b7798cb3bc91cc
- [tg_geom_type_string()]#group___geometry_accessors_1ga0435b45df2158200f3b527d1adb11a62
- [tg_geom_rect()]#group___geometry_accessors_1ga68d67f900b847ae08e6515a620f4f657
- [tg_geom_is_feature()]#group___geometry_accessors_1ga9bb37a84e3d0f67433309ff1ac3c6be3
- [tg_geom_is_featurecollection()]#group___geometry_accessors_1gadd8c3b4c29006264c9716fc7b5ebb212
- [tg_geom_point()]#group___geometry_accessors_1gad8c95d22a1f5900ddc22564575ba687b
- [tg_geom_line()]#group___geometry_accessors_1ga36d293b2d81c81785fe72c84ff73f861
- [tg_geom_poly()]#group___geometry_accessors_1ga37415d625c521abbe95ef799b2fd3809
- [tg_geom_num_points()]#group___geometry_accessors_1gaeb827e40d40c8160973a5cfb880580df
- [tg_geom_point_at()]#group___geometry_accessors_1ga4f43a8071ffe50ad5dafef4683a48414
- [tg_geom_num_lines()]#group___geometry_accessors_1gab4081f22ed68c0364a32b8ece9bfd49f
- [tg_geom_line_at()]#group___geometry_accessors_1gadfc1eecd7d86b2922e96502b6bdebc16
- [tg_geom_num_polys()]#group___geometry_accessors_1ga6eb2bf473b2672dd5ff00731e358e33e
- [tg_geom_poly_at()]#group___geometry_accessors_1gae87b48f5a0e34bd5f1c477aea4027508
- [tg_geom_num_geometries()]#group___geometry_accessors_1ga9012c39360345e8e662ac36137165d14
- [tg_geom_geometry_at()]#group___geometry_accessors_1ga55f13f898c2236e065e30f3313d48f38
- [tg_geom_extra_json()]#group___geometry_accessors_1ga91a2927f57c59c0dbe9a9be89e4c93dd
- [tg_geom_is_empty()]#group___geometry_accessors_1ga7fc477dff52783a69f2a876ca05b8183
- [tg_geom_dims()]#group___geometry_accessors_1ga32f2c81b2638a85e5209fc093703b847
- [tg_geom_has_z()]#group___geometry_accessors_1ga50731d93f23947df28bd12ef36f4fce2
- [tg_geom_has_m()]#group___geometry_accessors_1ga0eb6e450280ba90eeed711c49f7b3cd0
- [tg_geom_z()]#group___geometry_accessors_1ga706dd7e2dd524ea74f1ce258e133e112
- [tg_geom_m()]#group___geometry_accessors_1ga4a9e6147ff09959e232106de59ee3feb
- [tg_geom_extra_coords()]#group___geometry_accessors_1gac5115d2642b03552856865dad33dd494
- [tg_geom_num_extra_coords()]#group___geometry_accessors_1ga5f85cf4c143703ee227e3c35accbde8b
- [tg_geom_memsize()]#group___geometry_accessors_1ga4931914f5170cce2949cfdd79e34ef63
- [tg_geom_search()]#group___geometry_accessors_1gad18cdb2a4ab1fa711dce821a0868ecd2


<a name='group___geometry_predicates'></a>
## Geometry predicates

Functions for testing the spatial relations of two geometries. 



- [tg_geom_equals()]#group___geometry_predicates_1ga87876bf188ea21a55900b497bad436f0
- [tg_geom_intersects()]#group___geometry_predicates_1gacd094b340fcc39ae01f7e0493bc5f096
- [tg_geom_disjoint()]#group___geometry_predicates_1ga852863a931d4acb87d26fb7688587804
- [tg_geom_contains()]#group___geometry_predicates_1gac0edb8e95808d07ac21b1d17cfdd2544
- [tg_geom_within()]#group___geometry_predicates_1gab4018711f7e427767e4fb9fd58e3afab
- [tg_geom_covers()]#group___geometry_predicates_1gab50d4126fbefb891fdc387bcfab0b7bb
- [tg_geom_coveredby()]#group___geometry_predicates_1gabffa9e68db9c9708ad334a4ecd055d0b
- [tg_geom_touches()]#group___geometry_predicates_1gabc5c6a541f4e553b70432c33128296a4
- [tg_geom_intersects_rect()]#group___geometry_predicates_1ga9e21b39dd7fdf8338b221ef18dc7dbe6
- [tg_geom_intersects_xy()]#group___geometry_predicates_1ga5e059ff81a10aab64ec6b5f9af6d5bcf


<a name='group___geometry_parsing'></a>
## Geometry parsing

Functions for parsing geometries from external data representations. It's recommended to use [tg_geom_error()](#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e) after parsing to check for errors. 



- [tg_parse_geojson()]#group___geometry_parsing_1ga42ba8cac8e7f7d0b31c7d5eab63da8b4
- [tg_parse_geojsonn()]#group___geometry_parsing_1ga45f669345bccec7184f8a127ada71067
- [tg_parse_geojson_ix()]#group___geometry_parsing_1gab78f1bd7fede29ebb2ecb9895d1c6bdf
- [tg_parse_geojsonn_ix()]#group___geometry_parsing_1ga3b11ffa6b82d29245e673d096ac964db
- [tg_parse_wkt()]#group___geometry_parsing_1ga5abcaa01d5b5e14ea017ff9dd5bd426c
- [tg_parse_wktn()]#group___geometry_parsing_1gaae7cb710cdb42db02b398760acd37f84
- [tg_parse_wkt_ix()]#group___geometry_parsing_1ga0444fdcf8fb4cb754b4a2c1e07f899e5
- [tg_parse_wktn_ix()]#group___geometry_parsing_1gadf71b642030b63dc399bd2f213a76ed8
- [tg_parse_wkb()]#group___geometry_parsing_1ga6929035c4b0e606ef84537272d1ece30
- [tg_parse_wkb_ix()]#group___geometry_parsing_1gae7c77d7de79d8f8023bff15f6ad2b7ae
- [tg_parse_hex()]#group___geometry_parsing_1ga0fc4fd8cb076a78c44df07c517281f67
- [tg_parse_hexn()]#group___geometry_parsing_1ga2beb47ee201ddbd1a9a7a43c938c4396
- [tg_parse_hex_ix()]#group___geometry_parsing_1ga8718e134723418426e5df2b13acdf0c1
- [tg_parse_hexn_ix()]#group___geometry_parsing_1ga3d1f9eb85ff97812fed7cf7bf9e14bd4
- [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e


<a name='group___geometry_writing'></a>
## Geometry writing

Functions for writing geometries as external data representations. 



- [tg_geom_geojson()]#group___geometry_writing_1gae4669b8ee598a46e7f4c5a11e645fe8f
- [tg_geom_wkt()]#group___geometry_writing_1ga047599bbe51886a6c3fbe35a6372d5d6
- [tg_geom_wkb()]#group___geometry_writing_1gac0938697f9270d1924c6746af68dd693
- [tg_geom_hex()]#group___geometry_writing_1ga269f61715302d48f144ffaf46e8c397b


<a name='group___geometry_constructors_ex'></a>
## Geometry with alternative dimensions

Functions for working with geometries that have more than two dimensions or are empty. The extra dimensional coordinates contained within these geometries are only carried along and serve no other purpose than to be available for when it's desired to export to an output representation such as GeoJSON, WKT, or WKB. 



- [tg_geom_new_point_z()]#group___geometry_constructors_ex_1ga1f4b592d4005fea6b9b49b35b0c15e74
- [tg_geom_new_point_m()]#group___geometry_constructors_ex_1ga68013f90e62307ef0245e8e3398eeda6
- [tg_geom_new_point_zm()]#group___geometry_constructors_ex_1ga74f8f3f07973ec99af27950735d8bb30
- [tg_geom_new_point_empty()]#group___geometry_constructors_ex_1ga64d9a692f5f8d7d5ba37fd0b5abdb9a3
- [tg_geom_new_linestring_z()]#group___geometry_constructors_ex_1ga5b16e072effa305db633265277852a97
- [tg_geom_new_linestring_m()]#group___geometry_constructors_ex_1ga1141d62a61f6aef6342e02bf930123c0
- [tg_geom_new_linestring_zm()]#group___geometry_constructors_ex_1gaf7f088fd78eb1340fd91a46f4225d234
- [tg_geom_new_linestring_empty()]#group___geometry_constructors_ex_1gadbd7a00e18648a3430bf89118448db58
- [tg_geom_new_polygon_z()]#group___geometry_constructors_ex_1gac81514f9acbafce335d8982233772664
- [tg_geom_new_polygon_m()]#group___geometry_constructors_ex_1gaf8a608082f6310107d029f25be660991
- [tg_geom_new_polygon_zm()]#group___geometry_constructors_ex_1ga5b2cbc15b3780925a1cfa05da25e0285
- [tg_geom_new_polygon_empty()]#group___geometry_constructors_ex_1ga72b1cb66d57ec21a4aef558cd64b647e
- [tg_geom_new_multipoint_z()]#group___geometry_constructors_ex_1gad7609eb5456dfb084ee7d2ab0637db82
- [tg_geom_new_multipoint_m()]#group___geometry_constructors_ex_1gaae2123bcb6b30a5efeae422ac4a4aec6
- [tg_geom_new_multipoint_zm()]#group___geometry_constructors_ex_1ga772ab89b63583177d537615f1bd2adb5
- [tg_geom_new_multipoint_empty()]#group___geometry_constructors_ex_1ga967114d5e9332630c7f99ac6a116991d
- [tg_geom_new_multilinestring_z()]#group___geometry_constructors_ex_1ga9a855e4d8aeb386b3fcdf2f35da4bb53
- [tg_geom_new_multilinestring_m()]#group___geometry_constructors_ex_1gad53b72d80be834a14a9a47d0953f08c3
- [tg_geom_new_multilinestring_zm()]#group___geometry_constructors_ex_1ga5ff87656da4c72c947cef312acb50ef1
- [tg_geom_new_multilinestring_empty()]#group___geometry_constructors_ex_1ga2798822f3fdb20132a6cc6ad2247fae4
- [tg_geom_new_multipolygon_z()]#group___geometry_constructors_ex_1ga46c67962e6d151e46cc961a76e90941c
- [tg_geom_new_multipolygon_m()]#group___geometry_constructors_ex_1ga824ac7a05f0cc5e4a74d9335f23954a0
- [tg_geom_new_multipolygon_zm()]#group___geometry_constructors_ex_1ga998ef169fc03e82c75fe32757b057334
- [tg_geom_new_multipolygon_empty()]#group___geometry_constructors_ex_1ga48684027f9beb519c52575bf6754a6f8
- [tg_geom_new_geometrycollection_empty()]#group___geometry_constructors_ex_1ga15fc542f3f6b4bb4dc7e91d554e0dfff


<a name='group___point_funcs'></a>
## Point functions

Functions for working directly with the [tg_point](#structtg__point) type. 



- [tg_point_rect()]#group___point_funcs_1ga07ff1afb45368e2f511da5cb8e689943
- [tg_point_intersects_rect()]#group___point_funcs_1ga59e99021c916a5fe7a350aee695ef6d3


<a name='group___segment_funcs'></a>
## Segment functions

Functions for working directly with the [tg_segment](#structtg__segment) type. 



- [tg_segment_rect()]#group___segment_funcs_1ga8218b7694fe5079da6ce0a241991cf78
- [tg_segment_intersects_segment()]#group___segment_funcs_1ga12b1ec6c72d4120391daff364d5c7b9b


<a name='group___rect_funcs'></a>
## Rectangle functions

Functions for working directly with the [tg_rect](#structtg__rect) type. 



- [tg_rect_expand()]#group___rect_funcs_1gadc227cfc279d612269a142841d736c79
- [tg_rect_expand_point()]#group___rect_funcs_1gaad0df238f6f430d9cc6fd6b0c6807931
- [tg_rect_center()]#group___rect_funcs_1ga44be4970fbbbdfa9e2ceb338a938d262
- [tg_rect_intersects_rect()]#group___rect_funcs_1ga910f2b37e7c7b17f9c01bbddee871b11
- [tg_rect_intersects_point()]#group___rect_funcs_1gac4d6e61cc5260ed913c736fd71defe05


<a name='group___ring_funcs'></a>
## Ring functions

Functions for working directly with the [tg_ring](#structtg__ring) type.

There are no direct spatial predicates for [tg_ring](#structtg__ring). If you want to perform operations like "intersects" or "covers" then you must upcast the ring to a [tg_geom](#structtg__geom), like such:

```c
tg_geom_interects((struct tg_geom*)ring, geom);
```
 



- [tg_ring_new()]#group___ring_funcs_1ga7defe1b6d43be8285a73f7977b342661
- [tg_ring_new_ix()]#group___ring_funcs_1ga9a154a6a8dc4beaf7758ef39b21c1ce8
- [tg_ring_free()]#group___ring_funcs_1ga51e9d824d50f67f89981f0edc7fe0cc5
- [tg_ring_clone()]#group___ring_funcs_1gafda24e3f1274ae1f1421934722cfd67b
- [tg_ring_copy()]#group___ring_funcs_1gaaa7b50bc974357abe9d67ec8d6ca0d91
- [tg_ring_memsize()]#group___ring_funcs_1ga0f146af1880d1ed7d02bfbdd0298feac
- [tg_ring_rect()]#group___ring_funcs_1ga64086c935039b1f0fcd8633be763427d
- [tg_ring_num_points()]#group___ring_funcs_1ga2437033fd4a6d67a54ce2cf1f771b66c
- [tg_ring_point_at()]#group___ring_funcs_1gad2450a013edd99a013dbaee437fb0c3d
- [tg_ring_points()]#group___ring_funcs_1gaf97a197de54c13d01aa9d983115a336d
- [tg_ring_num_segments()]#group___ring_funcs_1ga56dcd7ca3d210696979c3c6c62d71690
- [tg_ring_segment_at()]#group___ring_funcs_1ga52b3ba9138aee4245fca05bedd00801d
- [tg_ring_convex()]#group___ring_funcs_1ga2559c1e9f0a3b48d97b36010ac424703
- [tg_ring_clockwise()]#group___ring_funcs_1gae677767bd4bc40480f0a703e78f2e713
- [tg_ring_index_spread()]#group___ring_funcs_1gacecc3997e0cabb5532946acffee834f0
- [tg_ring_index_num_levels()]#group___ring_funcs_1ga1bbaf39cc96d727f253c0f66c0ede4e4
- [tg_ring_index_level_num_rects()]#group___ring_funcs_1ga292a911cdb05f7dbc19bcbd031226deb
- [tg_ring_index_level_rect()]#group___ring_funcs_1ga7eab00bc99a6f4148d2e6ced95ff24c3
- [tg_ring_nearest_segment()]#group___ring_funcs_1ga716e10054b4bda84efb259d57aff5015
- [tg_ring_line_search()]#group___ring_funcs_1gabee40f4a66c2ebb4516a9f980ff5d998
- [tg_ring_ring_search()]#group___ring_funcs_1gacd2c483213d8110c9373e8e47bd9f49e
- [tg_ring_area()]#group___ring_funcs_1gabe14408b3ad596ed14b4ce698c2e7826
- [tg_ring_perimeter()]#group___ring_funcs_1ga0d063ecfef895e21f6d7520db05d302e


<a name='group___line_funcs'></a>
## Line functions

Functions for working directly with the [tg_line](#structtg__line) type.

There are no direct spatial predicates for [tg_line](#structtg__line). If you want to perform operations like "intersects" or "covers" then you must upcast the line to a [tg_geom](#structtg__geom), like such:

```c
tg_geom_interects((struct tg_geom*)line, geom);
```
 



- [tg_line_new()]#group___line_funcs_1ga7f834a7213c8d87d8b7c7117bdf8bf63
- [tg_line_new_ix()]#group___line_funcs_1ga4057ac4ba72aa24985d947fa0ba42c19
- [tg_line_free()]#group___line_funcs_1ga13b2a0ed2014525d613c25c9232affd7
- [tg_line_clone()]#group___line_funcs_1gac7cbf109cca2dffba781a47932e1411d
- [tg_line_copy()]#group___line_funcs_1ga3a5d0aac59658eb2cfd8cdaea8ebf22f
- [tg_line_memsize()]#group___line_funcs_1ga6c2476d9dd302a3dea68aa44e7241ab1
- [tg_line_rect()]#group___line_funcs_1ga2e59f4517937e89ae69ac6c1f12bf797
- [tg_line_num_points()]#group___line_funcs_1gab4483ad3c5418dd9674b1f03498d18e6
- [tg_line_points()]#group___line_funcs_1ga45a892019af11582b2761301526519d9
- [tg_line_point_at()]#group___line_funcs_1ga44955f7b0ee3bd13a33b24aeca01651a
- [tg_line_num_segments()]#group___line_funcs_1gadb56b68cc4ce05cfa832e82e45995687
- [tg_line_segment_at()]#group___line_funcs_1gad0c0982aff76d943f0ce50deb0f9183d
- [tg_line_clockwise()]#group___line_funcs_1gaee0fcc56c7518fa81ebb3457d795ca49
- [tg_line_index_spread()]#group___line_funcs_1ga8b851e64231b8b30f30a936cf35cde08
- [tg_line_index_num_levels()]#group___line_funcs_1ga0cbcfec6e6ab81f31a47cd542e32b778
- [tg_line_index_level_num_rects()]#group___line_funcs_1gab9d4afd57889a11179df01c1df26488b
- [tg_line_index_level_rect()]#group___line_funcs_1gacc18e4ddb48ccc717f61f298fd6ae970
- [tg_line_nearest_segment()]#group___line_funcs_1gaa85835e9619ba7d8557fda3335a0353a
- [tg_line_line_search()]#group___line_funcs_1gafef8ca6e5381e93d4c4952343597c0e1
- [tg_line_length()]#group___line_funcs_1ga994796f0088c82bb0672d84f1a1ce9d1


<a name='group___poly_funcs'></a>
## Polygon functions

Functions for working directly with the [tg_poly](#structtg__poly) type.

There are no direct spatial predicates for [tg_poly](#structtg__poly). If you want to perform operations like "intersects" or "covers" then you must upcast the poly to a [tg_geom](#structtg__geom), like such:

```c
tg_geom_interects((struct tg_geom*)poly, geom);
```
 



- [tg_poly_new()]#group___poly_funcs_1ga56c2615488ca202baa944c85c20a40f1
- [tg_poly_free()]#group___poly_funcs_1ga7a591cc2298e4e24ae0e99b055a61fed
- [tg_poly_clone()]#group___poly_funcs_1ga2f01b5838bcb3669e3aacace12062fbf
- [tg_poly_copy()]#group___poly_funcs_1gae68cadbe9ae2fa26c92f010958c6ed11
- [tg_poly_memsize()]#group___poly_funcs_1gabccc5c197d02868b9d24df7b7cabeea4
- [tg_poly_exterior()]#group___poly_funcs_1ga802bb035aa8b2efd234973b98eefb128
- [tg_poly_num_holes()]#group___poly_funcs_1ga23934cf6af1048e2e4b06befef3f8c1f
- [tg_poly_hole_at()]#group___poly_funcs_1gad15090afe596c268858c65b5c5e47a73
- [tg_poly_rect()]#group___poly_funcs_1gaac2de96544c41331886fd2b48e11ba6d
- [tg_poly_clockwise()]#group___poly_funcs_1gac52d19818b926e8d9e70abb0e3889da8


<a name='group___global_funcs'></a>
## Global environment

Functions for optionally setting the behavior of the TG environment. These, if desired, should be called only once at program start up and prior to calling any other tg_*() functions. 



- [tg_env_set_allocator()]#group___global_funcs_1gab1e1478a3870e90d6b5932f5e67a032b
- [tg_env_set_index()]#group___global_funcs_1ga57a922edb770400033043354c1f4e80e
- [tg_env_set_index_spread()]#group___global_funcs_1gaf9e9214a8db08c306fdb529192e9dd5f

<a name='structtg__point'></a>
## tg_point
```c
struct tg_point {
    double x;
    double y;
};
```
The base point type used for all geometries. 

**See also**

- [Point functions]#group___point_funcs



<a name='structtg__segment'></a>
## tg_segment
```c
struct tg_segment {
    struct tg_point a;
    struct tg_point b;
};
```
The base segment type used in [tg_line](#structtg__line) and [tg_ring](#structtg__ring) for joining two vertices. 

**See also**

- [Segment functions]#group___segment_funcs



<a name='structtg__rect'></a>
## tg_rect
```c
struct tg_rect {
    struct tg_point min;
    struct tg_point max;
};
```
A rectangle defined by a minimum and maximum coordinates. Returned by the [tg_geom_rect()](#group___geometry_accessors_1ga68d67f900b847ae08e6515a620f4f657), [tg_ring_rect()](#group___ring_funcs_1ga64086c935039b1f0fcd8633be763427d), and other *_rect() functions for getting a geometry's minumum bounding rectangle. Also used internally for geometry indexing. 

**See also**

- [Rectangle functions]#group___rect_funcs



<a name='structtg__ring'></a>
## tg_ring
```c
struct tg_ring;
```
A ring is series of [tg_segment](#structtg__segment) which creates a shape that does not self-intersect and is fully closed, where the start and end points are the exact same value.

**Creating**

To create a new ring use the [tg_ring_new()](#group___ring_funcs_1ga7defe1b6d43be8285a73f7977b342661) function.

```c
struct tg_ring *ring = tg_ring_new(points, npoints);
```


**Upcasting**

A [tg_ring](#structtg__ring) can always be safely upcasted to a [tg_poly](#structtg__poly) or [tg_geom](#structtg__geom); allowing it to use any tg_poly_&ast;() or tg_geom_&ast;() function.

```c
struct tg_poly *poly = (struct tg_poly*)ring; // Cast to a tg_poly
struct tg_geom *geom = (struct tg_geom*)ring; // Cast to a tg_geom
```
 

**See also**

- [Ring functions]#group___ring_funcs
- [Polygon functions]#group___poly_funcs



<a name='structtg__line'></a>
## tg_line
```c
struct tg_line;
```
A line is a series of [tg_segment](#structtg__segment) that make up a linestring.

**Creating**

To create a new line use the [tg_line_new()](#group___line_funcs_1ga7f834a7213c8d87d8b7c7117bdf8bf63) function.

```c
struct tg_line *line = tg_line_new(points, npoints);
```


**Upcasting**

A [tg_line](#structtg__line) can always be safely upcasted to a [tg_geom](#structtg__geom); allowing it to use any tg_geom_&ast;() function.

```c
struct tg_geom *geom = (struct tg_geom*)line; // Cast to a tg_geom
```




**See also**

- [Line functions]#group___line_funcs



<a name='structtg__poly'></a>
## tg_poly
```c
struct tg_poly;
```
A polygon consists of one exterior ring and zero or more holes.

**Creating**

To create a new polygon use the [tg_poly_new()](#group___poly_funcs_1ga56c2615488ca202baa944c85c20a40f1) function.

```c
struct tg_poly *poly = tg_poly_new(exterior, holes, nholes);
```


**Upcasting**

A [tg_poly](#structtg__poly) can always be safely upcasted to a [tg_geom](#structtg__geom); allowing it to use any tg_geom_&ast;() function.

```c
struct tg_geom *geom = (struct tg_geom*)poly; // Cast to a tg_geom
```




**See also**

- [Polygon functions]#group___poly_funcs



<a name='structtg__geom'></a>
## tg_geom
```c
struct tg_geom;
```
A geometry is the common generic type that can represent a Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, or GeometryCollection.

For geometries that are derived from GeoJSON, they may have addtional attributes such as being a Feature or a FeatureCollection; or include extra json fields.

**Creating**

To create a new geometry use one of the [Geometry constructors](#group___geometry_constructors) or [Geometry parsing](#group___geometry_parsing) functions.

```c
struct tg_geom *geom = tg_geom_new_point(point);
struct tg_geom *geom = tg_geom_new_polygon(poly);
struct tg_geom *geom = tg_parse_geojson(geojson);
```


**Upcasting**

Other types, specifically [tg_line](#structtg__line), [tg_ring](#structtg__ring), and [tg_poly](#structtg__poly), can be safely upcasted to a [tg_geom](#structtg__geom); allowing them to use any tg_geom_&ast;() function.

```c
struct tg_geom *geom1 = (struct tg_geom*)line; // Cast to a LineString
struct tg_geom *geom2 = (struct tg_geom*)ring; // Cast to a Polygon
struct tg_geom *geom3 = (struct tg_geom*)poly; // Cast to a Polygon
```




**See also**

- [Geometry constructors]#group___geometry_constructors
- [Geometry accessors]#group___geometry_accessors
- [Geometry predicates]#group___geometry_predicates
- [Geometry parsing]#group___geometry_parsing
- [Geometry writing]#group___geometry_writing



<a name='tg_8h_1a041ea24bc56bb85748f965415a3bd864'></a>
## tg_geom_type
```c
enum tg_geom_type {
    TG_POINT              = 1, // Point.
    TG_LINESTRING         = 2, // LineString.
    TG_POLYGON            = 3, // Polygon.
    TG_MULTIPOINT         = 4, // MultiPoint, collection of points.
    TG_MULTILINESTRING    = 5, // MultiLineString, collection of linestrings.
    TG_MULTIPOLYGON       = 6, // MultiPolygon, collection of polygons.
    TG_GEOMETRYCOLLECTION = 7, // GeometryCollection, collection of geometries.
};
```
Geometry types.

All [tg_geom](#structtg__geom) are one of the following underlying types.



**See also**

- [tg_geom_typeof()]#group___geometry_accessors_1ga7a2e146938fab50268b7798cb3bc91cc
- [tg_geom_type_string()]#group___geometry_accessors_1ga0435b45df2158200f3b527d1adb11a62
- [Geometry accessors]#group___geometry_accessors



<a name='tg_8h_1a0dab409fed835315465fcb47a9a926c7'></a>
## tg_index
```c
enum tg_index {
    TG_DEFAULT,  // default is TG_NATURAL or tg_env_set_default_index().
    TG_NONE,     // no indexing available, or disabled.
    TG_NATURAL,  // indexing with natural ring order, for rings/lines
    TG_YSTRIPES, // indexing using segment striping, rings only
};
```
Geometry indexing options.

Used for polygons, rings, and lines to make the point-in-polygon and geometry intersection operations fast.

An index can also be used for efficiently traversing, searching, and performing nearest-neighbor (kNN) queries on the segment using tg_ring_index_*() and tg_ring_nearest() functions. 


<a name='group___geometry_constructors_1ga5ed750d9db318f6677f85b53e5b2ab2c'></a>
## tg_geom_new_point()
```c
struct tg_geom *tg_geom_new_point(struct tg_point point);
```
Creates a Point geometry. 

**Parameters**

- **point**: Input point



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry constructors]#group___geometry_constructors



<a name='group___geometry_constructors_1ga2f22a237852eee8821cdf2db95b3c094'></a>
## tg_geom_new_linestring()
```c
struct tg_geom *tg_geom_new_linestring(const struct tg_line *line);
```
Creates a LineString geometry. 

**Parameters**

- **line**: Input line, caller retains ownership.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry constructors]#group___geometry_constructors



<a name='group___geometry_constructors_1gac6d59362c7ec1971eca36b0ee4089409'></a>
## tg_geom_new_polygon()
```c
struct tg_geom *tg_geom_new_polygon(const struct tg_poly *poly);
```
Creates a Polygon geometry. 

**Parameters**

- **poly**: Input polygon, caller retains ownership.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry constructors]#group___geometry_constructors



<a name='group___geometry_constructors_1ga52fc0309986b70f9bb0622c65f801f92'></a>
## tg_geom_new_multipoint()
```c
struct tg_geom *tg_geom_new_multipoint(const struct tg_point *points, int npoints);
```
Creates a MultiPoint geometry. 

**Parameters**

- **points**: An array of points, caller retains ownership.
- **npoints**: The number of points in array



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry constructors]#group___geometry_constructors



<a name='group___geometry_constructors_1gaccfd80de48f1e5c7de38cbf515d3bf9f'></a>
## tg_geom_new_multilinestring()
```c
struct tg_geom *tg_geom_new_multilinestring(const struct tg_line *const lines[], int nlines);
```
Creates a MultiLineString geometry. 

**Parameters**

- **lines**: An array of lines, caller retains ownership.
- **nlines**: The number of lines in array



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry constructors]#group___geometry_constructors



<a name='group___geometry_constructors_1gad57b01099788e21a5103cd8293f4e364'></a>
## tg_geom_new_multipolygon()
```c
struct tg_geom *tg_geom_new_multipolygon(const struct tg_poly *const polys[], int npolys);
```
Creates a MultiPolygon geometry. 

**Parameters**

- **polys**: An array of polygons, caller retains ownership.
- **npolys**: The number of polygons in array



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry constructors]#group___geometry_constructors



<a name='group___geometry_constructors_1ga39569ef55606b8d54ed7cf14a4382bdd'></a>
## tg_geom_new_geometrycollection()
```c
struct tg_geom *tg_geom_new_geometrycollection(const struct tg_geom *const geoms[], int ngeoms);
```
Creates a GeometryCollection geometry. 

**Parameters**

- **geoms**: An array of geometries, caller retains ownership.
- **ngeoms**: The number of geometries in array



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry constructors]#group___geometry_constructors



<a name='group___geometry_constructors_1ga76f55846aa97188b1840b9ad07dae000'></a>
## tg_geom_clone()
```c
struct tg_geom *tg_geom_clone(const struct tg_geom *geom);
```
Clones a geometry 

**Parameters**

- **geom**: Input geometry, caller retains ownership.



**Return**

- A duplicate of the provided geometry.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.
- This method of cloning uses implicit sharing through an atomic reference counter.


**See also**

- [Geometry constructors]#group___geometry_constructors



<a name='group___geometry_constructors_1ga389a890d60908d3e2b448a0e2b3d558e'></a>
## tg_geom_copy()
```c
struct tg_geom *tg_geom_copy(const struct tg_geom *geom);
```
Copies a geometry 

**Parameters**

- **geom**: Input geometry, caller retains ownership.



**Return**

- A duplicate of the provided geometry.
- NULL if out of memory


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.
- This method performs a deep copy of the entire geometry to new memory.


**See also**

- [Geometry constructors]#group___geometry_constructors



<a name='group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae'></a>
## tg_geom_free()
```c
void tg_geom_free(struct tg_geom *geom);
```
Releases the memory associated with a geometry. 

**Parameters**

- **geom**: Input geometry



**See also**

- [Geometry constructors]#group___geometry_constructors



<a name='group___geometry_accessors_1ga7a2e146938fab50268b7798cb3bc91cc'></a>
## tg_geom_typeof()
```c
enum tg_geom_type tg_geom_typeof(const struct tg_geom *geom);
```
Returns the geometry type. e.g. TG_POINT, TG_POLYGON, TG_LINESTRING 

**Parameters**

- **geom**: Input geometry



**Return**

- The geometry type


**See also**

- [tg_geom_type].#tg_geom_type
- [tg_geom_type_string()]#group___geometry_accessors_1ga0435b45df2158200f3b527d1adb11a62
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1ga0435b45df2158200f3b527d1adb11a62'></a>
## tg_geom_type_string()
```c
const char *tg_geom_type_string(enum tg_geom_type type);
```
Get the string representation of a geometry type. e.g. "Point", "Polygon", "LineString". 

**Parameters**

- **type**: Input geometry type



**Return**

- A string representing the type


**Note**

- The returned string does not need to be freed.


**See also**

- [tg_geom_typeof()]#group___geometry_accessors_1ga7a2e146938fab50268b7798cb3bc91cc
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1ga68d67f900b847ae08e6515a620f4f657'></a>
## tg_geom_rect()
```c
struct tg_rect tg_geom_rect(const struct tg_geom *geom);
```
Returns the minimum bounding rectangle of a geometry. 

**Parameters**

- **geom**: Input geometry



**Return**

- Minumum bounding rectangle


**See also**

- [tg_rect]#structtg__rect
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1ga9bb37a84e3d0f67433309ff1ac3c6be3'></a>
## tg_geom_is_feature()
```c
bool tg_geom_is_feature(const struct tg_geom *geom);
```
Returns true if the geometry is a GeoJSON Feature. 

**Parameters**

- **geom**: Input geometry



**Return**

- True or false


**See also**

- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1gadd8c3b4c29006264c9716fc7b5ebb212'></a>
## tg_geom_is_featurecollection()
```c
bool tg_geom_is_featurecollection(const struct tg_geom *geom);
```
Returns true if the geometry is a GeoJSON FeatureCollection. 

**Parameters**

- **geom**: Input geometry



**Return**

- True or false


**See also**

- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1gad8c95d22a1f5900ddc22564575ba687b'></a>
## tg_geom_point()
```c
struct tg_point tg_geom_point(const struct tg_geom *geom);
```
Returns the underlying point for the provided geometry. 

**Parameters**

- **geom**: Input geometry



**Return**

- For a TG_POINT geometry, returns the point.
- For everything else returns the center of the geometry's bounding rectangle.


**See also**

- [tg_point]#structtg__point
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1ga36d293b2d81c81785fe72c84ff73f861'></a>
## tg_geom_line()
```c
const struct tg_line *tg_geom_line(const struct tg_geom *geom);
```
Returns the underlying line for the provided geometry. 

**Parameters**

- **geom**: Input geometry



**Return**

- For a TG_LINESTRING geometry, returns the line.
- For everything else returns NULL.


**See also**

- [tg_line]#structtg__line
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1ga37415d625c521abbe95ef799b2fd3809'></a>
## tg_geom_poly()
```c
const struct tg_poly *tg_geom_poly(const struct tg_geom *geom);
```
Returns the underlying polygon for the provided geometry. 

**Parameters**

- **geom**: Input geometry



**Return**

- For a TG_POLYGON geometry, returns the polygon.
- For everything else returns NULL.


**See also**

- [tg_poly]#structtg__poly
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1gaeb827e40d40c8160973a5cfb880580df'></a>
## tg_geom_num_points()
```c
int tg_geom_num_points(const struct tg_geom *geom);
```
Returns the number of points in a MultiPoint geometry. 

**Parameters**

- **geom**: Input geometry



**Return**

- For a TG_MULTIPOINT geometry, returns the number of points.
- For everything else returns zero.


**See also**

- [tg_geom_point_at()]#group___geometry_accessors_1ga4f43a8071ffe50ad5dafef4683a48414
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1ga4f43a8071ffe50ad5dafef4683a48414'></a>
## tg_geom_point_at()
```c
struct tg_point tg_geom_point_at(const struct tg_geom *geom, int index);
```
Returns the point at index for a MultiPoint geometry. 

**Parameters**

- **geom**: Input geometry
- **index**: Index of point



**Return**

- The point at index. Returns an empty point if the geometry type is not TG_MULTIPOINT or when the provided index is out of range.


**See also**

- [tg_geom_num_points()]#group___geometry_accessors_1gaeb827e40d40c8160973a5cfb880580df
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1gab4081f22ed68c0364a32b8ece9bfd49f'></a>
## tg_geom_num_lines()
```c
int tg_geom_num_lines(const struct tg_geom *geom);
```
Returns the number of lines in a MultiLineString geometry. 

**Parameters**

- **geom**: Input geometry



**Return**

- For a TG_MULTILINESTRING geometry, returns the number of lines.
- For everything else returns zero.


**See also**

- [tg_geom_line_at()]#group___geometry_accessors_1gadfc1eecd7d86b2922e96502b6bdebc16
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1gadfc1eecd7d86b2922e96502b6bdebc16'></a>
## tg_geom_line_at()
```c
const struct tg_line *tg_geom_line_at(const struct tg_geom *geom, int index);
```
Returns the line at index for a MultiLineString geometry. 

**Parameters**

- **geom**: Input geometry
- **index**: Index of line



**Return**

- The line at index. Returns NULL if the geometry type is not TG_MULTILINE or when the provided index is out of range.


**See also**

- [tg_geom_num_lines()]#group___geometry_accessors_1gab4081f22ed68c0364a32b8ece9bfd49f
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1ga6eb2bf473b2672dd5ff00731e358e33e'></a>
## tg_geom_num_polys()
```c
int tg_geom_num_polys(const struct tg_geom *geom);
```
Returns the number of polygons in a MultiPolygon geometry. 

**Parameters**

- **geom**: Input geometry



**Return**

- For a TG_MULTIPOLYGON geometry, returns the number of polygons.
- For everything else returns zero.


**See also**

- [tg_geom_poly_at()]#group___geometry_accessors_1gae87b48f5a0e34bd5f1c477aea4027508
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1gae87b48f5a0e34bd5f1c477aea4027508'></a>
## tg_geom_poly_at()
```c
const struct tg_poly *tg_geom_poly_at(const struct tg_geom *geom, int index);
```
Returns the polygon at index for a MultiPolygon geometry. 

**Parameters**

- **geom**: Input geometry
- **index**: Index of polygon



**Return**

- The polygon at index. Returns NULL if the geometry type is not TG_MULTIPOLYGON or when the provided index is out of range.


**See also**

- [tg_geom_num_polys()]#group___geometry_accessors_1ga6eb2bf473b2672dd5ff00731e358e33e
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1ga9012c39360345e8e662ac36137165d14'></a>
## tg_geom_num_geometries()
```c
int tg_geom_num_geometries(const struct tg_geom *geom);
```
Returns the number of geometries in a GeometryCollection geometry. 

**Parameters**

- **geom**: Input geometry



**Return**

- For a TG_MULTIGEOMETRY geometry, returns the number of geometries.
- For everything else returns zero.


**Note**

- A geometry that is a GeoJSON FeatureCollection can use this function to get number features in its collection.


**See also**

- [tg_geom_geometry_at()]#group___geometry_accessors_1ga55f13f898c2236e065e30f3313d48f38
- [tg_geom_is_featurecollection()]#group___geometry_accessors_1gadd8c3b4c29006264c9716fc7b5ebb212
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1ga55f13f898c2236e065e30f3313d48f38'></a>
## tg_geom_geometry_at()
```c
const struct tg_geom *tg_geom_geometry_at(const struct tg_geom *geom, int index);
```
Returns the geometry at index for a GeometryCollection geometry. 

**Parameters**

- **geom**: Input geometry
- **index**: Index of geometry



**Return**

- For a TG_MULTIGEOMETRY geometry, returns the number of geometries.
- For everything else returns zero.


**Note**

- A geometry that is a GeoJSON FeatureCollection can use this function to get number features in its collection.


**See also**

- [tg_geom_geometry_at()]#group___geometry_accessors_1ga55f13f898c2236e065e30f3313d48f38
- [tg_geom_is_featurecollection()]#group___geometry_accessors_1gadd8c3b4c29006264c9716fc7b5ebb212
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_accessors_1ga91a2927f57c59c0dbe9a9be89e4c93dd'></a>
## tg_geom_extra_json()
```c
const char *tg_geom_extra_json(const struct tg_geom *geom);
```
Returns a string that represents any extra JSON from a parsed GeoJSON geometry. Such as the "id" or "properties" fields. 

**Parameters**

- **geom**: Input geometry



**Return**

- Returns a valid JSON object as a string, or NULL if the geometry did not come from GeoJSON or there is no extra JSON.


**Note**

- The returned string does not need to be freed.


**See also**

- [tg_parse_geojson()]#group___geometry_parsing_1ga42ba8cac8e7f7d0b31c7d5eab63da8b4



<a name='group___geometry_accessors_1ga7fc477dff52783a69f2a876ca05b8183'></a>
## tg_geom_is_empty()
```c
bool tg_geom_is_empty(const struct tg_geom *geom);
```
Tests whether a geometry is empty. An empty geometry is one that has no interior boundary. 

**Parameters**

- **geom**: Input geometry



**Return**

- True or false



<a name='group___geometry_accessors_1ga32f2c81b2638a85e5209fc093703b847'></a>
## tg_geom_dims()
```c
int tg_geom_dims(const struct tg_geom *geom);
```
Get the number of dimensions for a geometry. 

**Parameters**

- **geom**: Input geometry



**Return**

- 2 for standard geometries
- 3 when geometry has Z or M coordinates
- 4 when geometry has Z and M coordinates
- 0 when input is NULL



<a name='group___geometry_accessors_1ga50731d93f23947df28bd12ef36f4fce2'></a>
## tg_geom_has_z()
```c
bool tg_geom_has_z(const struct tg_geom *geom);
```
Tests whether a geometry has Z coordinates. 

**Parameters**

- **geom**: Input geometry



**Return**

- True or false



<a name='group___geometry_accessors_1ga0eb6e450280ba90eeed711c49f7b3cd0'></a>
## tg_geom_has_m()
```c
bool tg_geom_has_m(const struct tg_geom *geom);
```
Tests whether a geometry has M coordinates. 

**Parameters**

- **geom**: Input geometry



**Return**

- True or false



<a name='group___geometry_accessors_1ga706dd7e2dd524ea74f1ce258e133e112'></a>
## tg_geom_z()
```c
double tg_geom_z(const struct tg_geom *geom);
```
Get the Z coordinate of a Point geometry. 

**Parameters**

- **geom**: Input geometry



**Return**

- For a TG_POINT geometry, returns the Z coodinate.
- For everything else returns zero.



<a name='group___geometry_accessors_1ga4a9e6147ff09959e232106de59ee3feb'></a>
## tg_geom_m()
```c
double tg_geom_m(const struct tg_geom *geom);
```
Get the M coordinate of a Point geometry. 

**Parameters**

- **geom**: Input geometry



**Return**

- For a TG_POINT geometry, returns the M coodinate.
- For everything else returns zero.



<a name='group___geometry_accessors_1gac5115d2642b03552856865dad33dd494'></a>
## tg_geom_extra_coords()
```c
const double *tg_geom_extra_coords(const struct tg_geom *geom);
```
Get the extra coordinates for a geometry. 

**Parameters**

- **geom**: Input geometry



**Return**

- Array of coordinates
- NULL if there are no extra coordinates


**Note**

- These are the raw coodinates provided by a constructor like [tg_geom_new_polygon_z()]#group___geometry_constructors_ex_1gac81514f9acbafce335d8982233772664 or from a parsed source like WKT "POLYGON Z ...".


**See also**

- [tg_geom_num_extra_coords()]#group___geometry_accessors_1ga5f85cf4c143703ee227e3c35accbde8b



<a name='group___geometry_accessors_1ga5f85cf4c143703ee227e3c35accbde8b'></a>
## tg_geom_num_extra_coords()
```c
int tg_geom_num_extra_coords(const struct tg_geom *geom);
```
Get the number of extra coordinates for a geometry 

**Parameters**

- **geom**: Input geometry



**Return**

- The number of extra coordinates, or zero if none.


**See also**

- [tg_geom_extra_coords()]#group___geometry_accessors_1gac5115d2642b03552856865dad33dd494



<a name='group___geometry_accessors_1ga4931914f5170cce2949cfdd79e34ef63'></a>
## tg_geom_memsize()
```c
size_t tg_geom_memsize(const struct tg_geom *geom);
```
Returns the allocation size of the geometry. 

**Parameters**

- **geom**: Input geometry



**Return**

- Size of geometry in bytes



<a name='group___geometry_accessors_1gad18cdb2a4ab1fa711dce821a0868ecd2'></a>
## tg_geom_search()
```c
void tg_geom_search(const struct tg_geom *geom, struct tg_rect rect, bool(*iter)(const struct tg_geom *geom, int index, void *udata), void *udata);
```
Iterates over all child geometries in geom that intersect rect 

**Note**

- Only iterates over collection types: TG_MULTIPOINT, TG_MULTILINESTRING, TG_MULTIPOLYGON, and TG_GEOMETRYCOLLECTION.
- A GeoJSON FeatureCollection works as well.


**See also**

- [tg_geom_typeof()]#group___geometry_accessors_1ga7a2e146938fab50268b7798cb3bc91cc
- [Geometry accessors]#group___geometry_accessors



<a name='group___geometry_predicates_1ga87876bf188ea21a55900b497bad436f0'></a>
## tg_geom_equals()
```c
bool tg_geom_equals(const struct tg_geom *a, const struct tg_geom *b);
```
Tests whether two geometries are topologically equal. 

**See also**

- [Geometry predicates]#group___geometry_predicates



<a name='group___geometry_predicates_1gacd094b340fcc39ae01f7e0493bc5f096'></a>
## tg_geom_intersects()
```c
bool tg_geom_intersects(const struct tg_geom *a, const struct tg_geom *b);
```
Tests whether two geometries intersect. 

**See also**

- [Geometry predicates]#group___geometry_predicates



<a name='group___geometry_predicates_1ga852863a931d4acb87d26fb7688587804'></a>
## tg_geom_disjoint()
```c
bool tg_geom_disjoint(const struct tg_geom *a, const struct tg_geom *b);
```
Tests whether 'a' and 'b' have no point in common, and are fully disconnected geometries. 

**Note**

- Works the same as `!tg_geom_intersects(a, b)`


**See also**

- [Geometry predicates]#group___geometry_predicates



<a name='group___geometry_predicates_1gac0edb8e95808d07ac21b1d17cfdd2544'></a>
## tg_geom_contains()
```c
bool tg_geom_contains(const struct tg_geom *a, const struct tg_geom *b);
```
Tests whether 'a' contains 'b', and 'b' is not touching the boundary of 'a'. 

**Note**

- Works the same as `tg_geom_within(b, a)`


**Warning**

- This predicate returns **false** when geometry 'b' is *on* or *touching* the boundary of geometry 'a'. Such as when a point is on the edge of a polygon. 
 For full coverage, consider using [tg_geom_covers]#group___geometry_predicates_1gab50d4126fbefb891fdc387bcfab0b7bb.


**See also**

- [Geometry predicates]#group___geometry_predicates



<a name='group___geometry_predicates_1gab4018711f7e427767e4fb9fd58e3afab'></a>
## tg_geom_within()
```c
bool tg_geom_within(const struct tg_geom *a, const struct tg_geom *b);
```
Tests whether 'a' is contained inside of 'b' and not touching the boundary of 'b'. 

**Note**

- Works the same as `tg_geom_contains(b, a)`


**Warning**

- This predicate returns **false** when geometry 'a' is *on* or *touching* the boundary of geometry 'b'. Such as when a point is on the edge of a polygon. 
 For full coverage, consider using [tg_geom_coveredby]#group___geometry_predicates_1gabffa9e68db9c9708ad334a4ecd055d0b.


**See also**

- [Geometry predicates]#group___geometry_predicates



<a name='group___geometry_predicates_1gab50d4126fbefb891fdc387bcfab0b7bb'></a>
## tg_geom_covers()
```c
bool tg_geom_covers(const struct tg_geom *a, const struct tg_geom *b);
```
Tests whether a geometry 'a' fully contains geometry 'b'. 

**See also**

- [Geometry predicates]#group___geometry_predicates



<a name='group___geometry_predicates_1gabffa9e68db9c9708ad334a4ecd055d0b'></a>
## tg_geom_coveredby()
```c
bool tg_geom_coveredby(const struct tg_geom *a, const struct tg_geom *b);
```
Tests whether 'a' is fully contained inside of 'b'. 

**Note**

- Works the same as `tg_geom_covers(b, a)`


**See also**

- [Geometry predicates]#group___geometry_predicates



<a name='group___geometry_predicates_1gabc5c6a541f4e553b70432c33128296a4'></a>
## tg_geom_touches()
```c
bool tg_geom_touches(const struct tg_geom *a, const struct tg_geom *b);
```
Tests whether a geometry 'a' touches 'b'. They have at least one point in common, but their interiors do not intersect. 

**See also**

- [Geometry predicates]#group___geometry_predicates



<a name='group___geometry_predicates_1ga9e21b39dd7fdf8338b221ef18dc7dbe6'></a>
## tg_geom_intersects_rect()
```c
bool tg_geom_intersects_rect(const struct tg_geom *a, struct tg_rect b);
```
Tests whether a geometry intersects a rect. 

**See also**

- [Geometry predicates]#group___geometry_predicates



<a name='group___geometry_predicates_1ga5e059ff81a10aab64ec6b5f9af6d5bcf'></a>
## tg_geom_intersects_xy()
```c
bool tg_geom_intersects_xy(const struct tg_geom *a, double x, double y);
```
Tests whether a geometry intersects a point using xy coordinates. 

**See also**

- [Geometry predicates]#group___geometry_predicates



<a name='group___geometry_parsing_1ga42ba8cac8e7f7d0b31c7d5eab63da8b4'></a>
## tg_parse_geojson()
```c
struct tg_geom *tg_parse_geojson(const char *geojson);
```
Parse geojson.

Supports [GeoJSON](https://datatracker.ietf.org/doc/html/rfc7946) standard, including Features, FeaturesCollection, ZM coordinates, properties, and arbritary JSON members. 

**Parameters**

- **geojson**: A geojson string. Must be UTF8 and null-terminated.



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_parse_geojsonn()]#group___geometry_parsing_1ga45f669345bccec7184f8a127ada71067
- [tg_parse_geojson_ix()]#group___geometry_parsing_1gab78f1bd7fede29ebb2ecb9895d1c6bdf
- [tg_parse_geojsonn_ix()]#group___geometry_parsing_1ga3b11ffa6b82d29245e673d096ac964db
- [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e
- [tg_geom_geojson()]#group___geometry_writing_1gae4669b8ee598a46e7f4c5a11e645fe8f
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_parsing_1ga45f669345bccec7184f8a127ada71067'></a>
## tg_parse_geojsonn()
```c
struct tg_geom *tg_parse_geojsonn(const char *geojson, size_t len);
```
Parse geojson with an included data length. 

**Parameters**

- **geojson**: Geojson data. Must be UTF8.
- **len**: Length of data



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_parse_geojson()]#group___geometry_parsing_1ga42ba8cac8e7f7d0b31c7d5eab63da8b4
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_parsing_1gab78f1bd7fede29ebb2ecb9895d1c6bdf'></a>
## tg_parse_geojson_ix()
```c
struct tg_geom *tg_parse_geojson_ix(const char *geojson, enum tg_index ix);
```
Parse geojson using provided indexing option. 

**Parameters**

- **geojson**: A geojson string. Must be UTF8 and null-terminated.
- **ix**: Indexing option, e.g. TG_NONE, TG_NATURAL, TG_YSTRIPES



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_index].#tg_index
- [tg_parse_geojson()]#group___geometry_parsing_1ga42ba8cac8e7f7d0b31c7d5eab63da8b4
- [tg_parse_geojsonn_ix()]#group___geometry_parsing_1ga3b11ffa6b82d29245e673d096ac964db
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_parsing_1ga3b11ffa6b82d29245e673d096ac964db'></a>
## tg_parse_geojsonn_ix()
```c
struct tg_geom *tg_parse_geojsonn_ix(const char *geojson, size_t len, enum tg_index ix);
```
Parse geojson using provided indexing option. 

**Parameters**

- **geojson**: Geojson data. Must be UTF8.
- **len**: Length of data
- **ix**: Indexing option, e.g. TG_NONE, TG_NATURAL, TG_YSTRIPES



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_index].#tg_index
- [tg_parse_geojson()]#group___geometry_parsing_1ga42ba8cac8e7f7d0b31c7d5eab63da8b4
- [tg_parse_geojson_ix()]#group___geometry_parsing_1gab78f1bd7fede29ebb2ecb9895d1c6bdf
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_parsing_1ga5abcaa01d5b5e14ea017ff9dd5bd426c'></a>
## tg_parse_wkt()
```c
struct tg_geom *tg_parse_wkt(const char *wkt);
```
Parse Well-known text (WKT). 

**Parameters**

- **wkt**: A WKT string. Must be null-terminated



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_parse_wktn()]#group___geometry_parsing_1gaae7cb710cdb42db02b398760acd37f84
- [tg_parse_wkt_ix()]#group___geometry_parsing_1ga0444fdcf8fb4cb754b4a2c1e07f899e5
- [tg_parse_wktn_ix()]#group___geometry_parsing_1gadf71b642030b63dc399bd2f213a76ed8
- [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e
- [tg_geom_wkt()]#group___geometry_writing_1ga047599bbe51886a6c3fbe35a6372d5d6
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_parsing_1gaae7cb710cdb42db02b398760acd37f84'></a>
## tg_parse_wktn()
```c
struct tg_geom *tg_parse_wktn(const char *wkt, size_t len);
```
Parse Well-known text (WKT) with an included data length. 

**Parameters**

- **wkt**: WKT data
- **len**: Length of data



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_parse_wkt()]#group___geometry_parsing_1ga5abcaa01d5b5e14ea017ff9dd5bd426c
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_parsing_1ga0444fdcf8fb4cb754b4a2c1e07f899e5'></a>
## tg_parse_wkt_ix()
```c
struct tg_geom *tg_parse_wkt_ix(const char *wkt, enum tg_index ix);
```
Parse Well-known text (WKT) using provided indexing option. 

**Parameters**

- **wkt**: A WKT string. Must be null-terminated
- **ix**: Indexing option, e.g. TG_NONE, TG_NATURAL, TG_YSTRIPES



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_parse_wkt()]#group___geometry_parsing_1ga5abcaa01d5b5e14ea017ff9dd5bd426c
- [tg_parse_wktn_ix()]#group___geometry_parsing_1gadf71b642030b63dc399bd2f213a76ed8
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_parsing_1gadf71b642030b63dc399bd2f213a76ed8'></a>
## tg_parse_wktn_ix()
```c
struct tg_geom *tg_parse_wktn_ix(const char *wkt, size_t len, enum tg_index ix);
```
Parse Well-known text (WKT) using provided indexing option. 

**Parameters**

- **wkt**: WKT data
- **len**: Length of data
- **ix**: Indexing option, e.g. TG_NONE, TG_NATURAL, TG_YSTRIPES



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_parse_wkt()]#group___geometry_parsing_1ga5abcaa01d5b5e14ea017ff9dd5bd426c
- [tg_parse_wkt_ix()]#group___geometry_parsing_1ga0444fdcf8fb4cb754b4a2c1e07f899e5
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_parsing_1ga6929035c4b0e606ef84537272d1ece30'></a>
## tg_parse_wkb()
```c
struct tg_geom *tg_parse_wkb(const uint8_t *wkb, size_t len);
```
Parse Well-known binary (WKB). 

**Parameters**

- **wkb**: WKB data
- **len**: Length of data



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_parse_wkb_ix()]#group___geometry_parsing_1gae7c77d7de79d8f8023bff15f6ad2b7ae
- [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e
- [tg_geom_wkb()]#group___geometry_writing_1gac0938697f9270d1924c6746af68dd693
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_parsing_1gae7c77d7de79d8f8023bff15f6ad2b7ae'></a>
## tg_parse_wkb_ix()
```c
struct tg_geom *tg_parse_wkb_ix(const uint8_t *wkb, size_t len, enum tg_index ix);
```
Parse Well-known binary (WKB) using provided indexing option. 

**Parameters**

- **wkb**: WKB data
- **len**: Length of data
- **ix**: Indexing option, e.g. TG_NONE, TG_NATURAL, TG_YSTRIPES



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_parse_wkb()]#group___geometry_parsing_1ga6929035c4b0e606ef84537272d1ece30



<a name='group___geometry_parsing_1ga0fc4fd8cb076a78c44df07c517281f67'></a>
## tg_parse_hex()
```c
struct tg_geom *tg_parse_hex(const char *hex);
```
Parse hex encoded Well-known binary (WKB). 

**Parameters**

- **hex**: A hex string. Must be null-terminated



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_parse_hexn()]#group___geometry_parsing_1ga2beb47ee201ddbd1a9a7a43c938c4396
- [tg_parse_hex_ix()]#group___geometry_parsing_1ga8718e134723418426e5df2b13acdf0c1
- [tg_parse_hexn_ix()]#group___geometry_parsing_1ga3d1f9eb85ff97812fed7cf7bf9e14bd4
- [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e
- [tg_geom_hex()]#group___geometry_writing_1ga269f61715302d48f144ffaf46e8c397b
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_parsing_1ga2beb47ee201ddbd1a9a7a43c938c4396'></a>
## tg_parse_hexn()
```c
struct tg_geom *tg_parse_hexn(const char *hex, size_t len);
```
Parse hex encoded Well-known binary (WKB) with an included data length. 

**Parameters**

- **hex**: Hex data
- **len**: Length of data



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_parse_hex()]#group___geometry_parsing_1ga0fc4fd8cb076a78c44df07c517281f67
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_parsing_1ga8718e134723418426e5df2b13acdf0c1'></a>
## tg_parse_hex_ix()
```c
struct tg_geom *tg_parse_hex_ix(const char *hex, enum tg_index ix);
```
Parse hex encoded Well-known binary (WKB) using provided indexing option. 

**Parameters**

- **hex**: Hex string. Must be null-terminated
- **ix**: Indexing option, e.g. TG_NONE, TG_NATURAL, TG_YSTRIPES



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_parse_hex()]#group___geometry_parsing_1ga0fc4fd8cb076a78c44df07c517281f67
- [tg_parse_hexn_ix()]#group___geometry_parsing_1ga3d1f9eb85ff97812fed7cf7bf9e14bd4
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_parsing_1ga3d1f9eb85ff97812fed7cf7bf9e14bd4'></a>
## tg_parse_hexn_ix()
```c
struct tg_geom *tg_parse_hexn_ix(const char *hex, size_t len, enum tg_index ix);
```
Parse hex encoded Well-known binary (WKB) using provided indexing option. 

**Parameters**

- **hex**: Hex data
- **len**: Length of data
- **ix**: Indexing option, e.g. TG_NONE, TG_NATURAL, TG_YSTRIPES



**Return**

- A geometry or an error. Use [tg_geom_error()]#group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e after parsing to check for errors.


**See also**

- [tg_parse_hex()]#group___geometry_parsing_1ga0fc4fd8cb076a78c44df07c517281f67
- [tg_parse_hex_ix()]#group___geometry_parsing_1ga8718e134723418426e5df2b13acdf0c1
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_parsing_1gae77b27ad34c2a215cc281647ab6dbc7e'></a>
## tg_geom_error()
```c
const char *tg_geom_error(const struct tg_geom *geom);
```
Return a parsing error.

Parsing functions, such as [tg_parse_geojson()](#group___geometry_parsing_1ga42ba8cac8e7f7d0b31c7d5eab63da8b4), may fail due to invalid input data.

It's important to **always** check for errors after parsing.

**Example**

```c
struct tg_geom *geom = tg_parse_geojson(input);
if (tg_geom_error(geom)) {
    // The parsing failed due to invalid input or out of memory.

    // Get the error message.
    const char *err = tg_geom_error(geom);

    // Do something with the error, such as log it.
    printf("[err] %s\n", err);

    // Make sure to free the error geom and it's resources.
    tg_geom_free(geom);

    // !!
    // DO NOT use the return value of tg_geom_error() after calling 
    // tg_geom_free(). If you need to hang onto the error for a longer
    // period of time then you must copy it before freeing.
    // !!

    return;
} else {
    // ... Parsing succeeded 
}
```




**Return**

- A string describing the error
- NULL if there was no error


**See also**

- [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae
- [tg_parse_geojson()]#group___geometry_parsing_1ga42ba8cac8e7f7d0b31c7d5eab63da8b4
- [tg_parse_wkt()]#group___geometry_parsing_1ga5abcaa01d5b5e14ea017ff9dd5bd426c
- [tg_parse_wkb()]#group___geometry_parsing_1ga6929035c4b0e606ef84537272d1ece30
- [tg_parse_hex()]#group___geometry_parsing_1ga0fc4fd8cb076a78c44df07c517281f67
- [Geometry parsing]#group___geometry_parsing



<a name='group___geometry_writing_1gae4669b8ee598a46e7f4c5a11e645fe8f'></a>
## tg_geom_geojson()
```c
size_t tg_geom_geojson(const struct tg_geom *geom, char *dst, size_t n);
```
Writes a GeoJSON representation of a geometry.

The content is stored as a C string in the buffer pointed to by dst. A terminating null character is automatically appended after the content written.



**Parameters**

- **geom**: Input geometry
- **dst**: Buffer where the resulting content is stored.
- **n**: Maximum number of bytes to be used in the buffer.



**Return**

- The number of characters, not including the null-terminator, needed to store the content into the C string buffer. If the returned length is greater than n-1, then only a parital copy occurred, for example:
```c
char str[64];
size_t len = tg_geom_geojson(geom, str, sizeof(str));
if (len > sizeof(str)-1) {
    // ... write did not complete ...
}
```




**See also**

- [tg_geom_wkt()]#group___geometry_writing_1ga047599bbe51886a6c3fbe35a6372d5d6
- [tg_geom_wkb()]#group___geometry_writing_1gac0938697f9270d1924c6746af68dd693
- [tg_geom_hex()]#group___geometry_writing_1ga269f61715302d48f144ffaf46e8c397b
- [Geometry writing]#group___geometry_writing



<a name='group___geometry_writing_1ga047599bbe51886a6c3fbe35a6372d5d6'></a>
## tg_geom_wkt()
```c
size_t tg_geom_wkt(const struct tg_geom *geom, char *dst, size_t n);
```
Writes a Well-known text (WKT) representation of a geometry.

The content is stored as a C string in the buffer pointed to by dst. A terminating null character is automatically appended after the content written.



**Parameters**

- **geom**: Input geometry
- **dst**: Buffer where the resulting content is stored.
- **n**: Maximum number of bytes to be used in the buffer.



**Return**

- The number of characters, not including the null-terminator, needed to store the content into the C string buffer. If the returned length is greater than n-1, then only a parital copy occurred, for example:
```c
char str[64];
size_t len = tg_geom_wkt(geom, str, sizeof(str));
if (len > sizeof(str)-1) {
    // ... write did not complete ...
}
```




**See also**

- [tg_geom_geojson()]#group___geometry_writing_1gae4669b8ee598a46e7f4c5a11e645fe8f
- [tg_geom_wkb()]#group___geometry_writing_1gac0938697f9270d1924c6746af68dd693
- [tg_geom_hex()]#group___geometry_writing_1ga269f61715302d48f144ffaf46e8c397b
- [Geometry writing]#group___geometry_writing



<a name='group___geometry_writing_1gac0938697f9270d1924c6746af68dd693'></a>
## tg_geom_wkb()
```c
size_t tg_geom_wkb(const struct tg_geom *geom, uint8_t *dst, size_t n);
```
Writes a Well-known binary (WKB) representation of a geometry.

The content is stored in the buffer pointed by dst.



**Parameters**

- **geom**: Input geometry
- **dst**: Buffer where the resulting content is stored.
- **n**: Maximum number of bytes to be used in the buffer.



**Return**

- The number of characters needed to store the content into the buffer. If the returned length is greater than n, then only a parital copy occurred, for example:
```c
uint8_t buf[64];
size_t len = tg_geom_wkb(geom, buf, sizeof(buf));
if (len > sizeof(buf)) {
    // ... write did not complete ...
}
```




**See also**

- [tg_geom_geojson()]#group___geometry_writing_1gae4669b8ee598a46e7f4c5a11e645fe8f
- [tg_geom_wkt()]#group___geometry_writing_1ga047599bbe51886a6c3fbe35a6372d5d6
- [tg_geom_hex()]#group___geometry_writing_1ga269f61715302d48f144ffaf46e8c397b
- [Geometry writing]#group___geometry_writing



<a name='group___geometry_writing_1ga269f61715302d48f144ffaf46e8c397b'></a>
## tg_geom_hex()
```c
size_t tg_geom_hex(const struct tg_geom *geom, char *dst, size_t n);
```
Writes a hex encoded Well-known binary (WKB) representation of a geometry.

The content is stored as a C string in the buffer pointed to by dst. A terminating null character is automatically appended after the content written.



**Parameters**

- **geom**: Input geometry
- **dst**: Buffer where the resulting content is stored.
- **n**: Maximum number of bytes to be used in the buffer.



**Return**

- The number of characters, not including the null-terminator, needed to store the content into the C string buffer. If the returned length is greater than n-1, then only a parital copy occurred, for example:
```c
char str[64];
size_t len = tg_geom_hex(geom, str, sizeof(str));
if (len > sizeof(str)-1) {
    // ... write did not complete ...
}
```




**See also**

- [tg_geom_geojson()]#group___geometry_writing_1gae4669b8ee598a46e7f4c5a11e645fe8f
- [tg_geom_wkt()]#group___geometry_writing_1ga047599bbe51886a6c3fbe35a6372d5d6
- [tg_geom_wkb()]#group___geometry_writing_1gac0938697f9270d1924c6746af68dd693
- [Geometry writing]#group___geometry_writing



<a name='group___geometry_constructors_ex_1ga1f4b592d4005fea6b9b49b35b0c15e74'></a>
## tg_geom_new_point_z()
```c
struct tg_geom *tg_geom_new_point_z(struct tg_point point, double z);
```
Creates a Point geometry that includes a Z coordinate. 

**Parameters**

- **point**: Input point
- **z**: The Z coordinate



**Return**

- A newly allocated geometry, or NULL if system is out of memory. The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga68013f90e62307ef0245e8e3398eeda6'></a>
## tg_geom_new_point_m()
```c
struct tg_geom *tg_geom_new_point_m(struct tg_point point, double m);
```
Creates a Point geometry that includes an M coordinate. 

**Parameters**

- **point**: Input point
- **m**: The M coordinate



**Return**

- A newly allocated geometry, or NULL if system is out of memory. The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga74f8f3f07973ec99af27950735d8bb30'></a>
## tg_geom_new_point_zm()
```c
struct tg_geom *tg_geom_new_point_zm(struct tg_point point, double z, double m);
```
Creates a Point geometry that includes a Z and M coordinates. 

**Parameters**

- **point**: Input point
- **z**: The Z coordinate
- **m**: The M coordinate



**Return**

- A newly allocated geometry, or NULL if system is out of memory. The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga64d9a692f5f8d7d5ba37fd0b5abdb9a3'></a>
## tg_geom_new_point_empty()
```c
struct tg_geom *tg_geom_new_point_empty();
```
Creates an empty Point geometry. 

**Return**

- A newly allocated geometry, or NULL if system is out of memory. The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga5b16e072effa305db633265277852a97'></a>
## tg_geom_new_linestring_z()
```c
struct tg_geom *tg_geom_new_linestring_z(const struct tg_line *line, const double *extra_coords, int ncoords);
```
Creates a LineString geometry that includes Z coordinates. 

**Parameters**

- **line**: Input line, caller retains ownership.
- **coords**: Array of doubles representing each Z coordinate, caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga1141d62a61f6aef6342e02bf930123c0'></a>
## tg_geom_new_linestring_m()
```c
struct tg_geom *tg_geom_new_linestring_m(const struct tg_line *line, const double *extra_coords, int ncoords);
```
Creates a LineString geometry that includes M coordinates. 

**Parameters**

- **line**: Input line, caller retains ownership.
- **coords**: Array of doubles representing each M coordinate, caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1gaf7f088fd78eb1340fd91a46f4225d234'></a>
## tg_geom_new_linestring_zm()
```c
struct tg_geom *tg_geom_new_linestring_zm(const struct tg_line *line, const double *extra_coords, int ncoords);
```
Creates a LineString geometry that includes ZM coordinates. 

**Parameters**

- **line**: Input line, caller retains ownership.
- **coords**: Array of doubles representing each Z and M coordinate, interleaved. Caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1gadbd7a00e18648a3430bf89118448db58'></a>
## tg_geom_new_linestring_empty()
```c
struct tg_geom *tg_geom_new_linestring_empty();
```
Creates an empty LineString geometry. 

**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1gac81514f9acbafce335d8982233772664'></a>
## tg_geom_new_polygon_z()
```c
struct tg_geom *tg_geom_new_polygon_z(const struct tg_poly *poly, const double *extra_coords, int ncoords);
```
Creates a Polygon geometry that includes Z coordinates. 

**Parameters**

- **poly**: Input polygon, caller retains ownership.
- **coords**: Array of doubles representing each Z coordinate, caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1gaf8a608082f6310107d029f25be660991'></a>
## tg_geom_new_polygon_m()
```c
struct tg_geom *tg_geom_new_polygon_m(const struct tg_poly *poly, const double *extra_coords, int ncoords);
```
Creates a Polygon geometry that includes M coordinates. 

**Parameters**

- **poly**: Input polygon, caller retains ownership.
- **coords**: Array of doubles representing each M coordinate, caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga5b2cbc15b3780925a1cfa05da25e0285'></a>
## tg_geom_new_polygon_zm()
```c
struct tg_geom *tg_geom_new_polygon_zm(const struct tg_poly *poly, const double *extra_coords, int ncoords);
```
Creates a Polygon geometry that includes ZM coordinates. 

**Parameters**

- **poly**: Input polygon, caller retains ownership.
- **coords**: Array of doubles representing each Z and M coordinate, interleaved. Caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga72b1cb66d57ec21a4aef558cd64b647e'></a>
## tg_geom_new_polygon_empty()
```c
struct tg_geom *tg_geom_new_polygon_empty();
```
Creates an empty Polygon geometry. 

**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1gad7609eb5456dfb084ee7d2ab0637db82'></a>
## tg_geom_new_multipoint_z()
```c
struct tg_geom *tg_geom_new_multipoint_z(const struct tg_point *points, int npoints, const double *extra_coords, int ncoords);
```
Creates a MultiPoint geometry that includes Z coordinates. 

**Parameters**

- **points**: An array of points, caller retains ownership.
- **npoints**: The number of points in array
- **coords**: Array of doubles representing each Z coordinate, caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1gaae2123bcb6b30a5efeae422ac4a4aec6'></a>
## tg_geom_new_multipoint_m()
```c
struct tg_geom *tg_geom_new_multipoint_m(const struct tg_point *points, int npoints, const double *extra_coords, int ncoords);
```
Creates a MultiPoint geometry that includes M coordinates. 

**Parameters**

- **points**: An array of points, caller retains ownership.
- **npoints**: The number of points in array
- **coords**: Array of doubles representing each M coordinate, caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga772ab89b63583177d537615f1bd2adb5'></a>
## tg_geom_new_multipoint_zm()
```c
struct tg_geom *tg_geom_new_multipoint_zm(const struct tg_point *points, int npoints, const double *extra_coords, int ncoords);
```
Creates a MultiPoint geometry that includes ZM coordinates. 

**Parameters**

- **points**: An array of points, caller retains ownership.
- **npoints**: The number of points in array
- **coords**: Array of doubles representing each Z and M coordinate, interleaved. Caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga967114d5e9332630c7f99ac6a116991d'></a>
## tg_geom_new_multipoint_empty()
```c
struct tg_geom *tg_geom_new_multipoint_empty();
```
Creates an empty MultiPoint geometry. 

**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga9a855e4d8aeb386b3fcdf2f35da4bb53'></a>
## tg_geom_new_multilinestring_z()
```c
struct tg_geom *tg_geom_new_multilinestring_z(const struct tg_line *const lines[], int nlines, const double *extra_coords, int ncoords);
```
Creates a MultiLineString geometry that includes Z coordinates. 

**Parameters**

- **lines**: An array of lines, caller retains ownership.
- **nlines**: The number of lines in array
- **coords**: Array of doubles representing each Z coordinate, caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1gad53b72d80be834a14a9a47d0953f08c3'></a>
## tg_geom_new_multilinestring_m()
```c
struct tg_geom *tg_geom_new_multilinestring_m(const struct tg_line *const lines[], int nlines, const double *extra_coords, int ncoords);
```
Creates a MultiLineString geometry that includes M coordinates. 

**Parameters**

- **lines**: An array of lines, caller retains ownership.
- **nlines**: The number of lines in array
- **coords**: Array of doubles representing each M coordinate, caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga5ff87656da4c72c947cef312acb50ef1'></a>
## tg_geom_new_multilinestring_zm()
```c
struct tg_geom *tg_geom_new_multilinestring_zm(const struct tg_line *const lines[], int nlines, const double *extra_coords, int ncoords);
```
Creates a MultiLineString geometry that includes ZM coordinates. 

**Parameters**

- **lines**: An array of lines, caller retains ownership.
- **nlines**: The number of lines in array
- **coords**: Array of doubles representing each Z and M coordinate, interleaved. Caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga2798822f3fdb20132a6cc6ad2247fae4'></a>
## tg_geom_new_multilinestring_empty()
```c
struct tg_geom *tg_geom_new_multilinestring_empty();
```
Creates an empty MultiLineString geometry. 

**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga46c67962e6d151e46cc961a76e90941c'></a>
## tg_geom_new_multipolygon_z()
```c
struct tg_geom *tg_geom_new_multipolygon_z(const struct tg_poly *const polys[], int npolys, const double *extra_coords, int ncoords);
```
Creates a MultiPolygon geometry that includes Z coordinates. 

**Parameters**

- **polys**: An array of polygons, caller retains ownership.
- **npolys**: The number of polygons in array
- **coords**: Array of doubles representing each Z coordinate, caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga824ac7a05f0cc5e4a74d9335f23954a0'></a>
## tg_geom_new_multipolygon_m()
```c
struct tg_geom *tg_geom_new_multipolygon_m(const struct tg_poly *const polys[], int npolys, const double *extra_coords, int ncoords);
```
Creates a MultiPolygon geometry that includes M coordinates. 

**Parameters**

- **polys**: An array of polygons, caller retains ownership.
- **npolys**: The number of polygons in array
- **coords**: Array of doubles representing each M coordinate, caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga998ef169fc03e82c75fe32757b057334'></a>
## tg_geom_new_multipolygon_zm()
```c
struct tg_geom *tg_geom_new_multipolygon_zm(const struct tg_poly *const polys[], int npolys, const double *extra_coords, int ncoords);
```
Creates a MultiPolygon geometry that includes ZM coordinates. 

**Parameters**

- **polys**: An array of polygons, caller retains ownership.
- **npolys**: The number of polygons in array
- **coords**: Array of doubles representing each Z and M coordinate, interleaved. Caller retains ownership.
- **ncoords**: Number of doubles in array.



**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga48684027f9beb519c52575bf6754a6f8'></a>
## tg_geom_new_multipolygon_empty()
```c
struct tg_geom *tg_geom_new_multipolygon_empty();
```
Creates an empty MultiPolygon geometry. 

**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___geometry_constructors_ex_1ga15fc542f3f6b4bb4dc7e91d554e0dfff'></a>
## tg_geom_new_geometrycollection_empty()
```c
struct tg_geom *tg_geom_new_geometrycollection_empty();
```
Creates an empty GeometryCollection geometry. 

**Return**

- A newly allocated geometry.
- NULL if system is out of memory.


**Note**

- The caller is responsible for freeing with [tg_geom_free()]#group___geometry_constructors_1gaf6f400f624b9f3e9052ac26ab17d72ae.


**See also**

- [Geometry with alternative dimensions]#group___geometry_constructors_ex



<a name='group___point_funcs_1ga07ff1afb45368e2f511da5cb8e689943'></a>
## tg_point_rect()
```c
struct tg_rect tg_point_rect(struct tg_point point);
```
Returns the minimum bounding rectangle of a point. 

**See also**

- [Point functions]#group___point_funcs



<a name='group___point_funcs_1ga59e99021c916a5fe7a350aee695ef6d3'></a>
## tg_point_intersects_rect()
```c
bool tg_point_intersects_rect(struct tg_point a, struct tg_rect b);
```
Tests whether a point fully intersects a rectangle. 

**See also**

- [Point functions]#group___point_funcs



<a name='group___segment_funcs_1ga8218b7694fe5079da6ce0a241991cf78'></a>
## tg_segment_rect()
```c
struct tg_rect tg_segment_rect(struct tg_segment s);
```
Returns the minimum bounding rectangle of a segment. 

**See also**

- [Segment functions]#group___segment_funcs



<a name='group___segment_funcs_1ga12b1ec6c72d4120391daff364d5c7b9b'></a>
## tg_segment_intersects_segment()
```c
bool tg_segment_intersects_segment(struct tg_segment a, struct tg_segment b);
```
Tests whether a segment intersects another segment. 

**See also**

- [Segment functions]#group___segment_funcs



<a name='group___rect_funcs_1gadc227cfc279d612269a142841d736c79'></a>
## tg_rect_expand()
```c
struct tg_rect tg_rect_expand(struct tg_rect rect, struct tg_rect other);
```
Expands a rectangle to include an additional rectangle. 

**Parameters**

- **rect**: Input rectangle
- **other**: Input rectangle



**Return**

- Expanded rectangle


**See also**

- [Rectangle functions]#group___rect_funcs



<a name='group___rect_funcs_1gaad0df238f6f430d9cc6fd6b0c6807931'></a>
## tg_rect_expand_point()
```c
struct tg_rect tg_rect_expand_point(struct tg_rect rect, struct tg_point point);
```
Expands a rectangle to include an additional point. 

**Parameters**

- **rect**: Input rectangle
- **point**: Input Point



**Return**

- Expanded rectangle


**See also**

- [Rectangle functions]#group___rect_funcs



<a name='group___rect_funcs_1ga44be4970fbbbdfa9e2ceb338a938d262'></a>
## tg_rect_center()
```c
struct tg_point tg_rect_center(struct tg_rect rect);
```
Returns the center point of a rectangle 

**See also**

- [Rectangle functions]#group___rect_funcs



<a name='group___rect_funcs_1ga910f2b37e7c7b17f9c01bbddee871b11'></a>
## tg_rect_intersects_rect()
```c
bool tg_rect_intersects_rect(struct tg_rect a, struct tg_rect b);
```
Tests whether a rectangle intersects another rectangle. 

**See also**

- [Rectangle functions]#group___rect_funcs



<a name='group___rect_funcs_1gac4d6e61cc5260ed913c736fd71defe05'></a>
## tg_rect_intersects_point()
```c
bool tg_rect_intersects_point(struct tg_rect a, struct tg_point b);
```
Tests whether a rectangle and a point intersect. 

**See also**

- [Rectangle functions]#group___rect_funcs



<a name='group___ring_funcs_1ga7defe1b6d43be8285a73f7977b342661'></a>
## tg_ring_new()
```c
struct tg_ring *tg_ring_new(const struct tg_point *points, int npoints);
```
Creates a ring from a series of points. 

**Parameters**

- **points**: Array of points
- **npoints**: Number of points in array



**Return**

- A newly allocated ring
- NULL if out of memory


**Note**

- A [tg_ring]#structtg__ring can be safely upcasted to a [tg_geom]#structtg__geom. `(struct tg_geom*)ring`
- A [tg_ring]#structtg__ring can be safely upcasted to a [tg_poly]#structtg__poly. `(struct tg_poly*)ring`
- All rings with 32 or more points are automatically indexed.


**See also**

- [tg_ring_new_ix()]#group___ring_funcs_1ga9a154a6a8dc4beaf7758ef39b21c1ce8
- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1ga9a154a6a8dc4beaf7758ef39b21c1ce8'></a>
## tg_ring_new_ix()
```c
struct tg_ring *tg_ring_new_ix(const struct tg_point *points, int npoints, enum tg_index ix);
```
Creates a ring from a series of points using provided index option. 

**Parameters**

- **points**: Array of points
- **npoints**: Number of points in array
- **ix**: Indexing option, e.g. TG_NONE, TG_NATURAL, TG_YSTRIPES



**Return**

- A newly allocated ring
- NULL if out of memory


**Note**

- A [tg_ring]#structtg__ring can be safely upcasted to a [tg_geom]#structtg__geom. `(struct tg_geom*)ring`
- A [tg_ring]#structtg__ring can be safely upcasted to a [tg_poly]#structtg__poly. `(struct tg_poly*)ring`


**See also**

- [tg_ring_new()]#group___ring_funcs_1ga7defe1b6d43be8285a73f7977b342661
- [tg_index].#tg_index
- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1ga51e9d824d50f67f89981f0edc7fe0cc5'></a>
## tg_ring_free()
```c
void tg_ring_free(struct tg_ring *ring);
```
Releases the memory associated with a ring. 

**Parameters**

- **ring**: Input ring



**See also**

- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1gafda24e3f1274ae1f1421934722cfd67b'></a>
## tg_ring_clone()
```c
struct tg_ring *tg_ring_clone(const struct tg_ring *ring);
```
Clones a ring 

**Parameters**

- **ring**: Input ring, caller retains ownership.



**Return**

- A duplicate of the provided ring.


**Note**

- The caller is responsible for freeing with [tg_ring_free()]#group___ring_funcs_1ga51e9d824d50f67f89981f0edc7fe0cc5.
- This method of cloning uses implicit sharing through an atomic reference counter.


**See also**

- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1gaaa7b50bc974357abe9d67ec8d6ca0d91'></a>
## tg_ring_copy()
```c
struct tg_ring *tg_ring_copy(const struct tg_ring *ring);
```
Copies a ring 

**Parameters**

- **ring**: Input ring, caller retains ownership.



**Return**

- A duplicate of the provided ring.
- NULL if out of memory


**Note**

- The caller is responsible for freeing with [tg_ring_free()]#group___ring_funcs_1ga51e9d824d50f67f89981f0edc7fe0cc5.
- This method performs a deep copy of the entire geometry to new memory.


**See also**

- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1ga0f146af1880d1ed7d02bfbdd0298feac'></a>
## tg_ring_memsize()
```c
size_t tg_ring_memsize(const struct tg_ring *ring);
```
Returns the allocation size of the ring. 

**Parameters**

- **ring**: Input ring



**Return**

- Size of ring in bytes


**See also**

- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1ga64086c935039b1f0fcd8633be763427d'></a>
## tg_ring_rect()
```c
struct tg_rect tg_ring_rect(const struct tg_ring *ring);
```
Returns the minimum bounding rectangle of a rect. 

**Parameters**

- **ring**: Input ring



**Return**

- Minimum bounding retangle


**See also**

- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1ga2437033fd4a6d67a54ce2cf1f771b66c'></a>
## tg_ring_num_points()
```c
int tg_ring_num_points(const struct tg_ring *ring);
```
Returns the number of points. 

**Parameters**

- **ring**: Input ring



**Return**

- Number of points


**See also**

- [tg_ring_point_at()]#group___ring_funcs_1gad2450a013edd99a013dbaee437fb0c3d
- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1gad2450a013edd99a013dbaee437fb0c3d'></a>
## tg_ring_point_at()
```c
struct tg_point tg_ring_point_at(const struct tg_ring *ring, int index);
```
Returns the point at index. 

**Parameters**

- **ring**: Input ring
- **index**: Index of point



**Return**

- The point at index


**Note**

- This function performs bounds checking. Use [tg_ring_points()]#group___ring_funcs_1gaf97a197de54c13d01aa9d983115a336d for direct access to the points.


**See also**

- [tg_ring_num_points()]#group___ring_funcs_1ga2437033fd4a6d67a54ce2cf1f771b66c
- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1gaf97a197de54c13d01aa9d983115a336d'></a>
## tg_ring_points()
```c
const struct tg_point *tg_ring_points(const struct tg_ring *ring);
```
Returns the underlying point array of a ring. 

**Parameters**

- **ring**: Input ring



**Return**

- Array or points


**See also**

- [tg_ring_num_points()]#group___ring_funcs_1ga2437033fd4a6d67a54ce2cf1f771b66c
- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1ga56dcd7ca3d210696979c3c6c62d71690'></a>
## tg_ring_num_segments()
```c
int tg_ring_num_segments(const struct tg_ring *ring);
```
Returns the number of segments. 

**Parameters**

- **ring**: Input ring



**Return**

- Number of segments


**See also**

- [tg_ring_segment_at()]#group___ring_funcs_1ga52b3ba9138aee4245fca05bedd00801d
- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1ga52b3ba9138aee4245fca05bedd00801d'></a>
## tg_ring_segment_at()
```c
struct tg_segment tg_ring_segment_at(const struct tg_ring *ring, int index);
```
Returns the segment at index. 

**Parameters**

- **ring**: Input ring
- **index**: Index of segment



**Return**

- The segment at index


**See also**

- [tg_ring_num_segments()]#group___ring_funcs_1ga56dcd7ca3d210696979c3c6c62d71690
- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1ga2559c1e9f0a3b48d97b36010ac424703'></a>
## tg_ring_convex()
```c
bool tg_ring_convex(const struct tg_ring *ring);
```
Returns true if ring is convex. 

**Parameters**

- **ring**: Input ring



**Return**

- True if ring is convex.
- False if ring is concave.


**See also**

- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1gae677767bd4bc40480f0a703e78f2e713'></a>
## tg_ring_clockwise()
```c
bool tg_ring_clockwise(const struct tg_ring *ring);
```
Returns true if winding order is clockwise. 

**Parameters**

- **ring**: Input ring



**Return**

- True if clockwise
- False if counter-clockwise


**See also**

- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1gacecc3997e0cabb5532946acffee834f0'></a>
## tg_ring_index_spread()
```c
int tg_ring_index_spread(const struct tg_ring *ring);
```
Returns the indexing spread for a ring.

The "spread" is the number of segments or rectangles that are grouped together to produce a unioned rectangle that is stored at a higher level.

For a tree based structure, this would be the number of items per node.



**Parameters**

- **ring**: Input ring



**Return**

- The spread, default is 16
- Zero if ring has no indexing


**See also**

- [tg_ring_index_num_levels()]#group___ring_funcs_1ga1bbaf39cc96d727f253c0f66c0ede4e4
- [tg_ring_index_level_num_rects()]#group___ring_funcs_1ga292a911cdb05f7dbc19bcbd031226deb
- [tg_ring_index_level_rect()]#group___ring_funcs_1ga7eab00bc99a6f4148d2e6ced95ff24c3
- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1ga1bbaf39cc96d727f253c0f66c0ede4e4'></a>
## tg_ring_index_num_levels()
```c
int tg_ring_index_num_levels(const struct tg_ring *ring);
```
Returns the number of levels. 

**Parameters**

- **ring**: Input ring



**Return**

- The number of levels
- Zero if ring has no indexing


**See also**

- [tg_ring_index_spread()]#group___ring_funcs_1gacecc3997e0cabb5532946acffee834f0
- [tg_ring_index_level_num_rects()]#group___ring_funcs_1ga292a911cdb05f7dbc19bcbd031226deb
- [tg_ring_index_level_rect()]#group___ring_funcs_1ga7eab00bc99a6f4148d2e6ced95ff24c3
- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1ga292a911cdb05f7dbc19bcbd031226deb'></a>
## tg_ring_index_level_num_rects()
```c
int tg_ring_index_level_num_rects(const struct tg_ring *ring, int levelidx);
```
Returns the number of rectangles at level. 

**Parameters**

- **ring**: Input ring
- **levelidx**: The index of level



**Return**

- The number of index levels
- Zero if ring has no indexing or levelidx is out of bounds.


**See also**

- [tg_ring_index_spread()]#group___ring_funcs_1gacecc3997e0cabb5532946acffee834f0
- [tg_ring_index_num_levels()]#group___ring_funcs_1ga1bbaf39cc96d727f253c0f66c0ede4e4
- [tg_ring_index_level_rect()]#group___ring_funcs_1ga7eab00bc99a6f4148d2e6ced95ff24c3
- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1ga7eab00bc99a6f4148d2e6ced95ff24c3'></a>
## tg_ring_index_level_rect()
```c
struct tg_rect tg_ring_index_level_rect(const struct tg_ring *ring, int levelidx, int rectidx);
```
Returns a specific level rectangle. 

**Parameters**

- **ring**: Input ring
- **levelidx**: The index of level
- **rectidx**: The index of rectangle



**Return**

- The rectangle
- Empty rectangle if ring has no indexing, or levelidx or rectidx is out of bounds.


**See also**

- [tg_ring_index_spread()]#group___ring_funcs_1gacecc3997e0cabb5532946acffee834f0
- [tg_ring_index_num_levels()]#group___ring_funcs_1ga1bbaf39cc96d727f253c0f66c0ede4e4
- [tg_ring_index_level_num_rects()]#group___ring_funcs_1ga292a911cdb05f7dbc19bcbd031226deb
- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1ga716e10054b4bda84efb259d57aff5015'></a>
## tg_ring_nearest_segment()
```c
bool tg_ring_nearest_segment(const struct tg_ring *ring, double(*rect_dist)(struct tg_rect rect, int *more, void *udata), double(*seg_dist)(struct tg_segment seg, int *more, void *udata), bool(*iter)(struct tg_segment seg, double dist, int index, void *udata), void *udata);
```
Iterates over segments from nearest to farthest.

This is a kNN operation. The caller must provide their own "rect_dist" and "seg_dist" callbacks to do the actual distance calculations.



**Parameters**

- **ring**: Input ring
- **rect_dist**: Callback that returns the distance to a [tg_rect]#structtg__rect.
- **seg_dist**: Callback that returns the distance to a [tg_segment]#structtg__segment.
- **iter**: Callback that returns each segment in the ring in order of nearest to farthest. Caller must return true to continue to the next segment, or return false to stop iterating.
- **udata**: User-defined data



**Return**

- True if operation succeeded, false if out of memory.


**Note**

- Though not typical, this operation may need to allocate memory. It's recommended to check the return value for success.
- The `*more` argument is an optional ref-value that is used for performing partial step-based or probability-based calculations. A detailed description of its use is outside the scope of this document. Ignoring it altogether is the preferred behavior.


**See also**

- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1gabee40f4a66c2ebb4516a9f980ff5d998'></a>
## tg_ring_line_search()
```c
void tg_ring_line_search(const struct tg_ring *a, const struct tg_line *b, bool(*iter)(struct tg_segment aseg, int aidx, struct tg_segment bseg, int bidx, void *udata), void *udata);
```
Iterates over all segments in ring A that intersect with segments in line B. 

**Note**

- This efficently uses the indexes of each geometry, if available.


**See also**

- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1gacd2c483213d8110c9373e8e47bd9f49e'></a>
## tg_ring_ring_search()
```c
void tg_ring_ring_search(const struct tg_ring *a, const struct tg_ring *b, bool(*iter)(struct tg_segment aseg, int aidx, struct tg_segment bseg, int bidx, void *udata), void *udata);
```
Iterates over all segments in ring A that intersect with segments in ring B. 

**Note**

- This efficently uses the indexes of each geometry, if available.


**See also**

- [Ring functions]#group___ring_funcs



<a name='group___ring_funcs_1gabe14408b3ad596ed14b4ce698c2e7826'></a>
## tg_ring_area()
```c
double tg_ring_area(const struct tg_ring *ring);
```
Calculate the area of a ring. 


<a name='group___ring_funcs_1ga0d063ecfef895e21f6d7520db05d302e'></a>
## tg_ring_perimeter()
```c
double tg_ring_perimeter(const struct tg_ring *ring);
```
Calculate the perimeter length of a ring. 


<a name='group___line_funcs_1ga7f834a7213c8d87d8b7c7117bdf8bf63'></a>
## tg_line_new()
```c
struct tg_line *tg_line_new(const struct tg_point *points, int npoints);
```
Creates a line from a series of points. 

**Parameters**

- **points**: Array of points
- **npoints**: Number of points in array



**Return**

- A newly allocated line
- NULL if out of memory


**Note**

- A [tg_line]#structtg__line can be safely upcasted to a [tg_geom]#structtg__geom. `(struct tg_geom*)line`
- All lines with 32 or more points are automatically indexed.


**See also**

- [Line functions]#group___line_funcs



<a name='group___line_funcs_1ga4057ac4ba72aa24985d947fa0ba42c19'></a>
## tg_line_new_ix()
```c
struct tg_line *tg_line_new_ix(const struct tg_point *points, int npoints, enum tg_index ix);
```
Creates a line from a series of points using provided index option. 

**Parameters**

- **points**: Array of points
- **npoints**: Number of points in array
- **ix**: Indexing option, e.g. TG_NONE, TG_NATURAL, TG_YSTRIPES



**Return**

- A newly allocated line
- NULL if out of memory


**Note**

- A [tg_line]#structtg__line can be safely upcasted to a [tg_geom]#structtg__geom. `(struct tg_geom*)poly`


**See also**

- [tg_index].#tg_index
- [Line functions]#group___line_funcs



<a name='group___line_funcs_1ga13b2a0ed2014525d613c25c9232affd7'></a>
## tg_line_free()
```c
void tg_line_free(struct tg_line *line);
```
Releases the memory associated with a line. 

**Parameters**

- **line**: Input line



**See also**

- [Line functions]#group___line_funcs



<a name='group___line_funcs_1gac7cbf109cca2dffba781a47932e1411d'></a>
## tg_line_clone()
```c
struct tg_line *tg_line_clone(const struct tg_line *line);
```
Clones a line 

**Parameters**

- **line**: Input line, caller retains ownership.



**Return**

- A duplicate of the provided line.


**Note**

- The caller is responsible for freeing with [tg_line_free()]#group___line_funcs_1ga13b2a0ed2014525d613c25c9232affd7.
- This method of cloning uses implicit sharing through an atomic reference counter.


**See also**

- [Line functions]#group___line_funcs



<a name='group___line_funcs_1ga3a5d0aac59658eb2cfd8cdaea8ebf22f'></a>
## tg_line_copy()
```c
struct tg_line *tg_line_copy(const struct tg_line *line);
```
Copies a line 

**Parameters**

- **line**: Input line, caller retains ownership.



**Return**

- A duplicate of the provided line.
- NULL if out of memory


**Note**

- The caller is responsible for freeing with [tg_line_free()]#group___line_funcs_1ga13b2a0ed2014525d613c25c9232affd7.
- This method performs a deep copy of the entire geometry to new memory.


**See also**

- [Line functions]#group___line_funcs



<a name='group___line_funcs_1ga6c2476d9dd302a3dea68aa44e7241ab1'></a>
## tg_line_memsize()
```c
size_t tg_line_memsize(const struct tg_line *line);
```
Returns the allocation size of the line. 

**Parameters**

- **line**: Input line



**Return**

- Size of line in bytes


**See also**

- [Line functions]#group___line_funcs



<a name='group___line_funcs_1ga2e59f4517937e89ae69ac6c1f12bf797'></a>
## tg_line_rect()
```c
struct tg_rect tg_line_rect(const struct tg_line *line);
```
Returns the minimum bounding rectangle of a line. 

**See also**

- [Line functions]#group___line_funcs



<a name='group___line_funcs_1gab4483ad3c5418dd9674b1f03498d18e6'></a>
## tg_line_num_points()
```c
int tg_line_num_points(const struct tg_line *line);
```
Returns the number of points. 

**Parameters**

- **line**: Input line



**Return**

- Number of points


**See also**

- [tg_line_point_at()]#group___line_funcs_1ga44955f7b0ee3bd13a33b24aeca01651a
- [Line functions]#group___line_funcs



<a name='group___line_funcs_1ga45a892019af11582b2761301526519d9'></a>
## tg_line_points()
```c
const struct tg_point *tg_line_points(const struct tg_line *line);
```
Returns the underlying point array of a line. 

**Parameters**

- **line**: Input line



**Return**

- Array or points


**See also**

- [tg_line_num_points()]#group___line_funcs_1gab4483ad3c5418dd9674b1f03498d18e6
- [Line functions]#group___line_funcs



<a name='group___line_funcs_1ga44955f7b0ee3bd13a33b24aeca01651a'></a>
## tg_line_point_at()
```c
struct tg_point tg_line_point_at(const struct tg_line *line, int index);
```
Returns the point at index. 

**Parameters**

- **line**: Input line
- **index**: Index of point



**Return**

- The point at index


**Note**

- This function performs bounds checking. Use [tg_line_points()]#group___line_funcs_1ga45a892019af11582b2761301526519d9 for direct access to the points.


**See also**

- [tg_line_num_points()]#group___line_funcs_1gab4483ad3c5418dd9674b1f03498d18e6
- [Line functions]#group___line_funcs



<a name='group___line_funcs_1gadb56b68cc4ce05cfa832e82e45995687'></a>
## tg_line_num_segments()
```c
int tg_line_num_segments(const struct tg_line *line);
```
Returns the number of segments. 

**Parameters**

- **line**: Input line



**Return**

- Number of segments


**See also**

- [tg_line_segment_at()]#group___line_funcs_1gad0c0982aff76d943f0ce50deb0f9183d
- [Line functions]#group___line_funcs



<a name='group___line_funcs_1gad0c0982aff76d943f0ce50deb0f9183d'></a>
## tg_line_segment_at()
```c
struct tg_segment tg_line_segment_at(const struct tg_line *line, int index);
```
Returns the segment at index. 

**Parameters**

- **line**: Input line
- **index**: Index of segment



**Return**

- The segment at index


**See also**

- [tg_line_num_segments()]#group___line_funcs_1gadb56b68cc4ce05cfa832e82e45995687
- [Line functions]#group___line_funcs



<a name='group___line_funcs_1gaee0fcc56c7518fa81ebb3457d795ca49'></a>
## tg_line_clockwise()
```c
bool tg_line_clockwise(const struct tg_line *line);
```
Returns true if winding order is clockwise. 

**Parameters**

- **line**: Input line



**Return**

- True if clockwise
- False if counter-clockwise


**See also**

- [Line functions]#group___line_funcs



<a name='group___line_funcs_1ga8b851e64231b8b30f30a936cf35cde08'></a>
## tg_line_index_spread()
```c
int tg_line_index_spread(const struct tg_line *line);
```
Returns the indexing spread for a line.

The "spread" is the number of segments or rectangles that are grouped together to produce a unioned rectangle that is stored at a higher level.

For a tree based structure, this would be the number of items per node.



**Parameters**

- **line**: Input line



**Return**

- The spread, default is 16
- Zero if line has no indexing


**See also**

- [tg_line_index_num_levels()]#group___line_funcs_1ga0cbcfec6e6ab81f31a47cd542e32b778
- [tg_line_index_level_num_rects()]#group___line_funcs_1gab9d4afd57889a11179df01c1df26488b
- [tg_line_index_level_rect()]#group___line_funcs_1gacc18e4ddb48ccc717f61f298fd6ae970
- [Line functions]#group___line_funcs



<a name='group___line_funcs_1ga0cbcfec6e6ab81f31a47cd542e32b778'></a>
## tg_line_index_num_levels()
```c
int tg_line_index_num_levels(const struct tg_line *line);
```
Returns the number of levels. 

**Parameters**

- **line**: Input line



**Return**

- The number of levels
- Zero if line has no indexing


**See also**

- [tg_line_index_spread()]#group___line_funcs_1ga8b851e64231b8b30f30a936cf35cde08
- [tg_line_index_level_num_rects()]#group___line_funcs_1gab9d4afd57889a11179df01c1df26488b
- [tg_line_index_level_rect()]#group___line_funcs_1gacc18e4ddb48ccc717f61f298fd6ae970
- [Line functions]#group___line_funcs



<a name='group___line_funcs_1gab9d4afd57889a11179df01c1df26488b'></a>
## tg_line_index_level_num_rects()
```c
int tg_line_index_level_num_rects(const struct tg_line *line, int levelidx);
```
Returns the number of rectangles at level. 

**Parameters**

- **line**: Input line
- **levelidx**: The index of level



**Return**

- The number of index levels
- Zero if line has no indexing or levelidx is out of bounds.


**See also**

- [tg_line_index_spread()]#group___line_funcs_1ga8b851e64231b8b30f30a936cf35cde08
- [tg_line_index_num_levels()]#group___line_funcs_1ga0cbcfec6e6ab81f31a47cd542e32b778
- [tg_line_index_level_rect()]#group___line_funcs_1gacc18e4ddb48ccc717f61f298fd6ae970
- [Line functions]#group___line_funcs



<a name='group___line_funcs_1gacc18e4ddb48ccc717f61f298fd6ae970'></a>
## tg_line_index_level_rect()
```c
struct tg_rect tg_line_index_level_rect(const struct tg_line *line, int levelidx, int rectidx);
```
Returns a specific level rectangle. 

**Parameters**

- **line**: Input line
- **levelidx**: The index of level
- **rectidx**: The index of rectangle



**Return**

- The rectangle
- Empty rectangle if line has no indexing, or levelidx or rectidx is out of bounds.


**See also**

- [tg_line_index_spread()]#group___line_funcs_1ga8b851e64231b8b30f30a936cf35cde08
- [tg_line_index_num_levels()]#group___line_funcs_1ga0cbcfec6e6ab81f31a47cd542e32b778
- [tg_line_index_level_num_rects()]#group___line_funcs_1gab9d4afd57889a11179df01c1df26488b
- [Line functions]#group___line_funcs



<a name='group___line_funcs_1gaa85835e9619ba7d8557fda3335a0353a'></a>
## tg_line_nearest_segment()
```c
bool tg_line_nearest_segment(const struct tg_line *line, double(*rect_dist)(struct tg_rect rect, int *more, void *udata), double(*seg_dist)(struct tg_segment seg, int *more, void *udata), bool(*iter)(struct tg_segment seg, double dist, int index, void *udata), void *udata);
```
Iterates over segments from nearest to farthest. 

**See also**

- [tg_ring_nearest_segment()]#group___ring_funcs_1ga716e10054b4bda84efb259d57aff5015, which shares the same interface, for a detailed description.
- [Line functions]#group___line_funcs



<a name='group___line_funcs_1gafef8ca6e5381e93d4c4952343597c0e1'></a>
## tg_line_line_search()
```c
void tg_line_line_search(const struct tg_line *a, const struct tg_line *b, bool(*iter)(struct tg_segment aseg, int aidx, struct tg_segment bseg, int bidx, void *udata), void *udata);
```
Iterates over all segments in line A that intersect with segments in line B. 

**Note**

- This efficently uses the indexes of each geometry, if available.


**See also**

- [Line functions]#group___line_funcs



<a name='group___line_funcs_1ga994796f0088c82bb0672d84f1a1ce9d1'></a>
## tg_line_length()
```c
double tg_line_length(const struct tg_line *line);
```
Calculate the length of a line. 


<a name='group___poly_funcs_1ga56c2615488ca202baa944c85c20a40f1'></a>
## tg_poly_new()
```c
struct tg_poly *tg_poly_new(const struct tg_ring *exterior, const struct tg_ring *const holes[], int nholes);
```
Creates a polygon. 

**Parameters**

- **exterior**: Exterior ring
- **holes**: Array of interior rings that are holes
- **nholes**: Number of holes in array



**Return**

- A newly allocated polygon
- NULL if out of memory
- NULL if exterior or any holes are NULL


**Note**

- A [tg_poly]#structtg__poly can be safely upcasted to a [tg_geom]#structtg__geom. `(struct tg_geom*)poly`


**See also**

- [Polygon functions]#group___poly_funcs



<a name='group___poly_funcs_1ga7a591cc2298e4e24ae0e99b055a61fed'></a>
## tg_poly_free()
```c
void tg_poly_free(struct tg_poly *poly);
```
Releases the memory associated with a polygon. 

**Parameters**

- **poly**: Input polygon



**See also**

- [Polygon functions]#group___poly_funcs



<a name='group___poly_funcs_1ga2f01b5838bcb3669e3aacace12062fbf'></a>
## tg_poly_clone()
```c
struct tg_poly *tg_poly_clone(const struct tg_poly *poly);
```
Clones a polygon. 

**Parameters**

- **poly**: Input polygon, caller retains ownership.



**Return**

- A duplicate of the provided polygon.


**Note**

- The caller is responsible for freeing with [tg_poly_free()]#group___poly_funcs_1ga7a591cc2298e4e24ae0e99b055a61fed.
- This method of cloning uses implicit sharing through an atomic reference counter.


**See also**

- [Polygon functions]#group___poly_funcs



<a name='group___poly_funcs_1gae68cadbe9ae2fa26c92f010958c6ed11'></a>
## tg_poly_copy()
```c
struct tg_poly *tg_poly_copy(const struct tg_poly *poly);
```
Copies a polygon. 

**Parameters**

- **poly**: Input polygon, caller retains ownership.



**Return**

- A duplicate of the provided polygon.
- NULL if out of memory


**Note**

- The caller is responsible for freeing with [tg_poly_free()]#group___poly_funcs_1ga7a591cc2298e4e24ae0e99b055a61fed.
- This method performs a deep copy of the entire geometry to new memory.


**See also**

- [Polygon functions]#group___poly_funcs



<a name='group___poly_funcs_1gabccc5c197d02868b9d24df7b7cabeea4'></a>
## tg_poly_memsize()
```c
size_t tg_poly_memsize(const struct tg_poly *poly);
```
Returns the allocation size of the polygon. 

**Parameters**

- **poly**: Input polygon



**Return**

- Size of polygon in bytes


**See also**

- [Polygon functions]#group___poly_funcs



<a name='group___poly_funcs_1ga802bb035aa8b2efd234973b98eefb128'></a>
## tg_poly_exterior()
```c
const struct tg_ring *tg_poly_exterior(const struct tg_poly *poly);
```
Returns the exterior ring. 

**Parameters**

- **poly**: Input polygon



**Return**

- Exterior ring


**Note**

- The polygon maintains ownership of the exterior ring.


**See also**

- [Polygon functions]#group___poly_funcs



<a name='group___poly_funcs_1ga23934cf6af1048e2e4b06befef3f8c1f'></a>
## tg_poly_num_holes()
```c
int tg_poly_num_holes(const struct tg_poly *poly);
```
Returns the number of interior holes. 

**Parameters**

- **poly**: Input polygon



**Return**

- Number of holes


**See also**

- [tg_poly_hole_at()]#group___poly_funcs_1gad15090afe596c268858c65b5c5e47a73
- [Polygon functions]#group___poly_funcs



<a name='group___poly_funcs_1gad15090afe596c268858c65b5c5e47a73'></a>
## tg_poly_hole_at()
```c
const struct tg_ring *tg_poly_hole_at(const struct tg_poly *poly, int index);
```
Returns an interior hole. 

**Parameters**

- **poly**: Input polygon
- **index**: Index of hole



**Return**

- Ring hole


**See also**

- [tg_poly_num_holes()]#group___poly_funcs_1ga23934cf6af1048e2e4b06befef3f8c1f
- [Polygon functions]#group___poly_funcs



<a name='group___poly_funcs_1gaac2de96544c41331886fd2b48e11ba6d'></a>
## tg_poly_rect()
```c
struct tg_rect tg_poly_rect(const struct tg_poly *poly);
```
Returns the minimum bounding rectangle of a polygon. 

**See also**

- [Polygon functions]#group___poly_funcs



<a name='group___poly_funcs_1gac52d19818b926e8d9e70abb0e3889da8'></a>
## tg_poly_clockwise()
```c
bool tg_poly_clockwise(const struct tg_poly *poly);
```
Returns true if winding order is clockwise. 

**Parameters**

- **poly**: Input polygon



**Return**

- True if clockwise
- False if counter-clockwise


**See also**

- [Polygon functions]#group___poly_funcs



<a name='group___global_funcs_1gab1e1478a3870e90d6b5932f5e67a032b'></a>
## tg_env_set_allocator()
```c
void tg_env_set_allocator(void *(*malloc)(size_t), void *(*realloc)(void *, size_t), void(*free)(void *));
```
Allow for configuring a custom allocator.

This overrides the built-in malloc, realloc, and free functions for all TG operations. 

**Warning**

- This function, if needed, should be called **only once** at program start up and prior to calling any other tg_*() function.


**See also**

- [Global environment]#group___global_funcs



<a name='group___global_funcs_1ga57a922edb770400033043354c1f4e80e'></a>
## tg_env_set_index()
```c
void tg_env_set_index(enum tg_index ix);
```
Set the geometry indexing default.

This is a global override to the indexing for all yet-to-be created geometries. 

**Warning**

- This function, if needed, should be called **only once** at program start up and prior to calling any other tg_*() function.


**See also**

- [tg_index].#tg_index
- [tg_env_set_index()]#group___global_funcs_1ga57a922edb770400033043354c1f4e80e
- [Global environment]#group___global_funcs



<a name='group___global_funcs_1gaf9e9214a8db08c306fdb529192e9dd5f'></a>
## tg_env_set_index_spread()
```c
void tg_env_set_index_spread(int spread);
```
Set the default index spread.

The "spread" is how many rectangles are grouped together on an indexed level before propagating up to a higher level.

Default is 16.

This is a global override to the indexing spread for all yet-to-be created geometries. 

**Warning**

- This function, if needed, should be called **only once** at program start up and prior to calling any other tg_*() function.


**See also**

- [tg_index].#tg_index
- [tg_env_set_index()]#group___global_funcs_1ga57a922edb770400033043354c1f4e80e
- [About TG indexing]POLYGON_INDEXING.md
- [Global environment]#group___global_funcs



***

Generated with the help of [doxygen](https://www.doxygen.nl/index.html)