diff --git a/rgis-camera/src/lib.rs b/rgis-camera/src/lib.rs index 7b95676..1796e68 100644 --- a/rgis-camera/src/lib.rs +++ b/rgis-camera/src/lib.rs @@ -44,12 +44,17 @@ struct CameraOffset { pub y: f32, } +#[derive(Debug)] +enum Error { + FloatConversion, +} + impl CameraOffset { - fn from_coord(coord: geo::Coord) -> Self { - CameraOffset { - x: coord.x.to_f32().unwrap(), - y: coord.y.to_f32().unwrap(), - } + fn from_coord(coord: geo::Coord) -> Result { + Ok(CameraOffset { + x: coord.x.to_f32().ok_or(Error::FloatConversion)?, + y: coord.y.to_f32().ok_or(Error::FloatConversion)?, + }) } fn from_transform(transform: &Transform) -> Self { diff --git a/rgis-camera/src/utils.rs b/rgis-camera/src/utils.rs index e2051ab..2d34661 100644 --- a/rgis-camera/src/utils.rs +++ b/rgis-camera/src/utils.rs @@ -8,7 +8,13 @@ pub(crate) fn center_camera_on_projected_world_rect( let layer_center = bounding_rect.center(); let scale = determine_scale(bounding_rect, map_area.size()); let camera_scale = crate::CameraScale(scale); - let mut camera_offset = crate::CameraOffset::from_coord(layer_center); + let mut camera_offset = match crate::CameraOffset::from_coord(layer_center) { + Ok(offset) => offset, + Err(e) => { + error!("Error converting layer center to camera offset: {:?}", e); + return; + } + }; camera_offset.pan_x( (map_area.right_offset_px - map_area.left_offset_px) / 2., camera_scale,