Skip to main content

geometry_adapt_geo_types/
lib.rs

1//! Adapt `geo-types` geometries to the `geometry-trait` concept
2//! surface.
3//!
4//! Mirrors the role of the Boost `BOOST_GEOMETRY_REGISTER_*` macros in
5//! `boost/geometry/geometries/adapted/` — those specialise the C++
6//! `traits::{tag, dimension, coordinate_type, coordinate_system,
7//! access}` metafunctions (and, for containers, `ring_const_type`,
8//! `exterior_ring`, `interior_rings`, …) for a foreign storage layout.
9//! Rust has no specialisation and the orphan rule forbids implementing
10//! a foreign concept trait for a foreign `geo-types` type, so — as with
11//! [`geometry_adapt::Adapt`](https://docs.rs/geometry-adapt) and the
12//! [`geometry_adapt_nalgebra`](https://docs.rs/geometry-adapt-nalgebra)
13//! sibling — each foreign value is wrapped in a local newtype and the
14//! geometry concepts hang off the wrapper.
15//!
16//! # Point wrappers
17//!
18//! * [`GeoCoord`] — `geo_types::Coord`, the `(x, y)` ordinate pair.
19//! * [`GeoPoint`] — `geo_types::Point`, the newtype around a `Coord`.
20//!
21//! Both pin `Cs = Cartesian`, `DIM = 2`, and are read-write
22//! ([`geometry_trait::PointMut`]).
23//!
24//! # Container wrappers
25//!
26//! * [`GeoLineString`] — `geo_types::LineString` as a `Linestring`.
27//! * [`GeoRing`] — `geo_types::LineString` as a `Ring` (`geo-types` has
28//!   no separate ring type; the caller asserts closure and
29//!   orientation).
30//! * [`GeoPolygon`] — `geo_types::Polygon`.
31//! * [`GeoMultiPoint`] / [`GeoMultiLineString`] / [`GeoMultiPolygon`].
32//! * [`GeoLine`] — `geo_types::Line` as a `Segment`.
33//! * [`GeoRect`] — `geo_types::Rect` as a `Box`.
34//! * [`GeoCollection`] — `geo_types::GeometryCollection`.
35//!
36//! Because the container concepts yield their points *by reference*
37//! (`points() -> impl Iterator<Item = &Self::Point>`) and this crate is
38//! `#![forbid(unsafe_code)]`, the container wrappers store their
39//! vertices as the wrapped point type ([`GeoCoord`] / [`GeoPoint`])
40//! rather than re-casting the raw `geo-types` storage. Construction and
41//! [`into_inner`](GeoLineString::into_inner) copy ordinates
42//! element-by-element; both coordinate representations are `Copy`, so
43//! the round trip is lossless.
44//!
45//! # `DynGeometry` interop
46//!
47//! [`crate::dyn_conversion`] provides
48//! `From<geo_types::Geometry<T>>` ↔
49//! [`DynGeometry<T, Cartesian>`](geometry_model::DynGeometry) so a whole
50//! geometry tree can move between the two ecosystems.
51
52#![forbid(unsafe_code)]
53
54extern crate alloc;
55
56pub mod dyn_conversion;
57
58mod geo_collection;
59mod geo_coord;
60mod geo_line;
61mod geo_line_string;
62mod geo_multi_line_string;
63mod geo_multi_point;
64mod geo_multi_polygon;
65mod geo_point;
66mod geo_polygon;
67mod geo_rect;
68mod geo_ring;
69
70pub use geo_collection::GeoCollection;
71pub use geo_coord::GeoCoord;
72pub use geo_line::GeoLine;
73pub use geo_line_string::GeoLineString;
74pub use geo_multi_line_string::GeoMultiLineString;
75pub use geo_multi_point::GeoMultiPoint;
76pub use geo_multi_polygon::GeoMultiPolygon;
77pub use geo_point::GeoPoint;
78pub use geo_polygon::GeoPolygon;
79pub use geo_rect::GeoRect;
80pub use geo_ring::GeoRing;