diff --git a/src/lib.rs b/src/lib.rs index ca78ed8..5a5258e 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,7 +127,6 @@ pub enum StartinError { VertexUnknown, TinHasNoAttributes, WrongAttribute, - TriangulationAlreadyInitialised, } /// Possibilities for the insertion (with `insert()`) @@ -434,7 +433,6 @@ impl Triangulation { self.update_dt(j); } } - match &mut self.attributes { Some(x) => x.push(json!({})), _ => (), @@ -1463,6 +1461,18 @@ impl Triangulation { //-- flip31 to remove the vertex if adjs.len() == 3 { self.flip31(v); + if self.number_of_vertices() < 3 { + //-- going back to a line, no triangles + //-- wipe it all and start the insert_init_phase again + for i in 0..self.stars.len() { + self.stars[i].link.clear(); + } + self.stars[v].pt[0] = f64::NAN; + self.stars[v].pt[1] = f64::NAN; + self.stars[v].pt[2] = f64::NAN; + // self.removed_indices.push(v); + self.is_init = false; + } Ok(self.stars.len() - 1) } else { //-- convex part is filled, and we need to apply a special "flip" @@ -1498,7 +1508,6 @@ impl Triangulation { self.stars[v].pt[1] = f64::NAN; self.stars[v].pt[2] = f64::NAN; self.removed_indices.push(v); - for i in 0..1000 { if adjs[i] != 0 { self.cur = adjs[i]; diff --git a/tests/init_construction.rs b/tests/init_construction.rs index 7aa22a0..5d7c920 100755 --- a/tests/init_construction.rs +++ b/tests/init_construction.rs @@ -48,6 +48,24 @@ fn duplicates() { assert_eq!(0, dt.number_of_triangles()); } +#[test] +fn remove_and_invalid() { + let mut dt = startin::Triangulation::new(); + let _ = dt.insert_one_pt(1.5, 1.3, 4.5); + let _ = dt.insert_one_pt(2.2, 2.3, 4.5); + let _ = dt.insert_one_pt(3.2, 7.3, 4.5); + assert_eq!(3, dt.number_of_vertices()); + assert_eq!(1, dt.number_of_triangles()); + + let _ = dt.remove(2); + assert_eq!(2, dt.number_of_vertices()); + assert_eq!(0, dt.number_of_triangles()); + + let _ = dt.insert_one_pt(4.2, 17.3, 4.5); + assert_eq!(3, dt.number_of_vertices()); + assert_eq!(1, dt.number_of_triangles()); +} + #[test] fn grid() { let mut dt = startin::Triangulation::new();