Skip to content

Commit

Permalink
Handle object proccess errors
Browse files Browse the repository at this point in the history
  • Loading branch information
3dpass committed Sep 30, 2023
1 parent 914cf44 commit cfd70b0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use alloc::string::String;
use alloc::vec::Vec;

use obj::{load_obj, Obj, Vertex};
use obj::{load_obj, Obj, Vertex, ObjError};
use tri_mesh::prelude::*;
use cgmath::Point2;

Expand All @@ -15,6 +15,7 @@ extern crate alloc;

use ndarray::arr2;
use ndarray::Array3;
use tri_mesh::mesh_builder::Error as MeshError;
use crate::algo_grid::{get_contour, intersect, intersect_2};
use crate::contour::Rect;

Expand All @@ -40,7 +41,11 @@ pub enum AlgoType {
}

#[derive(Debug)]
pub struct P3DError {}
pub enum P3DError {
InvalidObject(ObjError),
MeshError(MeshError),
MathError,
}


#[allow(unused_variables)]
Expand All @@ -56,7 +61,7 @@ pub fn p3d_process_n(input: &[u8], algo: AlgoType, depth: usize, par1: i16, par2
let grid_size: i16 = par1;
let n_sections: i16 = par2;

let model: Obj<Vertex, u32> = load_obj(input).unwrap();
let model: Obj<Vertex, u32> = load_obj(input).map_err(|e| P3DError::InvalidObject(e))?;

let verts = model.vertices
.iter()
Expand All @@ -67,7 +72,8 @@ pub fn p3d_process_n(input: &[u8], algo: AlgoType, depth: usize, par1: i16, par2
let mut mesh = MeshBuilder::new()
.with_indices(model.indices)
.with_positions(verts)
.build().unwrap();
.build()
.map_err(|e| P3DError::MeshError(e))?;

let mut triangles: Array3<f64> = Array3::zeros((mesh.no_faces(), 3, 3));

Expand Down Expand Up @@ -95,7 +101,7 @@ pub fn p3d_process_n(input: &[u8], algo: AlgoType, depth: usize, par1: i16, par2
pit[[2,0]], pit[[2,1]], pit[[2,2]],
); //.transpose();

let b = a.invert().unwrap();
let b = a.invert().ok_or(P3DError::MathError)?;

let tr: Matrix4<f64> = Matrix4::new(
b.x[0], b.x[1], b.x[2], 0.0,
Expand Down

0 comments on commit cfd70b0

Please sign in to comment.