Skip to content

Commit

Permalink
use match for optionality checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Rennzie committed Nov 2, 2023
1 parent 1b949bc commit 0446ed1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
29 changes: 18 additions & 11 deletions src/inner_op/deformation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,25 @@ pub fn new(parameters: &RawParameters, ctx: &dyn Context) -> Result<Op, Error> {
continue;
}

// TODO: Handle @optional grids

let grid = ctx.get_grid(&grid_name)?;
let n = grid.bands();
if n != 3 {
return Err(Error::Unexpected {
message: "Bad dimensionality of deformation model grid".to_string(),
expected: "3".to_string(),
found: n.to_string(),
});
match ctx.get_grid(&grid_name) {
Ok(grid) => {
let n = grid.bands();
if n != 3 {
return Err(Error::Unexpected {
message: "Bad dimensionality of deformation model grid".to_string(),
expected: "3".to_string(),
found: n.to_string(),
});
}
params.grids.push(grid);
}
Err(e) => {
if grid_name.contains("@") {
continue;
}
return Err(e);
}
}
params.grids.push(grid);
}

let fwd = InnerOp(fwd);
Expand Down
17 changes: 8 additions & 9 deletions src/inner_op/gridshift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,18 @@ pub fn new(parameters: &RawParameters, ctx: &dyn Context) -> Result<Op, Error> {
for grid_name in params.texts("grids")?.clone() {
if grid_name.ends_with("@null") {
params.boolean.insert("null_grid");
// @null can only be used as the final grid
break;
continue;
}

if grid_name.contains("@") {
if let Ok(grid) = ctx.get_grid(&grid_name) {
params.grids.push(grid);
match ctx.get_grid(&grid_name) {
Ok(grid) => params.grids.push(grid),
Err(e) => {
if grid_name.contains("@") {
continue;
}
return Err(e);
}
continue;
}

let grid = ctx.get_grid(&grid_name)?;
params.grids.push(grid);
}

let fwd = InnerOp(fwd);
Expand Down

0 comments on commit 0446ed1

Please sign in to comment.