Skip to content

Commit

Permalink
integrate geo-validity-check into geo
Browse files Browse the repository at this point in the history
Note: some tests are failing
  • Loading branch information
michaelkirk committed Dec 10, 2024
1 parent 92d8bfc commit 5dd1909
Show file tree
Hide file tree
Showing 16 changed files with 307 additions and 387 deletions.
2 changes: 2 additions & 0 deletions geo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ i_overlay = { version = "1.9.0, < 1.10.0", default-features = false }
approx = ">= 0.4.0, < 0.6.0"
criterion = { version = "0.4", features = ["html_reports"] }
geo-test-fixtures = { path = "../geo-test-fixtures" }
# REVIEW: make optional? remove? It's used for some conformance tests which are somewhat redundant with the JTS tests
geos = { version = "9.1.1", features = ["geo"] }
jts-test-runner = { path = "../jts-test-runner" }
pretty_env_logger = "0.4"
rand = "0.8.0"
Expand Down
6 changes: 3 additions & 3 deletions geo/src/algorithm/validation/coord.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{utils, Problem, ProblemAtPosition, ProblemPosition, ProblemReport, Valid};
use geo::{Coord, GeoFloat};
use super::{utils, Problem, ProblemAtPosition, ProblemPosition, ProblemReport, Validation};
use crate::{Coord, GeoFloat};

impl<F: GeoFloat> Valid for Coord<F> {
impl<F: GeoFloat> Validation for Coord<F> {
fn is_valid(&self) -> bool {
if utils::check_coord_is_not_finite(self) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions geo/src/algorithm/validation/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{ProblemReport, Valid};
use geo::{GeoFloat, Geometry};
use super::{ProblemReport, Validation};
use crate::{GeoFloat, Geometry};

impl<F: GeoFloat> Valid for Geometry<F> {
impl<F: GeoFloat> Validation for Geometry<F> {
fn is_valid(&self) -> bool {
match self {
Geometry::Point(e) => e.is_valid(),
Expand Down
12 changes: 6 additions & 6 deletions geo/src/algorithm/validation/geometrycollection.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{GeometryPosition, ProblemAtPosition, ProblemPosition, ProblemReport, Valid};
use geo::{GeoFloat, GeometryCollection};
use super::{GeometryPosition, ProblemAtPosition, ProblemPosition, ProblemReport, Validation};
use crate::{GeoFloat, GeometryCollection};

/// GeometryCollection is valid if all its elements are valid
impl<F: GeoFloat> Valid for GeometryCollection<F> {
impl<F: GeoFloat> Validation for GeometryCollection<F> {
fn is_valid(&self) -> bool {
for geometry in self.0.iter() {
if !geometry.is_valid() {
Expand Down Expand Up @@ -41,11 +41,11 @@ impl<F: GeoFloat> Valid for GeometryCollection<F> {

#[cfg(test)]
mod tests {
use crate::{
use super::super::{
CoordinatePosition, GeometryPosition, Problem, ProblemAtPosition, ProblemPosition,
ProblemReport, Valid,
ProblemReport, Validation,
};
use geo::{Coord, Geometry, GeometryCollection, LineString, Point};
use crate::{Coord, Geometry, GeometryCollection, LineString, Point};
use geos::Geom;

#[test]
Expand Down
252 changes: 0 additions & 252 deletions geo/src/algorithm/validation/lib.rs

This file was deleted.

15 changes: 8 additions & 7 deletions geo/src/algorithm/validation/line.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::{
utils, CoordinatePosition, Problem, ProblemAtPosition, ProblemPosition, ProblemReport, Valid,
use super::{
utils, CoordinatePosition, Problem, ProblemAtPosition, ProblemPosition, ProblemReport,
Validation,
};
use geo::{GeoFloat, Line};
use crate::{GeoFloat, Line};

impl<F: GeoFloat> Valid for Line<F> {
impl<F: GeoFloat> Validation for Line<F> {
fn is_valid(&self) -> bool {
if utils::check_coord_is_not_finite(&self.start)
|| utils::check_coord_is_not_finite(&self.end)
Expand Down Expand Up @@ -50,10 +51,10 @@ impl<F: GeoFloat> Valid for Line<F> {

#[cfg(test)]
mod tests {
use crate::{
CoordinatePosition, Problem, ProblemAtPosition, ProblemPosition, ProblemReport, Valid,
use super::super::{
CoordinatePosition, Problem, ProblemAtPosition, ProblemPosition, ProblemReport, Validation,
};
use geo::Line;
use crate::Line;

#[test]
fn test_line_valid() {
Expand Down
15 changes: 8 additions & 7 deletions geo/src/algorithm/validation/linestring.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::{
utils, CoordinatePosition, Problem, ProblemAtPosition, ProblemPosition, ProblemReport, Valid,
use super::{
utils, CoordinatePosition, Problem, ProblemAtPosition, ProblemPosition, ProblemReport,
Validation,
};
use geo::{GeoFloat, LineString};
use crate::{GeoFloat, LineString};

/// In postGIS, a LineString is valid if it has at least 2 points
/// and have a non-zero length (i.e. the first and last points are not the same).
/// Here we also check that all its points are finite numbers.
impl<F: GeoFloat> Valid for LineString<F> {
impl<F: GeoFloat> Validation for LineString<F> {
fn is_valid(&self) -> bool {
if utils::check_too_few_points(self, false) {
return false;
Expand Down Expand Up @@ -51,10 +52,10 @@ impl<F: GeoFloat> Valid for LineString<F> {

#[cfg(test)]
mod tests {
use crate::{
CoordinatePosition, Problem, ProblemAtPosition, ProblemPosition, ProblemReport, Valid,
use super::super::{
CoordinatePosition, Problem, ProblemAtPosition, ProblemPosition, ProblemReport, Validation,
};
use geo::{Coord, LineString};
use crate::{Coord, LineString};
use geos::Geom;

#[test]
Expand Down
Loading

0 comments on commit 5dd1909

Please sign in to comment.