From a1f1c1ab5cdaa6f368f7fb78d2a433709eae20f0 Mon Sep 17 00:00:00 2001 From: Dorival Pedroso Date: Mon, 30 Dec 2024 10:28:18 +1000 Subject: [PATCH 1/6] [wip] Improve status/error code handling --- c_code/constants.h | 2 ++ src/constants.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/c_code/constants.h b/c_code/constants.h index 94970a1..5778294 100644 --- a/c_code/constants.h +++ b/c_code/constants.h @@ -28,4 +28,6 @@ const int32_t TRITET_ERROR_INVALID_FACET_POINT_ID = 7000; const int32_t TRITET_ERROR_INVALID_REGION_INDEX = 8000; const int32_t TRITET_ERROR_INVALID_HOLE_INDEX = 9000; +const int32_t TRITET_ERROR_TETGEN_FAIL = 10000; + #endif // CONSTANTS_H diff --git a/src/constants.rs b/src/constants.rs index 388a2a8..fc77150 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,3 +1,5 @@ +use crate::StrError; + pub(crate) const TRITET_SUCCESS: i32 = 0; pub(crate) const TRITET_ERROR_NULL_DATA: i32 = 10; @@ -20,6 +22,74 @@ pub(crate) const TRITET_ERROR_INVALID_FACET_POINT_ID: i32 = 7000; pub(crate) const TRITET_ERROR_INVALID_REGION_INDEX: i32 = 8000; pub(crate) const TRITET_ERROR_INVALID_HOLE_INDEX: i32 = 9000; +pub(crate) const TRITET_ERROR_TETGEN_FAIL: i32 = 10000; + +pub(crate) fn handle_status(status: i32) -> Result<(), StrError> { + if status == TRITET_SUCCESS { + return Ok(()); + } + + if status == TRITET_ERROR_NULL_DATA { + return Err("INTERNAL ERROR: found NULL data"); + } + if status == TRITET_ERROR_STRING_CONCAT { + return Err("INTERNAL ERROR: cannot write string with commands for TetGen"); + } + + if status == TRITET_ERROR_NULL_POINT_LIST { + return Err("INTERNAL ERROR: found NULL point list"); + } + if status == TRITET_ERROR_NULL_SEGMENT_LIST { + return Err("INTERNAL ERROR: found NULL segment list"); + } + if status == TRITET_ERROR_NULL_FACET_LIST { + return Err("INTERNAL ERROR: found NULL facet list"); + } + if status == TRITET_ERROR_NULL_FACET_POLYGON_LIST { + return Err("INTERNAL ERROR: found NULL facet polygon list"); + } + if status == TRITET_ERROR_NULL_REGION_LIST { + return Err("INTERNAL ERROR: found NULL region list"); + } + if status == TRITET_ERROR_NULL_HOLE_LIST { + return Err("INTERNAL ERROR: found NULL hole list"); + } + + if status == TRITET_ERROR_INVALID_POINT_INDEX { + return Err("index of point is out of bounds"); + } + if status == TRITET_ERROR_INVALID_SEGMENT_INDEX { + return Err("index of segment is out of bounds"); + } + if status == TRITET_ERROR_INVALID_SEGMENT_POINT_ID { + return Err("id of segment point is out of bounds"); + } + if status == TRITET_ERROR_INVALID_FACET_INDEX { + return Err("index of facet is out of bounds"); + } + if status == TRITET_ERROR_INVALID_FACET_NUM_POLYGON { + return Err("INTERNAL ERROR: found invalid facet number of polygon"); + } + if status == TRITET_ERROR_INVALID_FACET_POINT_INDEX { + return Err("index of facet point is out of bounds"); + } + if status == TRITET_ERROR_INVALID_FACET_POINT_ID { + return Err("id of facet point is out of bounds"); + } + if status == TRITET_ERROR_INVALID_REGION_INDEX { + return Err("index of region is out of bounds"); + } + if status == TRITET_ERROR_INVALID_HOLE_INDEX { + return Err("index of hole is out of bounds"); + } + + if status == TRITET_ERROR_TETGEN_FAIL { + return Err("TetGen failed: points are probably coplanar"); + } + + return Err("INTERNAL ERROR: some error occurred"); +} + /// Maps indices used in this library (tritet) to indices used in Triangle /// /// ```text From cafab18551fc1a10f335dcb57b72e92193078e1b Mon Sep 17 00:00:00 2001 From: Dorival Pedroso Date: Mon, 30 Dec 2024 10:30:15 +1000 Subject: [PATCH 2/6] [wip] Use handle_status function in tetgen.rs --- src/tetgen.rs | 123 ++++++++++---------------------------------------- 1 file changed, 24 insertions(+), 99 deletions(-) diff --git a/src/tetgen.rs b/src/tetgen.rs index bd3881a..f18e6d9 100644 --- a/src/tetgen.rs +++ b/src/tetgen.rs @@ -1,4 +1,4 @@ -use crate::constants; +use crate::constants::{handle_status, DARK_COLORS, TRITET_TO_TETGEN}; use crate::conversion::to_i32; use crate::StrError; use plotpy::{Canvas, Plot, Text}; @@ -250,18 +250,7 @@ impl Tetgen { pub fn set_point(&mut self, index: usize, marker: i32, x: f64, y: f64, z: f64) -> Result<&mut Self, StrError> { unsafe { let status = tet_set_point(self.ext_tetgen, to_i32(index), marker, x, y, z); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_POINT_LIST { - return Err("INTERNAL ERROR: found NULL point list"); - } - if status == constants::TRITET_ERROR_INVALID_POINT_INDEX { - return Err("index of point is out of bounds"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } if index == self.npoint - 1 { self.all_points_set = true; @@ -285,30 +274,7 @@ impl Tetgen { }; unsafe { let status = tet_set_facet_point(self.ext_tetgen, to_i32(index), to_i32(m), to_i32(p)); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_FACET_LIST { - return Err("INTERNAL ERROR: found NULL facet list"); - } - if status == constants::TRITET_ERROR_INVALID_FACET_INDEX { - return Err("index of facet is out of bounds"); - } - if status == constants::TRITET_ERROR_NULL_FACET_POLYGON_LIST { - return Err("INTERNAL ERROR: found NULL facet polygon list"); - } - if status == constants::TRITET_ERROR_INVALID_FACET_NUM_POLYGON { - return Err("INTERNAL ERROR: found invalid facet number of polygon"); - } - if status == constants::TRITET_ERROR_INVALID_FACET_POINT_INDEX { - return Err("index of facet point is out of bounds"); - } - if status == constants::TRITET_ERROR_INVALID_FACET_POINT_ID { - return Err("id of facet point is out of bounds"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } if index == 0 && m == 0 { self.facet_point_set_count = 0; @@ -333,18 +299,7 @@ impl Tetgen { }; unsafe { let status = tet_set_facet_marker(self.ext_tetgen, to_i32(index), marker); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_FACET_LIST { - return Err("INTERNAL ERROR: found NULL facet list"); - } - if status == constants::TRITET_ERROR_INVALID_FACET_INDEX { - return Err("index of facet is out of bounds"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } Ok(self) } @@ -386,18 +341,7 @@ impl Tetgen { z, volume_constraint, ); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_REGION_LIST { - return Err("INTERNAL ERROR: found NULL region list"); - } - if status == constants::TRITET_ERROR_INVALID_REGION_INDEX { - return Err("index of region is out of bounds"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } if index == nregion - 1 { self.all_regions_set = true; @@ -422,18 +366,7 @@ impl Tetgen { }; unsafe { let status = tet_set_hole(self.ext_tetgen, to_i32(index), x, y, z); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_HOLE_LIST { - return Err("INTERNAL ERROR: found NULL hole list"); - } - if status == constants::TRITET_ERROR_INVALID_HOLE_INDEX { - return Err("index of hole is out of bounds"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } if index == nhole - 1 { self.all_holes_set = true; @@ -454,15 +387,7 @@ impl Tetgen { } unsafe { let status = tet_run_delaunay(self.ext_tetgen, if verbose { 1 } else { 0 }); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_POINT_LIST { - return Err("INTERNAL ERROR: found NULL point list"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } Ok(()) } @@ -506,21 +431,7 @@ impl Tetgen { max_volume, min_angle, ); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_POINT_LIST { - return Err("INTERNAL ERROR: found NULL point list"); - } - if status == constants::TRITET_ERROR_NULL_FACET_LIST { - return Err("INTERNAL ERROR: list of facets must be defined first"); - } - if status == constants::TRITET_ERROR_STRING_CONCAT { - return Err("INTERNAL ERROR: cannot write string with commands for Tetgen"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } Ok(()) } @@ -609,7 +520,7 @@ impl Tetgen { /// This function will return 0 if `index` or `m` is out of range. pub fn out_cell_point(&self, index: usize, m: usize) -> usize { unsafe { - let corner = constants::TRITET_TO_TETGEN[m]; + let corner = TRITET_TO_TETGEN[m]; tet_out_cell_point(self.ext_tetgen, to_i32(index), to_i32(corner)) as usize } } @@ -772,7 +683,7 @@ impl Tetgen { let mut max = vec![f64::MIN; 3]; let mut colors: HashMap = HashMap::new(); let mut index_color = 0; - let clr = constants::DARK_COLORS; + let clr = DARK_COLORS; for tet in 0..ntet { let attribute = self.out_cell_attribute(tet); let color = match colors.get(&attribute) { @@ -1392,4 +1303,18 @@ mod tests { } Ok(()) } + + #[test] + fn handle_assert_1() -> Result<(), StrError> { + let mut tetgen = Tetgen::new(4, None, None, None)?; + tetgen.set_point(0, 0, -1.0, 0.0, 0.0)?; // z=0 + tetgen.set_point(1, 0, 0.0, 0.0, 0.0)?; // z=0 + tetgen.set_point(2, 0, 1.0, 0.0, 0.0)?; // z=0 + tetgen.set_point(3, 0, 0.0, 1.0, 0.0)?; // z=0, thus, all points are coplanar + assert_eq!( + tetgen.generate_delaunay(false).err(), + Some("TetGen failed: points are probably coplanar") + ); + Ok(()) + } } From af2da63b5f852b2d06056298f229fe59fe01a6c4 Mon Sep 17 00:00:00 2001 From: Dorival Pedroso Date: Mon, 30 Dec 2024 10:37:20 +1000 Subject: [PATCH 3/6] [Important] Remove assert. Return status/error code from exactinit and tetrahedralize --- c_code/interface_tetgen.cpp | 10 ++++++++-- c_code/predicates.cxx | 23 +++++++++++++++++------ c_code/tetgen.cxx | 25 ++++++++++++++++++------- c_code/tetgen.h | 6 +++--- 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/c_code/interface_tetgen.cpp b/c_code/interface_tetgen.cpp index 32e9ce5..39a6eb6 100644 --- a/c_code/interface_tetgen.cpp +++ b/c_code/interface_tetgen.cpp @@ -228,7 +228,10 @@ int32_t tet_run_delaunay(struct ExtTetgen *tetgen, int32_t verbose) { strcat(command, "Q"); } try { - tetrahedralize(command, &tetgen->input, &tetgen->output, NULL, NULL); + int status = tetrahedralize(command, &tetgen->input, &tetgen->output, NULL, NULL); + if (status != 0) { + return TRITET_ERROR_TETGEN_FAIL; + } } catch (int32_t status) { printf("status = %d\n", status); // TODO } catch (...) { @@ -318,7 +321,10 @@ int32_t tet_run_tetrahedralize(struct ExtTetgen *tetgen, int32_t verbose, int32_ strcat(command, "q"); } try { - tetrahedralize(command, &tetgen->input, &tetgen->output, NULL, NULL); + int status = tetrahedralize(command, &tetgen->input, &tetgen->output, NULL, NULL); + if (status != 0) { + return TRITET_ERROR_TETGEN_FAIL; + } } catch (int32_t status) { printf("status = %d\n", status); // TODO } catch (...) { diff --git a/c_code/predicates.cxx b/c_code/predicates.cxx index 2b0464e..276b4c9 100644 --- a/c_code/predicates.cxx +++ b/c_code/predicates.cxx @@ -125,7 +125,6 @@ // dorival / gemlab #include "tetgen.h" // Defines the symbol REAL (float or double). #define REAL double // dorival / gemlab -#include // dorival / gemlab #ifdef USE_CGAL_PREDICATES #include @@ -540,9 +539,13 @@ int test_double(int verbose) /* */ /* Don't change this routine unless you fully understand it. */ /* */ +/* Dorival: */ +/* Returns 1 if errors are found */ +/* Returns 0 if OK */ +/* */ /*****************************************************************************/ -void exactinit(int verbose, int noexact, int nofilter, REAL maxx, REAL maxy, +int exactinit(int verbose, int noexact, int nofilter, REAL maxx, REAL maxy, REAL maxz) { REAL half; @@ -630,11 +633,18 @@ void exactinit(int verbose, int noexact, int nofilter, REAL maxx, REAL maxy, // Calculate the two static filters for orient3d() and insphere() tests. // Added by H. Si, 2012-08-23. - // Sort maxx < maxy < maxz. Re-use 'half' for swapping. - assert(maxx > 0); - assert(maxy > 0); - assert(maxz > 0); + // dorival: make sure the points are not coplanar + if (!(maxx > 0)) { + return 1; // error + } + if (!(maxy > 0)) { + return 1; // error + } + if (!(maxz > 0)) { + return 1; // error + } + // Sort maxx < maxy < maxz. Re-use 'half' for swapping. if (maxx > maxz) { half = maxx; maxx = maxz; maxz = half; } @@ -648,6 +658,7 @@ void exactinit(int verbose, int noexact, int nofilter, REAL maxx, REAL maxy, o3dstaticfilter = 5.1107127829973299e-15 * maxx * maxy * maxz; ispstaticfilter = 1.2466136531027298e-13 * maxx * maxy * maxz * (maxz * maxz); + return 0; // dorival: OK: no errors found } /*****************************************************************************/ diff --git a/c_code/tetgen.cxx b/c_code/tetgen.cxx index 0c38b79..716c860 100644 --- a/c_code/tetgen.cxx +++ b/c_code/tetgen.cxx @@ -30875,9 +30875,12 @@ void tetgenmesh::outmesh2vtk(char* ofilename) // - Write the output files and print the statistics. // // - Check the consistency of the mesh (-C). // // // +// Dorival: // +// Returns 1 if errors are found // +// Returns 0 if OK // /////////////////////////////////////////////////////////////////////////////// -void tetrahedralize(tetgenbehavior *b, tetgenio *in, tetgenio *out, +int tetrahedralize(tetgenbehavior *b, tetgenio *in, tetgenio *out, tetgenio *addin, tetgenio *bgmin) { #ifdef DORIDEBUG @@ -30953,9 +30956,13 @@ void tetrahedralize(tetgenbehavior *b, tetgenio *in, tetgenio *out, m.initializepools(); m.transfernodes(); - exactinit(b->verbose, b->noexact, b->nostaticfilter, + int status = exactinit(b->verbose, b->noexact, b->nostaticfilter, m.xmax - m.xmin, m.ymax - m.ymin, m.zmax - m.zmin); + if (status != 0) { + return 1; // dorival: error found + } + tv[1] = clock(); if (b->refine) { // -r @@ -31001,7 +31008,7 @@ void tetrahedralize(tetgenbehavior *b, tetgenio *in, tetgenio *out, m.outsubfaces(out); } - return; + return 0; // dorival: OK: no errors found } } @@ -31265,6 +31272,8 @@ void tetrahedralize(tetgenbehavior *b, tetgenio *in, tetgenio *out, if (!b->quiet) { m.statistics(); } + + return 0; // dorival: OK: no errors found } #ifndef TETLIBRARY @@ -31285,7 +31294,7 @@ int main(int argc, char *argv[]) // // /////////////////////////////////////////////////////////////////////////////// -void tetrahedralize(char const *switches, tetgenio *in, tetgenio *out, +int tetrahedralize(char const *switches, tetgenio *in, tetgenio *out, tetgenio *addin, tetgenio *bgmin, char const *outfilename) // dorival @@ -31321,9 +31330,9 @@ void tetrahedralize(char const *switches, tetgenio *in, tetgenio *out, bgmin.load_tetmesh(b.bgmeshfilename, (int) b.object); } - tetrahedralize(&b, &in, NULL, &addin, &bgmin); + int status = tetrahedralize(&b, &in, NULL, &addin, &bgmin); - return 0; + return status; // dorival #else // with TETLIBRARY @@ -31336,7 +31345,9 @@ void tetrahedralize(char const *switches, tetgenio *in, tetgenio *out, strcpy(b.outfilename, outfilename); // dorival } // dorival - tetrahedralize(&b, in, out, addin, bgmin); + int status = tetrahedralize(&b, in, out, addin, bgmin); + + return status; // dorival #endif // not TETLIBRARY } diff --git a/c_code/tetgen.h b/c_code/tetgen.h index 496eff7..ae99241 100644 --- a/c_code/tetgen.h +++ b/c_code/tetgen.h @@ -793,7 +793,7 @@ class tetgenbehavior { // // /////////////////////////////////////////////////////////////////////////////// -void exactinit(int, int, int, REAL, REAL, REAL); +int exactinit(int, int, int, REAL, REAL, REAL); REAL orient3d(REAL *pa, REAL *pb, REAL *pc, REAL *pd); REAL insphere(REAL *pa, REAL *pb, REAL *pc, REAL *pd, REAL *pe); REAL orient4d(REAL *pa, REAL *pb, REAL *pc, REAL *pd, REAL *pe, @@ -2226,11 +2226,11 @@ class tetgenmesh { // // /////////////////////////////////////////////////////////////////////////////// -void tetrahedralize(tetgenbehavior *b, tetgenio *in, tetgenio *out, +int tetrahedralize(tetgenbehavior *b, tetgenio *in, tetgenio *out, tetgenio *addin = NULL, tetgenio *bgmin = NULL); #ifdef TETLIBRARY -void tetrahedralize(char const *switches, tetgenio *in, tetgenio *out, +int tetrahedralize(char const *switches, tetgenio *in, tetgenio *out, tetgenio *addin = NULL, tetgenio *bgmin = NULL, char const *outfilename=NULL); // dorival #endif // #ifdef TETLIBRARY From 1bc4bcd9d9b45ea6fc25577a2b09bde585cf693e Mon Sep 17 00:00:00 2001 From: Dorival Pedroso Date: Mon, 30 Dec 2024 10:39:19 +1000 Subject: [PATCH 4/6] Rename test fn --- src/tetgen.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tetgen.rs b/src/tetgen.rs index f18e6d9..33c1391 100644 --- a/src/tetgen.rs +++ b/src/tetgen.rs @@ -1305,7 +1305,7 @@ mod tests { } #[test] - fn handle_assert_1() -> Result<(), StrError> { + fn handle_coplanar_points() -> Result<(), StrError> { let mut tetgen = Tetgen::new(4, None, None, None)?; tetgen.set_point(0, 0, -1.0, 0.0, 0.0)?; // z=0 tetgen.set_point(1, 0, 0.0, 0.0, 0.0)?; // z=0 From 9a987a74179df456120726b12f6cda1fd5cc8ea6 Mon Sep 17 00:00:00 2001 From: Dorival Pedroso Date: Mon, 30 Dec 2024 11:01:10 +1000 Subject: [PATCH 5/6] Use handle_status in trigen.rs --- src/trigen.rs | 97 ++++++--------------------------------------------- 1 file changed, 10 insertions(+), 87 deletions(-) diff --git a/src/trigen.rs b/src/trigen.rs index bdccb34..5b9f18e 100644 --- a/src/trigen.rs +++ b/src/trigen.rs @@ -1,4 +1,4 @@ -use crate::constants; +use crate::constants::{handle_status, TRITET_TO_TRIANGLE,LIGHT_COLORS}; use crate::conversion::to_i32; use crate::StrError; use plotpy::{Canvas, Curve, Plot, PolyCode, Text}; @@ -347,18 +347,7 @@ impl Trigen { pub fn set_point(&mut self, index: usize, marker: i32, x: f64, y: f64) -> Result<&mut Self, StrError> { unsafe { let status = tri_set_point(self.ext_trigen, to_i32(index), marker, x, y); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_POINT_LIST { - return Err("INTERNAL ERROR: found NULL point list"); - } - if status == constants::TRITET_ERROR_INVALID_POINT_INDEX { - return Err("index of point is out of bounds"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } if index == self.npoint - 1 { self.all_points_set = true; @@ -391,21 +380,7 @@ impl Trigen { }; unsafe { let status = tri_set_segment(self.ext_trigen, to_i32(index), marker, to_i32(a), to_i32(b)); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_SEGMENT_LIST { - return Err("INTERNAL ERROR: found NULL segment list"); - } - if status == constants::TRITET_ERROR_INVALID_SEGMENT_INDEX { - return Err("index of segment is out of bounds"); - } - if status == constants::TRITET_ERROR_INVALID_SEGMENT_POINT_ID { - return Err("id of segment point is out of bounds"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } if index == nsegment - 1 { self.all_segments_set = true; @@ -442,18 +417,7 @@ impl Trigen { }; unsafe { let status = tri_set_region(self.ext_trigen, to_i32(index), to_i32(attribute), x, y, area_constraint); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_REGION_LIST { - return Err("INTERNAL ERROR: found NULL region list"); - } - if status == constants::TRITET_ERROR_INVALID_REGION_INDEX { - return Err("index of region is out of bounds"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } if index == nregion - 1 { self.all_regions_set = true; @@ -477,18 +441,7 @@ impl Trigen { }; unsafe { let status = tri_set_hole(self.ext_trigen, to_i32(index), x, y); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_HOLE_LIST { - return Err("INTERNAL ERROR: found NULL hole list"); - } - if status == constants::TRITET_ERROR_INVALID_HOLE_INDEX { - return Err("index of hole is out of bounds"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } if index == nhole - 1 { self.all_holes_set = true; @@ -509,15 +462,7 @@ impl Trigen { } unsafe { let status = tri_run_delaunay(self.ext_trigen, if verbose { 1 } else { 0 }); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_POINT_LIST { - return Err("INTERNAL ERROR: found NULL point list"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } Ok(()) } @@ -533,15 +478,7 @@ impl Trigen { } unsafe { let status = tri_run_voronoi(self.ext_trigen, if verbose { 1 } else { 0 }); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_POINT_LIST { - return Err("INTERNAL ERROR: found NULL point list"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } Ok(()) } @@ -586,21 +523,7 @@ impl Trigen { max_area, min_angle, ); - if status != constants::TRITET_SUCCESS { - if status == constants::TRITET_ERROR_NULL_DATA { - return Err("INTERNAL ERROR: found NULL data"); - } - if status == constants::TRITET_ERROR_NULL_POINT_LIST { - return Err("INTERNAL ERROR: found NULL point list"); - } - if status == constants::TRITET_ERROR_NULL_SEGMENT_LIST { - return Err("INTERNAL ERROR: list of segments must be defined first"); - } - if status == constants::TRITET_ERROR_STRING_CONCAT { - return Err("INTERNAL ERROR: cannot write string with commands for Triangle"); - } - return Err("INTERNAL ERROR: some error occurred"); - } + handle_status(status)?; } Ok(()) } @@ -725,7 +648,7 @@ impl Trigen { /// This function will return 0 if `index` or `m` is out of range. pub fn out_cell_point(&self, index: usize, m: usize) -> usize { unsafe { - let corner = constants::TRITET_TO_TRIANGLE[m]; + let corner = TRITET_TO_TRIANGLE[m]; tri_out_cell_point(self.ext_trigen, to_i32(index), to_i32(corner)) as usize } } @@ -858,7 +781,7 @@ impl Trigen { let mut max = vec![f64::MIN; 2]; let mut colors: HashMap = HashMap::new(); let mut index_color = 0; - let clr = constants::LIGHT_COLORS; + let clr = LIGHT_COLORS; for tri in 0..n_triangle { let attribute = self.out_cell_attribute(tri); let color = match colors.get(&attribute) { From 4b9b8b562b4f2b16c79451c1a365ef8c9d543399 Mon Sep 17 00:00:00 2001 From: Dorival Pedroso Date: Mon, 30 Dec 2024 11:04:07 +1000 Subject: [PATCH 6/6] Remove test and cov on push --- .github/workflows/test_and_coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_and_coverage.yml b/.github/workflows/test_and_coverage.yml index ba4c0fa..4eaa899 100644 --- a/.github/workflows/test_and_coverage.yml +++ b/.github/workflows/test_and_coverage.yml @@ -1,5 +1,5 @@ name: Test & Coverage -on: [pull_request, push] +on: [pull_request] jobs: test_and_coverage: runs-on: ubuntu-latest