From 482c2ae158ab791c734030d59f4fd3b83eed6780 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 22 Oct 2023 10:49:56 -0400 Subject: [PATCH] clean up errors --- geo-features/src/lib.rs | 18 +++++----- geo-file-loader/src/geojson.rs | 6 ++-- geo-file-loader/src/shapefile.rs | 2 +- geo-file-loader/src/wkt.rs | 4 +-- geo-projected/src/feature_collection.rs | 4 +-- rgis-geo-ops/src/convex_hull.rs | 2 +- rgis-geo-ops/src/outliers.rs | 2 +- rgis-geo-ops/src/simplify.rs | 2 +- rgis-geo-ops/src/smoothing.rs | 2 +- rgis-geo-ops/src/triangulate.rs | 2 +- rgis-layers/src/lib.rs | 4 +-- rgis-layers/src/systems.rs | 8 ++--- rgis-transform/src/jobs.rs | 4 +-- rgis-transform/src/lib.rs | 2 -- rgis-ui/src/side_panel.rs | 46 +++++++++++-------------- 15 files changed, 46 insertions(+), 62 deletions(-) diff --git a/geo-features/src/lib.rs b/geo-features/src/lib.rs index 2481a724..7b6648b9 100644 --- a/geo-features/src/lib.rs +++ b/geo-features/src/lib.rs @@ -33,17 +33,17 @@ impl FeatureBuilder { FeatureBuilder { properties, ..self } } - pub fn build(self) -> Result { + pub fn build(self) -> Feature { let bounding_rect = self .geometry .as_ref() .and_then(|geometry| geometry.bounding_rect()); - Ok(Feature { + Feature { id: FeatureId::new(), geometry: self.geometry, properties: self.properties, bounding_rect, - }) + } } } @@ -93,12 +93,11 @@ pub enum Value { pub type Properties = collections::HashMap; impl Feature { - pub fn recalculate_bounding_rect(&mut self) -> Result<(), BoundingRectError> { + pub fn recalculate_bounding_rect(&mut self) { self.bounding_rect = self .geometry .as_ref() .and_then(|geometry| geometry.bounding_rect()); - Ok(()) } } @@ -182,9 +181,9 @@ impl fmt::Display for BoundingRectError { impl std::error::Error for BoundingRectError {} impl FeatureCollection { - pub fn from_geometry(geometry: geo::Geometry) -> Result { - let feature = FeatureBuilder::new().with_geometry(geometry).build()?; - Ok(Self::from_feature(feature)) + pub fn from_geometry(geometry: geo::Geometry) -> Self { + let feature = FeatureBuilder::new().with_geometry(geometry).build(); + Self::from_feature(feature) } pub fn from_feature(feature: Feature) -> Self { @@ -216,9 +215,8 @@ impl FeatureCollection { ) } - pub fn recalculate_bounding_rect(&mut self) -> Result<(), BoundingRectError> { + pub fn recalculate_bounding_rect(&mut self) { self.bounding_rect = bounding_rect_from_features(&self.features); - Ok(()) } } diff --git a/geo-file-loader/src/geojson.rs b/geo-file-loader/src/geojson.rs index eb3ecd2a..83f219e3 100644 --- a/geo-file-loader/src/geojson.rs +++ b/geo-file-loader/src/geojson.rs @@ -30,8 +30,6 @@ pub enum LoadGeoJsonError { #[error("{0}")] SerdeJson(#[from] serde_json::Error), #[error("{0}")] - BoundingRect(#[from] geo_features::BoundingRectError), - #[error("{0}")] JsonNumberToFloat(#[from] JsonNumberToFloatError), } @@ -94,7 +92,7 @@ fn geojson_geometry_to_geo_feature_collection( let geo_geometry: geo::Geometry = geojson_geometry.try_into().map_err(Box::new)?; let feature = geo_features::FeatureBuilder::new() .with_geometry(geo_geometry) - .build()?; + .build(); Ok(geo_features::FeatureCollection::from_feature(feature)) } @@ -110,7 +108,7 @@ fn geojson_feature_to_geo_feature( { feature_builder = feature_builder.with_geometry(geo_geometry); } - Ok(feature_builder.build()?) + Ok(feature_builder.build()) } fn geojson_feature_properties_to_geo_features_properties( diff --git a/geo-file-loader/src/shapefile.rs b/geo-file-loader/src/shapefile.rs index fef147b9..899fa5b4 100644 --- a/geo-file-loader/src/shapefile.rs +++ b/geo-file-loader/src/shapefile.rs @@ -19,6 +19,6 @@ impl crate::FileLoader for ShapefileSource { let mut geo_writer = geozero::geo_types::GeoWriter::new(); for _ in shapefile_reader.iter_geometries(&mut geo_writer) {} let geometry = geo_writer.take_geometry().unwrap(); - Ok(geo_features::FeatureCollection::from_geometry(geometry).unwrap()) + Ok(geo_features::FeatureCollection::from_geometry(geometry)) } } diff --git a/geo-file-loader/src/wkt.rs b/geo-file-loader/src/wkt.rs index 987e16dc..c721ec60 100644 --- a/geo-file-loader/src/wkt.rs +++ b/geo-file-loader/src/wkt.rs @@ -4,8 +4,6 @@ use geozero::GeozeroDatasource; #[derive(thiserror::Error, Debug)] pub enum Error { - #[error("{0}")] - BoundingRect(#[from] geo_features::BoundingRectError), #[error("{0}")] Geozero(#[from] geozero::error::GeozeroError), } @@ -29,7 +27,7 @@ impl crate::FileLoader for WktSource { let mut geo_writer = geozero::geo_types::GeoWriter::new(); wkt_reader.process(&mut geo_writer)?; match geo_writer.take_geometry() { - Some(geometry) => Ok(geo_features::FeatureCollection::from_geometry(geometry)?), + Some(geometry) => Ok(geo_features::FeatureCollection::from_geometry(geometry)), None => Ok(geo_features::FeatureCollection::default()), } } diff --git a/geo-projected/src/feature_collection.rs b/geo-projected/src/feature_collection.rs index e0058ac8..49ae618b 100644 --- a/geo-projected/src/feature_collection.rs +++ b/geo-projected/src/feature_collection.rs @@ -37,8 +37,8 @@ macro_rules! feature_collection_impl { impl $outer_ty<$specific_inner_ty> { pub fn from_geometry( geometry: geo::Geometry, - ) -> Result<$outer_ty<$general_inner_ty>, geo_features::BoundingRectError> { - <$general_inner_ty>::from_geometry(geometry).map($outer_ty) + ) -> $outer_ty<$general_inner_ty> { + $outer_ty(<$general_inner_ty>::from_geometry(geometry)) } pub fn features_iter(&self) -> impl Iterator> { diff --git a/rgis-geo-ops/src/convex_hull.rs b/rgis-geo-ops/src/convex_hull.rs index 2a27d9a8..b71ccf0a 100644 --- a/rgis-geo-ops/src/convex_hull.rs +++ b/rgis-geo-ops/src/convex_hull.rs @@ -27,7 +27,7 @@ impl Operation for ConvexHull { let outcome = geo::GeometryCollection(geometries).convex_hull(); Ok(Outcome::FeatureCollection(geo_projected::Unprojected::new( - geo_features::FeatureCollection::from_geometry(outcome.into())?, + geo_features::FeatureCollection::from_geometry(outcome.into()), ))) } } diff --git a/rgis-geo-ops/src/outliers.rs b/rgis-geo-ops/src/outliers.rs index 9c50f5f0..fe45558b 100644 --- a/rgis-geo-ops/src/outliers.rs +++ b/rgis-geo-ops/src/outliers.rs @@ -42,7 +42,7 @@ impl Operation for Outliers { let new_multi_point = geo::MultiPoint::new(non_outliers); Ok(Outcome::FeatureCollection(geo_projected::Unprojected::new( - geo_features::FeatureCollection::from_geometry(new_multi_point.into())?, + geo_features::FeatureCollection::from_geometry(new_multi_point.into()), ))) } } diff --git a/rgis-geo-ops/src/simplify.rs b/rgis-geo-ops/src/simplify.rs index ff4711ce..59cedaa8 100644 --- a/rgis-geo-ops/src/simplify.rs +++ b/rgis-geo-ops/src/simplify.rs @@ -103,7 +103,7 @@ impl Operation for Simplify { Ok(Outcome::FeatureCollection(geo_projected::Unprojected::new( geo_features::FeatureCollection::from_geometry(geo::Geometry::GeometryCollection( simplified, - ))?, + )), ))) } } diff --git a/rgis-geo-ops/src/smoothing.rs b/rgis-geo-ops/src/smoothing.rs index 22d8b2c2..0528999b 100644 --- a/rgis-geo-ops/src/smoothing.rs +++ b/rgis-geo-ops/src/smoothing.rs @@ -53,7 +53,7 @@ impl Operation for Smoothing { Ok(Outcome::FeatureCollection(geo_projected::Unprojected::new( geo_features::FeatureCollection::from_geometry(geo::Geometry::GeometryCollection( smoothed, - ))?, + )), ))) } } diff --git a/rgis-geo-ops/src/triangulate.rs b/rgis-geo-ops/src/triangulate.rs index 33501898..a999122d 100644 --- a/rgis-geo-ops/src/triangulate.rs +++ b/rgis-geo-ops/src/triangulate.rs @@ -38,7 +38,7 @@ impl Operation for Triangulate { ); Ok(Outcome::FeatureCollection(geo_projected::Unprojected::new( - geo_features::FeatureCollection::from_geometry(multi_polygon.into())?, + geo_features::FeatureCollection::from_geometry(multi_polygon.into()), ))) } } diff --git a/rgis-layers/src/lib.rs b/rgis-layers/src/lib.rs index ca13453d..80eb8633 100644 --- a/rgis-layers/src/lib.rs +++ b/rgis-layers/src/lib.rs @@ -151,7 +151,7 @@ impl Layers { unprojected: geo_projected::Unprojected, name: String, source_crs: String, - ) -> Result { + ) -> rgis_layer_id::LayerId { let layer_id = self.next_layer_id(); let geom_type = geo_geom_type::determine(unprojected.as_raw().geometry_iter()); let layer = Layer { @@ -175,7 +175,7 @@ impl Layers { geom_type, }; self.data.push(layer); - Ok(layer_id) + layer_id } pub fn clear_projected(&mut self) { diff --git a/rgis-layers/src/systems.rs b/rgis-layers/src/systems.rs index 82765840..67bc37b4 100644 --- a/rgis-layers/src/systems.rs +++ b/rgis-layers/src/systems.rs @@ -127,12 +127,8 @@ fn handle_create_layer_events( mut layers: ResMut, ) { for event in create_layer_events.drain() { - match layers.add(event.feature_collection, event.name, event.source_crs) { - Ok(layer_id) => { - layer_created_event_writer.send(rgis_events::LayerCreatedEvent(layer_id)) - } - Err(e) => bevy::log::error!("Encountered error when creating layer: {:?}", e), - } + let layer_id = layers.add(event.feature_collection, event.name, event.source_crs); + layer_created_event_writer.send(rgis_events::LayerCreatedEvent(layer_id)) } } diff --git a/rgis-transform/src/jobs.rs b/rgis-transform/src/jobs.rs index eb823e2b..cee4b010 100644 --- a/rgis-transform/src/jobs.rs +++ b/rgis-transform/src/jobs.rs @@ -36,10 +36,10 @@ impl bevy_jobs::Job for ReprojectGeometryJob { transformer.transform(geometry)?; } - feature.0.recalculate_bounding_rect()?; + feature.0.recalculate_bounding_rect(); } - self.feature_collection.0.recalculate_bounding_rect()?; + self.feature_collection.0.recalculate_bounding_rect(); Ok(ReprojectGeometryJobOutcome { feature_collection: self.feature_collection.into_projected(), diff --git a/rgis-transform/src/lib.rs b/rgis-transform/src/lib.rs index ddf1fe35..2859e9fa 100644 --- a/rgis-transform/src/lib.rs +++ b/rgis-transform/src/lib.rs @@ -35,8 +35,6 @@ pub enum TransformError { #[cfg(not(target_arch = "wasm32"))] #[error("{0}")] Proj(#[from] geo::algorithm::proj::TransformError), - #[error("{0}")] - BoundingRect(#[from] geo_features::BoundingRectError), } pub trait Transformer { diff --git a/rgis-ui/src/side_panel.rs b/rgis-ui/src/side_panel.rs index 4c8a95f2..f4b1732e 100644 --- a/rgis-ui/src/side_panel.rs +++ b/rgis-ui/src/side_panel.rs @@ -130,46 +130,42 @@ impl<'a, 'w> SidePanel<'a, 'w> { if let Ok(bounding_rect) = layer.unprojected_feature_collection.bounding_rect() { - if let Ok(feature_collection) = geo_projected::Unprojected::< + let feature_collection = geo_projected::Unprojected::< geo_features::FeatureCollection, >::from_geometry( bounding_rect.0.into() - ) { - self.events.create_layer_event_writer.send( - rgis_events::CreateLayerEvent { - feature_collection, // todo - name: "Bounding rect".into(), // todo - source_crs: layer.crs.clone(), - }, - ); - } + ); + self.events.create_layer_event_writer.send( + rgis_events::CreateLayerEvent { + feature_collection, // todo + name: "Bounding rect".into(), // todo + source_crs: layer.crs.clone(), + }, + ); } } OperationButton::::new( self.events, layer, - ).ui(ui); - OperationButton::::new( - self.events, - layer, - ).ui(ui); - OperationButton::::new( - self.events, - layer, - ).ui(ui); - OperationButton::::new( - self.events, - layer, - ).ui(ui); + ) + .ui(ui); + OperationButton::::new(self.events, layer) + .ui(ui); + OperationButton::::new(self.events, layer) + .ui(ui); + OperationButton::::new(self.events, layer) + .ui(ui); OperationButton::::new( self.events, layer, - ).ui(ui); + ) + .ui(ui); OperationButton::::new( self.events, layer, - ).ui(ui); + ) + .ui(ui); }); }); });