1 /**
2  *   SFCGAL
3  *
4  *   Copyright (C) 2012-2013 Oslandia <infos@oslandia.com>
5  *   Copyright (C) 2012-2013 IGN (http://www.ign.fr)
6  *
7  *   This library is free software; you can redistribute it and/or
8  *   modify it under the terms of the GNU Library General Public
9  *   License as published by the Free Software Foundation; either
10  *   version 2 of the License, or (at your option) any later version.
11  *
12  *   This library is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *   Library General Public License for more details.
16 
17  *   You should have received a copy of the GNU Library General Public
18  *   License along with this library; if not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef _SFCGAL_CAPI_H_
22 #define _SFCGAL_CAPI_H_
23 
24 #include <SFCGAL/config.h>
25 #include <stdint.h>
26 #include <stddef.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 // TODO : return of errors ! => error handler
33 
34 /**
35  *
36  * Minimal C API for SFCGAL
37  *
38  */
39 
40 /*--------------------------------------------------------------------------------------*
41  *
42  * Support for SFCGAL::Geometry class hierarchy
43  *
44  *--------------------------------------------------------------------------------------*/
45 
46 /**
47  * sfcgal_geometry_t is an opaque pointer type that is used to represent a pointer to SFCGAL::Geometry
48  * @ingroup capi
49  */
50 typedef void sfcgal_geometry_t;
51 
52 /**
53  * Geometric types
54  * @ingroup capi
55  */
56 typedef enum {
57     //     TYPE_GEOMETRY            = 0, //abstract
58     SFCGAL_TYPE_POINT               = 1,
59     SFCGAL_TYPE_LINESTRING          = 2,
60     SFCGAL_TYPE_POLYGON             = 3,
61     SFCGAL_TYPE_MULTIPOINT          = 4,
62     SFCGAL_TYPE_MULTILINESTRING     = 5,
63     SFCGAL_TYPE_MULTIPOLYGON        = 6,
64     SFCGAL_TYPE_GEOMETRYCOLLECTION  = 7,
65     //     TYPE_CIRCULARSTRING      = 8,
66     //     TYPE_COMPOUNDCURVE       = 9,
67     //     TYPE_CURVEPOLYGON        = 10,
68     //     TYPE_MULTICURVE          = 11, //abstract
69     //     TYPE_MULTISURFACE        = 12, //abstract
70     //     TYPE_CURVE               = 13, //abstract
71     //     TYPE_SURFACE             = 14, //abstract
72     SFCGAL_TYPE_POLYHEDRALSURFACE   = 15,
73     SFCGAL_TYPE_TRIANGULATEDSURFACE = 16,
74 
75     //-- not official codes
76     SFCGAL_TYPE_TRIANGLE            = 100, //17 in Wikipedia???
77     SFCGAL_TYPE_SOLID               = 101,
78     SFCGAL_TYPE_MULTISOLID          = 102
79 } sfcgal_geometry_type_t ;
80 
81 /**
82  * Set the geometry validation mode
83  * @ingroup capi
84  * @note obsolete
85  */
86 SFCGAL_API void                      sfcgal_set_geometry_validation( int enabled );
87 
88 /**
89  * Returns the type of a given geometry
90  * @ingroup capi
91  */
92 SFCGAL_API sfcgal_geometry_type_t    sfcgal_geometry_type_id( const sfcgal_geometry_t* );
93 
94 /**
95  * Tests if the given geometry is valid or not
96  * @ingroup capi
97  */
98 SFCGAL_API int                       sfcgal_geometry_is_valid( const sfcgal_geometry_t* );
99 
100 /**
101  * Tests if the given geometry is valid or not
102  * And return details in case of invalidity
103  * @param geom the input geometry
104  * @param invalidity_reason input/output parameter. If non null, a null-terminated string could be allocated and contain reason of the invalidity
105  * @param invalidity_location input/output parameter. If non null, a geometry could be allocated and contain the location of the invalidity
106  * @ingroup capi
107  */
108 SFCGAL_API int                       sfcgal_geometry_is_valid_detail( const sfcgal_geometry_t* geom, char** invalidity_reason, sfcgal_geometry_t** invalidity_location );
109 
110 /**
111  * Tests if the given geometry is 3D or not
112  * @ingroup capi
113  */
114 SFCGAL_API int                       sfcgal_geometry_is_3d( const sfcgal_geometry_t* );
115 
116 /**
117  * Tests if the given geometry is measured (has an m) or not
118  * @ingroup capi
119  */
120 SFCGAL_API int                       sfcgal_geometry_is_measured( const sfcgal_geometry_t* );
121 
122 /**
123  * Tests if the given geometry is empty or not
124  * @ingroup capi
125  */
126 SFCGAL_API int                       sfcgal_geometry_is_empty( const sfcgal_geometry_t* );
127 
128 /**
129  * Returns a deep clone of the given geometry
130  * @post returns a pointer to an allocated geometry that must be deallocated by @ref sfcgal_geometry_delete
131  * @ingroup capi
132  */
133 SFCGAL_API sfcgal_geometry_t*        sfcgal_geometry_clone( const sfcgal_geometry_t* );
134 
135 /**
136  * Deletes a given geometry
137  * @pre the given pointer must have been previously allocated by a creation function
138  * @ingroup capi
139  */
140 SFCGAL_API void                      sfcgal_geometry_delete( sfcgal_geometry_t* );
141 
142 /**
143  * Returns a WKT representation of the given geometry using CGAL exact integer fractions as coordinate values
144  * @post buffer is returned allocated and must be freed by the caller
145  * @ingroup capi
146  */
147 SFCGAL_API void                      sfcgal_geometry_as_text( const sfcgal_geometry_t*, char** buffer, size_t* len );
148 
149 /**
150  * Returns a WKT representation of the given geometry using floating point coordinate values.
151  * Floating point precision can be set via the numDecimals parameter.
152  * Setting numDecimals to -1 yields the same result as sfcgal_geometry_as_text.
153  * @post buffer is returned allocated and must be freed by the caller
154  * @ingroup capi
155  */
156 SFCGAL_API void                      sfcgal_geometry_as_text_decim( const sfcgal_geometry_t*, int numDecimals, char** buffer, size_t* len );
157 
158 /**
159  * Creates an empty point
160  * @ingroup capi
161  */
162 SFCGAL_API sfcgal_geometry_t*        sfcgal_point_create();
163 
164 /**
165  * Creates a point from two X and Y coordinates
166  * @ingroup capi
167  */
168 SFCGAL_API sfcgal_geometry_t*        sfcgal_point_create_from_xy( double x, double y );
169 
170 /**
171  * Creates a point from three X, Y and Z coordinates
172  * @ingroup capi
173  */
174 SFCGAL_API sfcgal_geometry_t*        sfcgal_point_create_from_xyz( double x, double y, double z );
175 
176 /**
177  * Returns the X coordinate of the given Point
178  * @pre the given geometry must be a Point
179  * @pre the given point must not be empty
180  * @ingroup capi
181  */
182 SFCGAL_API double                    sfcgal_point_x( const sfcgal_geometry_t* );
183 
184 /**
185  * Returns the Y coordinate of the given Point
186  * @pre the given geometry must be a Point
187  * @pre the given point must not be empty
188  * @ingroup capi
189  */
190 SFCGAL_API double                    sfcgal_point_y( const sfcgal_geometry_t* );
191 
192 /**
193  * Returns the Z coordinate of the given Point
194  * @pre the given geometry must be a Point
195  * @pre the given point must not be empty
196  * @post the Z coordinate can value NaN if the given point is 2D only
197  * @ingroup capi
198  */
199 SFCGAL_API double                    sfcgal_point_z( const sfcgal_geometry_t* );
200 
201 /**
202  * Returns the M coordinate of the given Point
203  * @pre the given geometry must be a Point
204  * @pre the given point must not be empty
205  * @post the M coordinate can value NaN if the given point has no m
206  * @ingroup capi
207  */
208 SFCGAL_API double                    sfcgal_point_m( const sfcgal_geometry_t* );
209 
210 /**
211  * Creates an empty LineString
212  * @ingroup capi
213  */
214 SFCGAL_API sfcgal_geometry_t*        sfcgal_linestring_create();
215 
216 /**
217  * Returns the number of points of the given LineString
218  * @pre linestring must be a LineString
219  * @ingroup capi
220  */
221 SFCGAL_API size_t                    sfcgal_linestring_num_points( const sfcgal_geometry_t* linestring );
222 
223 /**
224  * Returns the ith point of a given LineString
225  * @param i is the point index in the LineString
226  * @pre linestring must be a LineString
227  * @pre i >= and i < sfcgal_linestring_num_points
228  * @post the returned Point is not writable and must not be deallocated by the caller
229  * @ingroup capi
230  */
231 SFCGAL_API const sfcgal_geometry_t*  sfcgal_linestring_point_n( const sfcgal_geometry_t* linestring, size_t i );
232 
233 /**
234  * Adds a point to a LineString
235  * @param linestring is the LineString where the Point has to be added to
236  * @param point is the Point to add to the given LineString
237  * @pre i >= and i < sfcgal_linestring_num_points
238  * @post the ownership of Point is taken by the function
239  * @ingroup capi
240  */
241 SFCGAL_API void                      sfcgal_linestring_add_point( sfcgal_geometry_t* linestring, sfcgal_geometry_t* point );
242 
243 /**
244  * Creates an empty Triangle
245  * @ingroup capi
246  */
247 SFCGAL_API sfcgal_geometry_t*        sfcgal_triangle_create();
248 
249 /**
250  * Creates a Triangle from three given Point
251  * @pre pta must be a Triangle
252  * @pre ptb must be a Triangle
253  * @pre ptc must be a Triangle
254  * @post the ownership of the three points are not taken. The caller is still responsible of their deallocation
255  * @ingroup capi
256  */
257 SFCGAL_API sfcgal_geometry_t*        sfcgal_triangle_create_from_points( const sfcgal_geometry_t* pta,
258         const sfcgal_geometry_t* ptb,
259         const sfcgal_geometry_t* ptc );
260 
261 /**
262  * Returns one the Triangle's vertex as a Point
263  * @pre triangle must be a Triangle
264  * @pre i >= 0 and i < 3
265  * @post returns a pointer to one of the vertices as a Point. This pointer is not writable and must not be deallocated by the caller
266  * @ingroup capi
267  */
268 SFCGAL_API const sfcgal_geometry_t*  sfcgal_triangle_vertex( const sfcgal_geometry_t* triangle, int i );
269 
270 /**
271  * Sets one vertex of a Triangle
272  * @pre triangle must be a Triangle
273  * @pre vertex must be a Point
274  * @post returns a pointer to one of the vertices as a Point. This pointer is not writable and must not be deallocated by the caller
275  * @ingroup capi
276  */
277 SFCGAL_API void                      sfcgal_triangle_set_vertex( sfcgal_geometry_t* triangle, int i, const sfcgal_geometry_t* vertex );
278 
279 /**
280  * Sets one vertex of a Triangle from two coordinates
281  * @pre triangle must be a Triangle
282  * @pre i >= 0 and i < 3
283  * @ingroup capi
284  */
285 SFCGAL_API void                      sfcgal_triangle_set_vertex_from_xy( sfcgal_geometry_t* triangle, int i, double x, double y );
286 
287 /**
288  * Sets one vertex of a Triangle from three coordinates
289  * @pre triangle must be a Triangle
290  * @pre i >= 0 and i < 3
291  * @ingroup capi
292  */
293 SFCGAL_API void                      sfcgal_triangle_set_vertex_from_xyz( sfcgal_geometry_t* triangle, int i, double x, double y, double z );
294 
295 /**
296  * Creates an empty Polygon
297  * @ingroup capi
298  */
299 SFCGAL_API sfcgal_geometry_t*        sfcgal_polygon_create();
300 
301 /**
302  * Creates an empty Polygon from an extrior ring
303  * @pre ring must be a LineString
304  * @post the ownership of the given ring is taken. The caller is not responsible anymore of its deallocation
305  * @ingroup capi
306  */
307 SFCGAL_API sfcgal_geometry_t*        sfcgal_polygon_create_from_exterior_ring( sfcgal_geometry_t* ring );
308 
309 /**
310  * Returns the exterior ring of a given Polygon
311  * @pre polygon must be a Polygon
312  * @pre polygon must not be empty
313  * @post the returned ring is a LineString, is not writable and must not be deallocated by the caller
314  * @ingroup capi
315  */
316 SFCGAL_API const sfcgal_geometry_t*  sfcgal_polygon_exterior_ring( const sfcgal_geometry_t* polygon );
317 
318 /**
319  * Returns the number of interior rings of a given Polygon
320  * @pre polygon must be a Polygon
321  * @ingroup capi
322  */
323 SFCGAL_API size_t                    sfcgal_polygon_num_interior_rings( const sfcgal_geometry_t* polygon );
324 
325 /**
326  * Returns the ith interior ring of a given Polygon
327  * @pre polygon must be a Polygon
328  * @pre i >= 0 and i < sfcgal_polygon_num_interior_rings
329  * @post the returned ring is a LineString, is not writable and must not be deallocated by the caller
330  * @ingroup capi
331  */
332 SFCGAL_API const sfcgal_geometry_t*  sfcgal_polygon_interior_ring_n( const sfcgal_geometry_t* polygon, size_t i );
333 
334 /**
335  * Adds an interior ring to a given Polygon
336  * @pre polygon must be a Polygon
337  * @pre ring must be a LineString
338  * @ingroup capi
339  */
340 SFCGAL_API void                      sfcgal_polygon_add_interior_ring( sfcgal_geometry_t* polygon, sfcgal_geometry_t* ring );
341 
342 /**
343  * Creates an empty  GeometryCollection
344  * @ingroup capi
345  */
346 SFCGAL_API sfcgal_geometry_t*        sfcgal_geometry_collection_create();
347 
348 /**
349  * Returns the number of geometries of a given GeometryCollection
350  * @pre collection is a GeometryCollection
351  * @ingroup capi
352  */
353 SFCGAL_API size_t                    sfcgal_geometry_collection_num_geometries( const sfcgal_geometry_t* collection );
354 
355 /**
356  * Returns the ith geometry of a GeometryCollection
357  * @pre collection is a GeometryCollection
358  * @pre i >= 0 and i < sfcgal_geometry_collection_num_geometries
359  * @post the returned Geometry is not writable and must not be deallocated by the caller
360  * @ingroup capi
361  */
362 SFCGAL_API const sfcgal_geometry_t*  sfcgal_geometry_collection_geometry_n( const sfcgal_geometry_t* collection , size_t i );
363 
364 /**
365  * Adds a Geometry to a given GeometryCollection
366  * @pre collection must be a GeometryCollection
367  * @post the ownership of the given geometry is taken. The caller is not responsible anymore of its deallocation
368  * @ingroup capi
369  */
370 SFCGAL_API void                      sfcgal_geometry_collection_add_geometry( sfcgal_geometry_t* collection, sfcgal_geometry_t* geometry );
371 
372 /**
373  * Creates an empty MultiPoint
374  * @ingroup capi
375  */
376 SFCGAL_API sfcgal_geometry_t*        sfcgal_multi_point_create();
377 
378 /**
379  * Creates an empty MultiLineString
380  * @ingroup capi
381  */
382 SFCGAL_API sfcgal_geometry_t*        sfcgal_multi_linestring_create();
383 
384 /**
385  * Creates an empty MultiPolygon
386  * @ingroup capi
387  */
388 SFCGAL_API sfcgal_geometry_t*        sfcgal_multi_polygon_create();
389 
390 /**
391  * Creates an empty PolyhedralSurface
392  * @ingroup capi
393  */
394 SFCGAL_API sfcgal_geometry_t*        sfcgal_polyhedral_surface_create();
395 
396 /**
397  * Returns the number of polygons of a given PolyhedralSurface
398  * @pre polyhedral must be a PolyhedralSurface
399  * @ingroup capi
400  */
401 SFCGAL_API size_t                    sfcgal_polyhedral_surface_num_polygons( const sfcgal_geometry_t* polyhedral );
402 
403 /**
404  * Returns the ith polygon of a given PolyhedralSurface
405  * @pre polyhedral must be a PolyhedralSurface
406  * @pre i >= 0 and i < sfcgal_polyhedral_surface_num_polygons(polyhedral)
407  * @post the returned Polygon is not writable and must not be deallocated by the caller
408  * @ingroup capi
409  */
410 SFCGAL_API const sfcgal_geometry_t*  sfcgal_polyhedral_surface_polygon_n( const sfcgal_geometry_t* polyhedral, size_t i );
411 
412 /**
413  * Adds a Polygon to a given PolyhedralSurface
414  * @pre polyhedral must be a PolyhedralSurface
415  * @pre polygon must be a Polygon
416  * @post the ownership of the Polygon is taken. The caller is not responsible anymore of its deallocation
417  * @ingroup capi
418  */
419 SFCGAL_API void                      sfcgal_polyhedral_surface_add_polygon( sfcgal_geometry_t* polyhedral, sfcgal_geometry_t* polygon );
420 
421 /**
422  * Creates an empty TriangulatedSurface
423  * @ingroup capi
424  */
425 SFCGAL_API sfcgal_geometry_t*        sfcgal_triangulated_surface_create();
426 
427 /**
428  * Returns the number of triangles of a given TriangulatedSurface
429  * @pre tin must be a TriangulatedSurface
430  * @ingroup capi
431  */
432 SFCGAL_API size_t                    sfcgal_triangulated_surface_num_triangles( const sfcgal_geometry_t* tin );
433 
434 /**
435  * Returns the ith Triangle of a given TriangulatedSurface
436  * @pre tin must be a TriangulatedSurface
437  * @pre i >= 0 and i < sfcgal_triangulated_surface_num_triangles( tin )
438  * @post the returned Triangle is not writable and must not be deallocated by the caller
439  * @ingroup capi
440  */
441 SFCGAL_API const sfcgal_geometry_t*  sfcgal_triangulated_surface_triangle_n( const sfcgal_geometry_t* tin, size_t i );
442 
443 /**
444  * Adds a Triangle to a given TriangulatedSurface
445  * @pre tin must be a TriangulatedSurface
446  * @pre triangle must be a Triangle
447  * @post the ownership of the Triangle is taken. The caller is not responsible anymore of its deallocation
448  * @ingroup capi
449  */
450 SFCGAL_API void                      sfcgal_triangulated_surface_add_triangle( sfcgal_geometry_t* tin, sfcgal_geometry_t* triangle );
451 
452 /**
453  * Creates an empty Solid
454  * @ingroup capi
455  */
456 SFCGAL_API sfcgal_geometry_t*        sfcgal_solid_create();
457 
458 /**
459  * Creates a Solid from an exterior shell
460  * @pre ring must be a PolyhedralSurface
461  * @post the ownership of the given shell is taken. The caller is not responsible anymore of its deallocation
462  * @ingroup capi
463  */
464 SFCGAL_API sfcgal_geometry_t*        sfcgal_solid_create_from_exterior_shell( sfcgal_geometry_t* shell );
465 
466 /**
467  * Returns the number of shells of a given Solid
468  * @pre solid must be a Solid
469  * @ingroup capi
470  */
471 SFCGAL_API size_t                    sfcgal_solid_num_shells( const sfcgal_geometry_t* solid );
472 
473 /**
474  * Returns the ith shell of a given Solid
475  * @pre solid must be a Solid
476  * @pre i >= 0 and i < sfcgal_solid_num_shells( tin )
477  * @post the returned PolyhedralSurface is not writable and must not be deallocated by the caller
478  * @ingroup capi
479  */
480 SFCGAL_API const sfcgal_geometry_t*  sfcgal_solid_shell_n( const sfcgal_geometry_t* solid, size_t i );
481 
482 /**
483  * Adds a shell to a given Solid
484  * @pre solid must be a Solid
485  * @pre shell must be a PolyhedralSurface
486  * @post the ownership of the shell is taken. The caller is not responsible anymore of its deallocation
487  * @ingroup capi
488  */
489 SFCGAL_API void                      sfcgal_solid_add_interior_shell( sfcgal_geometry_t* solid, sfcgal_geometry_t* shell );
490 
491 
492 /**
493  * Gets the validity flag of the geometry.
494  */
495 SFCGAL_API int sfcgal_geometry_has_validity_flag( const sfcgal_geometry_t* geom );
496 
497 /**
498  * Sets the validity flag of the geometry.
499  * FIXME We better have geometry constructors to directly build valid geometries
500  */
501 SFCGAL_API void sfcgal_geometry_force_valid( sfcgal_geometry_t* geom, int valid );
502 
503 /*--------------------------------------------------------------------------------------*
504  *
505  * Support for SFCGAL::PreparedGeometry
506  *
507  *--------------------------------------------------------------------------------------*/
508 
509 /**
510  * Opaque type that represents the C++ type SFCGAL::PreparedGeometry
511  * @ingroup capi
512  */
513 typedef void sfcgal_prepared_geometry_t;
514 
515 typedef uint32_t srid_t;
516 
517 /**
518  * Creates an empty PreparedGeometry
519  * @ingroup capi
520  */
521 SFCGAL_API sfcgal_prepared_geometry_t* sfcgal_prepared_geometry_create();
522 
523 /**
524  * Creates a PreparedGeometry from a Geometry and an SRID
525  * @ingroup capi
526  */
527 SFCGAL_API sfcgal_prepared_geometry_t* sfcgal_prepared_geometry_create_from_geometry( sfcgal_geometry_t* geometry, srid_t srid );
528 
529 /**
530  * Deletes a given PreparedGeometry
531  * @pre prepared must be a PreparedGeometry
532  * @post the underlying Geometry linked to the given PreparedGeometry is also deleted
533  * @ingroup capi
534  */
535 SFCGAL_API void                        sfcgal_prepared_geometry_delete( sfcgal_prepared_geometry_t* prepared );
536 
537 /**
538  * Returns the Geometry associated with a given PreparedGeometry
539  * @pre prepared must be a PreparedGeometry
540  * @post the returned Geometry is not writable and must not be deallocated by the caller
541  * @ingroup capi
542  */
543 SFCGAL_API const sfcgal_geometry_t*    sfcgal_prepared_geometry_geometry( const sfcgal_prepared_geometry_t* prepared );
544 
545 /**
546  * Sets the Geometry associated with the given PreparedGeometry
547  * @pre prepared must be a PreparedGeometry
548  * @post the ownership of the given geometry is taken. The caller is not responsible anymore of its deallocation
549  * @ingroup capi
550  */
551 SFCGAL_API void                        sfcgal_prepared_geometry_set_geometry( sfcgal_prepared_geometry_t* prepared, sfcgal_geometry_t* geometry );
552 
553 /**
554  * Returns SRID associated with a given PreparedGeometry
555  * @pre prepared must be a PreparedGeometry
556  * @ingroup capi
557  */
558 SFCGAL_API srid_t                      sfcgal_prepared_geometry_srid( const sfcgal_prepared_geometry_t* prepared );
559 
560 /**
561  * Sets SRID associated with a given PreparedGeometry
562  * @pre prepared must be a PreparedGeometry
563  * @ingroup capi
564  */
565 SFCGAL_API void                        sfcgal_prepared_geometry_set_srid( sfcgal_prepared_geometry_t* prepared, srid_t );
566 
567 /**
568  * Returns an EWKT representation of the given PreparedGeometry
569  * @param num_decimals number of decimals. -2 for a variable number of decimals. -1 for an exact representation
570  * @post buffer is returned allocated and must be freed by the caller
571  * @ingroup capi
572  */
573 SFCGAL_API void                        sfcgal_prepared_geometry_as_ewkt( const sfcgal_prepared_geometry_t* prepared, int num_decimals, char** buffer, size_t* len );
574 
575 /*--------------------------------------------------------------------------------------*
576  *
577  * I/O functions
578  *
579  *--------------------------------------------------------------------------------------*/
580 
581 /**
582  * io::readWKT
583  */
584 SFCGAL_API sfcgal_geometry_t*          sfcgal_io_read_wkt( const char*, size_t len );
585 SFCGAL_API sfcgal_prepared_geometry_t* sfcgal_io_read_ewkt( const char*, size_t len );
586 
587 /**
588  * Serialization
589  */
590 /* allocates into char**, must be freed by the caller */
591 SFCGAL_API void                        sfcgal_io_write_binary_prepared( const sfcgal_prepared_geometry_t*, char**, size_t* );
592 SFCGAL_API sfcgal_prepared_geometry_t* sfcgal_io_read_binary_prepared( const char*, size_t l );
593 
594 /*--------------------------------------------------------------------------------------*
595  *
596  * Spatial processing
597  *
598  *--------------------------------------------------------------------------------------*/
599 
600 /**
601  * Tests the intersection of geom1 and geom2
602  * @pre isValid(geom1) == true
603  * @pre isValid(geom2) == true
604  * @ingroup capi
605  */
606 SFCGAL_API int                         sfcgal_geometry_intersects( const sfcgal_geometry_t* geom1, const sfcgal_geometry_t* geom2 );
607 
608 /**
609  * Tests the 3D intersection of geom1 and geom2
610  * @pre isValid(geom1) == true
611  * @pre isValid(geom2) == true
612  * @ingroup capi
613  */
614 SFCGAL_API int                         sfcgal_geometry_intersects_3d( const sfcgal_geometry_t* geom1, const sfcgal_geometry_t* geom2 );
615 
616 /**
617  * Returns the intersection of geom1 and geom2
618  * @pre isValid(geom1) == true
619  * @pre isValid(geom2) == true
620  * @post isValid(return) == true
621  * @ingroup capi
622  */
623 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_intersection( const sfcgal_geometry_t* geom1, const sfcgal_geometry_t* geom2 );
624 
625 /**
626  * Returns the 3D intersection of geom1 and geom2
627  * @pre isValid(geom1) == true
628  * @pre isValid(geom2) == true
629  * @post isValid(return) == true
630  * @ingroup capi
631  */
632 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_intersection_3d( const sfcgal_geometry_t* geom1, const sfcgal_geometry_t* geom2 );
633 
634 /**
635  * Returns the difference of geom1 and geom2
636  * @pre isValid(geom1) == true
637  * @pre isValid(geom2) == true
638  * @post isValid(return) == true
639  * @ingroup capi
640  */
641 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_difference( const sfcgal_geometry_t* geom1, const sfcgal_geometry_t* geom2 );
642 
643 /**
644  * Returns the 3D difference of geom1 and geom2
645  * @pre isValid(geom1) == true
646  * @pre isValid(geom2) == true
647  * @post isValid(return) == true
648  * @ingroup capi
649  */
650 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_difference_3d( const sfcgal_geometry_t* geom1, const sfcgal_geometry_t* geom2 );
651 
652 /**
653  * Returns the union of geom1 and geom2
654  * @pre isValid(geom1) == true
655  * @pre isValid(geom2) == true
656  * @post isValid(return) == true
657  * @ingroup capi
658  */
659 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_union( const sfcgal_geometry_t* geom1, const sfcgal_geometry_t* geom2 );
660 
661 /**
662  * Returns the 3D union of geom1 and geom2
663  * @pre isValid(geom1) == true
664  * @pre isValid(geom2) == true
665  * @post isValid(return) == true
666  * @ingroup capi
667  */
668 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_union_3d( const sfcgal_geometry_t* geom1, const sfcgal_geometry_t* geom2 );
669 
670 /**
671  * Returns the convex hull of geom
672  * @pre isValid(geom) == true
673  * @post isValid(return) == true
674  * @ingroup capi
675  */
676 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_convexhull( const sfcgal_geometry_t* geom );
677 
678 /**
679  * Returns the 3D convex hull of geom
680  * @pre isValid(geom) == true
681  * @post isValid(return) == true
682  * @ingroup capi
683  */
684 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_convexhull_3d( const sfcgal_geometry_t* geom );
685 
686 /**
687  * Returns the volume of geom (must be a volume)
688  * @pre isValid(geom) == true
689  * @ingroup capi
690  */
691 SFCGAL_API double                      sfcgal_geometry_volume( const sfcgal_geometry_t* geom );
692 
693 /**
694  * Returns the area of geom
695  * @pre isValid(geom) == true
696  * @ingroup capi
697  */
698 SFCGAL_API double                      sfcgal_geometry_area( const sfcgal_geometry_t* geom );
699 
700 /**
701  * Returns the 3D area of geom
702  * @pre isValid(geom) == true
703  * @ingroup capi
704  */
705 SFCGAL_API double                      sfcgal_geometry_area_3d( const sfcgal_geometry_t* geom );
706 
707 /**
708  * Tests if the given Geometry is planar
709  * @pre isValid(geom) == true
710  * @ingroup capi
711  */
712 SFCGAL_API int                         sfcgal_geometry_is_planar( const sfcgal_geometry_t* geom );
713 
714 /**
715  * Returns the orientation of the given Polygon
716  * -1 for a counter clockwise orientation
717  * 1 for a clockwise orientation
718  * 0 for an invalid or undetermined orientation
719  * @pre geom is a Polygon
720  * @pre isValid(geom) == true
721  * @ingroup capi
722  */
723 SFCGAL_API int                         sfcgal_geometry_orientation( const sfcgal_geometry_t* geom );
724 
725 /**
726  * Returns a tesselation of the given Geometry
727  * @pre isValid(geom) == true
728  * @post isValid(return) == true
729  * @ingroup capi
730  */
731 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_tesselate( const sfcgal_geometry_t* geom );
732 
733 /**
734  * Returns a triangulation of the given Geometry
735  * @pre isValid(geom) == true
736  * @post isValid(return) == true
737  * @ingroup capi
738  */
739 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_triangulate_2dz( const sfcgal_geometry_t* geom );
740 
741 /**
742  * Returns an extrusion of the given Geometry
743  * @pre isValid(geom) == true
744  * @post isValid(return) == true
745  * @ingroup capi
746  */
747 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_extrude( const sfcgal_geometry_t* geom, double ex, double ey, double ez );
748 
749 /**
750  * Convert a PolyhedralSurface to a Solid
751  * @pre isValid(geom) == true
752  * @post isValid(return) == true
753  * @ingroup detail
754  */
755 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_make_solid( const sfcgal_geometry_t* geom );
756 
757 /**
758  * Force a Left Handed Rule on the given Geometry
759  * @pre isValid(geom) == true
760  * @post isValid(return) == true
761  * @ingroup capi
762  */
763 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_force_lhr( const sfcgal_geometry_t* geom );
764 
765 /**
766  * Force a Right Handed Rule on the given Geometry
767  * @pre isValid(geom) == true
768  * @post isValid(return) == true
769  * @ingroup capi
770  */
771 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_force_rhr( const sfcgal_geometry_t* geom );
772 
773 /**
774  * Computes the distance of the two given Geometry objects
775  * @pre isValid(geom1) == true
776  * @pre isValid(geom2) == true
777  * @ingroup capi
778  */
779 SFCGAL_API double                      sfcgal_geometry_distance( const sfcgal_geometry_t* geom1, const sfcgal_geometry_t* geom2 );
780 
781 /**
782  * Computes the 3D distance of the two given Geometry objects
783  * @pre isValid(geom1) == true
784  * @pre isValid(geom2) == true
785  * @ingroup capi
786  */
787 SFCGAL_API double                      sfcgal_geometry_distance_3d( const sfcgal_geometry_t* geom1, const sfcgal_geometry_t* geom2 );
788 
789 /**
790  * Round coordinates of the given Geometry
791  * @pre isValid(geom) == true
792  * @post isValid(return) == true
793  * @ingroup capi
794  */
795 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_round( const sfcgal_geometry_t* geom, int r );
796 
797 /**
798  * Returns the minkowski sum geom1 + geom2
799  * @pre isValid(geom1) == true
800  * @pre isValid(geom2) == true
801  * @post isValid(return) == true
802  * @ingroup capi
803  */
804 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_minkowski_sum( const sfcgal_geometry_t* geom1, const sfcgal_geometry_t* geom2 );
805 
806 /**
807  * Returns the offset polygon of the given Geometry.
808  * @pre isValid(geom) == true
809  * @post isValid(return) == true
810  * @ingroup capi
811  */
812 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_offset_polygon( const sfcgal_geometry_t* geom, double radius );
813 
814 /**
815  * Returns the straight skeleton of the given Geometry
816  * @pre isValid(geom) == true
817  * @post isValid(return) == true
818  * @ingroup capi
819  */
820 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_straight_skeleton( const sfcgal_geometry_t* geom );
821 
822 /**
823  * Returns the straight skeleton of the given Geometry with the distance to the border as M coordinate
824  * @pre isValid(geom) == true
825  * @post isValid(return) == true
826  * @ingroup capi
827  */
828 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_straight_skeleton_distance_in_m( const sfcgal_geometry_t* geom );
829 
830 /**
831  * Returns the approximate medial axis for the given Polygon
832  * Approximate medial axis is based on straight skeleton
833  * @pre isValid(geom) == true
834  * @ingroup capi
835  */
836 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_approximate_medial_axis( const sfcgal_geometry_t* geom );
837 
838 /**
839  * Tests the coverage of geom1 and geom2
840  * @pre isValid(geom1) == true
841  * @pre isValid(geom2) == true
842  * @ingroup capi
843  */
844 SFCGAL_API int                         sfcgal_geometry_covers( const sfcgal_geometry_t* geom1, const sfcgal_geometry_t* geom2 );
845 
846 /**
847  * Tests the 3D coverage of geom1 and geom2
848  * @pre isValid(geom1) == true
849  * @pre isValid(geom2) == true
850  * @ingroup capi
851  */
852 SFCGAL_API int                         sfcgal_geometry_covers_3d( const sfcgal_geometry_t* geom1, const sfcgal_geometry_t* geom2 );
853 
854 
855 /**
856  * Returns the substring of the given LineString between fractional distances
857  * @pre isValid(geom) == true
858  * @pre geom is a Linestring
859  * @pre -1 <= start <= 1
860  * @pre -1 <= end <= 1
861  * @post isValid(return) == true
862  * @ingroup capi
863  */
864 SFCGAL_API sfcgal_geometry_t*          sfcgal_geometry_line_sub_string( const sfcgal_geometry_t* geom, double start, double end );
865 /*--------------------------------------------------------------------------------------*
866  *
867  * Error handling
868  *
869  *--------------------------------------------------------------------------------------*/
870 
871 /**
872  * Warning and error handlers
873  * @ingroup capi
874  */
875 typedef int ( *sfcgal_error_handler_t ) ( const char*, ... );
876 
877 /**
878  * Sets the error handlers. These callbacks are called on warning or error
879  * @param warning_handler is the printf-styled callback function that will be called when a function raises a warning.
880  * The default behaviour is to call printf.
881  * @param error_handler is the printf-style callback function that will be called when a function generates an error.
882  * The default behaviour is to call printf.
883  * @ingroup capi
884  */
885 SFCGAL_API void sfcgal_set_error_handlers( sfcgal_error_handler_t warning_handler, sfcgal_error_handler_t error_handler );
886 
887 /*--------------------------------------------------------------------------------------*
888  *
889  * Memory allocation
890  *
891  *--------------------------------------------------------------------------------------*/
892 
893 typedef void* ( *sfcgal_alloc_handler_t ) ( size_t );
894 typedef void ( *sfcgal_free_handler_t ) ( void* );
895 
896 /**
897  * Sets the error handlers. These callbacks are called on warning or error
898  * @param malloc_handler is the function to call for memory allocation. The default behaviour is to call malloc()
899  * @param free_handler is the function to call for memory deallocation. The default behaviour is to call free()
900  * @ingroup capi
901  */
902 SFCGAL_API void sfcgal_set_alloc_handlers( sfcgal_alloc_handler_t malloc_handler, sfcgal_free_handler_t free_handler );
903 
904 /*--------------------------------------------------------------------------------------*
905  *
906  * Init
907  *
908  *--------------------------------------------------------------------------------------*/
909 
910 /**
911  * This function must be called before all the other one.
912  * @ingroup capi
913  */
914 SFCGAL_API void sfcgal_init();
915 
916 /**
917  * Get version
918  * @ingroup capi
919  */
920 SFCGAL_API const char* sfcgal_version();
921 
922 /**
923  * Get full version (including CGAL and Boost versions)
924  * @ingroup capi
925  */
926 SFCGAL_API const char* sfcgal_full_version();
927 
928 #ifdef __cplusplus
929 }
930 #endif
931 #endif
932