Once (if) the new geo-types
with 3dM support is merged, I think wkt can migrate to use them directly, instead of having its own duplicate set of types. This should improve performance (no extra transformation), and simplify code - one set of types for everything.
// current WKT type
pub struct Coord<T: WktFloat> {
pub x: T,
pub y: T,
pub z: Option<T>,
pub m: Option<T>,
}
// corresponding geo type
pub struct Coordinate<T: CoordNum, Z: ZCoord, M: Measure> {
pub x: T,
pub y: T,
pub z: Z,
pub m: M,
}
The 3dM types require proper generics (either concrete float type or a NoValue
empty struct). We could represent it with a new Wkt
enum instead of the existing pub struct Wkt<T> { pub item: Geometry<T> }
. NoValue
might need to be updated to support all CoordNum
requirements.
// Usage:
match Wkt::from_str("LINESTRING (10 -20, -0 -0.5)").unwrap() {
Wkt(g) => ..., // 2D value
WktM(g) => ..., // 2D+M value
Wkt3D(g) => ..., // 3D value
Wkt3DM(g) => ..., // 3D+M value
WktEmpty(g) => ..., // Empty value, e.g. "POINT EMPTY"
}
// Note that all T, Z, and M types of the 3dM geo-types in WKT are used as the same `T` generic type, except for the empty type
pub enum Wkt {
Wkt(Geometry<T>),
WktM(GeometryM<T>),
Wkt3D(Geometry3D<T>),
Wkt3DM(Geometry3DM<T>),
WktEmpty(Geometry<NoValue>),
}