Skip to main content

wbtopology/
lib.rs

1#![forbid(unsafe_code)]
2#![deny(missing_docs)]
3
4//! # wbtopology
5//!
6//! A pure-Rust topology suite inspired by JTS.
7//! The crate is dependency-light (currently zero external dependencies), avoids
8//! unsafe code, and focuses on predictable performance for core geometry
9//! predicates and operations.
10//!
11//! ## Selected APIs
12//!
13//! - Hulls: [`convex_hull`], [`convex_hull_geometry`], [`concave_hull`],
14//!   [`concave_hull_geometry`], precision-aware `*_with_precision` wrappers,
15//!   and [`ConcaveHullOptions`] for advanced concave-hull tuning, including
16//!   scale-free `relative_edge_length_ratio` control and selectable
17//!   [`ConcaveHullEngine`] backends.
18//! - Constructive buffering: [`buffer_point`], [`buffer_linestring`], [`buffer_polygon`],
19//!   and [`buffer_polygon_multi`] for erosion results that may split into multiple components.
20//! - Spatial indexing: [`SpatialIndex`] with packed STR hierarchy, nearest-neighbor,
21//!   and top-k nearest (`nearest_k`) lookup.
22//!
23//! ## `buffer_polygon_multi` Example
24//!
25//! ```
26//! use wbtopology::{buffer_polygon_multi, BufferOptions, Coord, LinearRing, Polygon};
27//!
28//! let poly = Polygon::new(
29//!     LinearRing::new(vec![
30//!         Coord::xy(0.0, 0.0),
31//!         Coord::xy(10.0, 0.0),
32//!         Coord::xy(10.0, 10.0),
33//!         Coord::xy(0.0, 10.0),
34//!     ]),
35//!     vec![],
36//! );
37//!
38//! let parts = buffer_polygon_multi(&poly, -1.0, BufferOptions::default());
39//! assert!(!parts.is_empty());
40//! ```
41//!
42//! ## `SpatialIndex` Remove vs Compact Semantics
43//!
44//! ```
45//! use wbtopology::{Coord, Geometry, SpatialIndex};
46//!
47//! let geoms = vec![
48//!     Geometry::Point(Coord::xy(0.0, 0.0)), // id 0
49//!     Geometry::Point(Coord::xy(5.0, 0.0)), // id 1
50//!     Geometry::Point(Coord::xy(9.0, 0.0)), // id 2
51//! ];
52//! let mut idx = SpatialIndex::from_geometries(&geoms);
53//!
54//! idx.remove(1);
55//! let ids_after_remove: Vec<usize> = idx.all_entries().map(|e| e.id).collect();
56//! assert_eq!(ids_after_remove, vec![0, 2]);
57//!
58//! // Compaction reassigns dense ids.
59//! idx.compact();
60//! let ids_after_compact: Vec<usize> = idx.all_entries().map(|e| e.id).collect();
61//! assert_eq!(ids_after_compact, vec![0, 1]);
62//! ```
63
64pub mod algorithms;
65pub mod constructive;
66pub mod error;
67pub mod fixed_radius_search;
68mod fast_triangulation;
69pub mod geom;
70pub mod graph;
71pub mod hull;
72pub mod io;
73pub mod natural_neighbour;
74pub mod noding;
75pub mod overlay;
76pub mod precision;
77pub mod relate;
78pub mod spatial_index;
79pub mod topology;
80pub mod triangulation;
81pub mod vector_io;
82pub mod voronoi;
83
84pub use error::{Result, TopologyError};
85pub use fixed_radius_search::{DistanceMetric, FixedRadiusSearch2D};
86pub use constructive::{
87	buffer_linestring,
88	buffer_linestring_curve_set,
89	buffer_linestring_with_precision,
90	buffer_polygon,
91	buffer_polygon_multi,
92	buffer_polygon_with_precision,
93	buffer_point,
94	buffer_point_with_precision,
95	offset_linestring,
96	make_valid_geometry,
97	make_valid_polygon,
98	polygonize_linework,
99	polygonize_closed_linestrings,
100	BufferBuilder,
101	BufferCapStyle,
102	BufferPipelineStrategy,
103	BufferJoinStyle,
104	BufferOptions,
105	GeometryFixMode,
106	GeometryFixOptions,
107	OffsetCurveOptions,
108	OffsetSide,
109	PolygonizeOptions,
110	PolygonizeResult,
111};
112pub use algorithms::distance::{coord_dist, geometry_distance, is_within_distance, nearest_points};
113pub use algorithms::measurements::{
114	geometry_area, geometry_centroid, geometry_length, linestring_length, polygon_area,
115	polygon_centroid, ring_signed_area,
116};
117pub use algorithms::simplify::{
118	simplify_geometry,
119	simplify_polygon_coverage_topology_preserving,
120	simplify_geometry_topology_preserving,
121	simplify_linestring,
122	simplify_linestring_topology_preserving,
123	simplify_polygon,
124	simplify_polygon_topology_preserving,
125	simplify_ring,
126	simplify_ring_topology_preserving,
127};
128pub use algorithms::transform::{rotate, scale, translate};
129pub use geom::{Coord, Envelope, Geometry, LineString, LinearRing, Polygon};
130pub use graph::{DirectedEdge, GraphNode, TopologyGraph};
131pub use hull::{
132	concave_hull,
133	concave_hull_geometry,
134	concave_hull_geometry_with_options,
135	concave_hull_geometry_with_precision,
136	concave_hull_with_options,
137	concave_hull_with_precision,
138	convex_hull,
139	convex_hull_geometry,
140	convex_hull_geometry_with_precision,
141	convex_hull_with_precision,
142	ConcaveHullEngine,
143	ConcaveHullOptions,
144};
145pub use io::{from_wkb, from_wkt, to_wkb, to_wkt};
146pub use natural_neighbour::PreparedSibsonInterpolator;
147pub use noding::{node_linestrings, node_linestrings_with_options, NodingOptions, NodingStrategy};
148pub use overlay::{
149	polygon_difference,
150	polygon_difference_with_precision,
151	polygon_difference_faces,
152	polygon_intersection,
153	polygon_intersection_with_precision,
154	polygon_intersection_faces,
155	polygon_overlay,
156	polygon_overlay_all,
157	polygon_overlay_all_with_precision,
158	polygon_overlay_with_precision,
159	polygon_overlay_faces,
160	polygon_sym_diff,
161	polygon_sym_diff_with_precision,
162	polygon_sym_diff_faces,
163	polygon_union,
164	polygon_union_with_precision,
165	polygon_union_faces,
166	polygon_unary_union,
167	polygon_unary_union_with_options,
168	polygon_unary_dissolve,
169	polygon_unary_dissolve_with_options,
170	OverlayOutputs,
171	OverlayOp,
172	UnaryDissolveOptions,
173	UnaryDissolveStrategy,
174	UnaryDissolveGroup,
175};
176pub use precision::{PrecisionModel, TopologyPrecisionOptions};
177pub use relate::{relate, relate_with_epsilon, relate_with_precision, Location, RelateMatrix};
178pub use spatial_index::{IndexedGeometry, SpatialIndex};
179pub use topology::{
180	contains,
181	contains_with_epsilon,
182	contains_with_precision,
183	covered_by,
184	covered_by_with_epsilon,
185	covered_by_with_precision,
186	covers,
187	covers_with_epsilon,
188	covers_with_precision,
189	crosses,
190	crosses_with_epsilon,
191	crosses_with_precision,
192	disjoint,
193	disjoint_with_epsilon,
194	disjoint_with_precision,
195	intersects,
196	intersects_with_epsilon,
197	intersects_with_precision,
198	is_simple_linestring,
199	is_valid_polygon,
200	overlaps,
201	overlaps_with_epsilon,
202	overlaps_with_precision,
203	touches,
204	touches_with_epsilon,
205	touches_with_precision,
206	within,
207	within_with_epsilon,
208	within_with_precision,
209	PreparedPolygon,
210};
211pub use triangulation::{
212	delaunay_triangulation,
213	delaunay_triangulation_with_constraints,
214	delaunay_triangulation_with_options,
215	delaunay_triangulation_with_options_checked,
216	delaunay_triangulation_with_precision,
217	DelaunayTriangulation,
218	TriangulationOptions,
219};
220pub use fast_triangulation::delaunay_triangulation_fast;
221pub use voronoi::{
222	voronoi_diagram,
223	voronoi_diagram_with_clip,
224	voronoi_diagram_with_clip_with_precision,
225	voronoi_diagram_with_options,
226	voronoi_diagram_with_precision,
227	VoronoiOptions,
228	VoronoiDiagram,
229};