Skip to main content

geo_repair_polygon/
lib.rs

1//! This package provides two traits for (Multi)Polygon: repair and merge
2//!
3//! When running repair, it will try its best to produce a (Multi)Polygon
4//! that meets OGC standards. Some very invalid polygons still fail, but
5//! most come through as valid with very little change.
6//!
7//! The join trait for MultiPolygon will merge all of its Polygons
8//! into a single valid Polygon. This may involve a union or the
9//! creation of a small bridge between the closes points of non-overlapping
10//! Polygons.
11//!
12mod close_poly;
13mod dedup_poly_point;
14mod fix_intersecting_rings;
15mod fix_point_touching_ring_line;
16mod fix_self_intersecting_ring;
17pub mod join;
18pub mod repair;
19
20use float_next_after::NextAfter;
21use geo_booleanop::boolean::Float;
22use geo_types::Coordinate;
23use std::fmt;
24
25pub trait GeoRepairFloat:
26    Float
27    + NextAfter<Self>
28    + fmt::Display
29    + num_traits::cast::FromPrimitive
30    + std::iter::Sum
31    + num_traits::Signed
32{
33}
34impl<
35        T: Float
36            + NextAfter<T>
37            + fmt::Display
38            + num_traits::cast::FromPrimitive
39            + std::iter::Sum
40            + num_traits::Signed,
41    > GeoRepairFloat for T
42{
43}
44
45fn shift_point<T: GeoRepairFloat>(coord: &Coordinate<T>, x_dir: T, y_dir: T) -> Coordinate<T> {
46    // Put some distance between the submitted coord and the output (2 steps seems enough)
47    Coordinate {
48        x: coord.x.next_after(x_dir).next_after(x_dir),
49        y: coord.y.next_after(y_dir).next_after(y_dir),
50    }
51}