Skip to content

Commit

Permalink
remove unwrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Nov 21, 2024
1 parent 0da58b8 commit 17813be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 10 additions & 5 deletions rgis-camera/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ struct CameraOffset {
pub y: f32,
}

#[derive(Debug)]
enum Error {
FloatConversion,
}

impl CameraOffset {
fn from_coord<Scalar: geo::CoordFloat>(coord: geo::Coord<Scalar>) -> Self {
CameraOffset {
x: coord.x.to_f32().unwrap(),
y: coord.y.to_f32().unwrap(),
}
fn from_coord<Scalar: geo::CoordFloat>(coord: geo::Coord<Scalar>) -> Result<Self, Error> {
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 {
Expand Down
8 changes: 7 additions & 1 deletion rgis-camera/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 17813be

Please sign in to comment.