diff --git a/examples/attributes.rs b/examples/attributes.rs index 51a8ab5..766b0f0 100644 --- a/examples/attributes.rs +++ b/examples/attributes.rs @@ -14,9 +14,12 @@ struct MyAttribute { fn main() { let mut dt = startin::Triangulation::new(); dt.set_duplicates_handling(startin::DuplicateHandling::Highest); - let _ = dt.add_attribute_map("intensity".to_string(), "f64".to_string()); - let _ = dt.add_attribute_map("classification".to_string(), "u64".to_string()); - let _ = dt.add_attribute_map("visited".to_string(), "bool".to_string()); + let att_schema: Vec<(String, String)> = vec![ + ("intensity".to_string(), "f64".to_string()), + ("classification".to_string(), "u64".to_string()), + ("visited".to_string(), "bool".to_string()), + ]; + let _ = dt.set_attributes_schema(att_schema); let a = MyAttribute { intensity: 44.0, @@ -36,7 +39,7 @@ fn main() { let _ = dt.add_vertex_attributes(vi.unwrap(), json!({"classification": 1, "visited": true})); println!("{}", dt); - println!("{:?}\n", dt.list_all_attributes()); + println!("{:?}\n", dt.all_attributes()); println!("{:?}", dt.all_attributes()); println!("{:?}", dt.get_vertex_attributes(4)); diff --git a/examples/example2.rs b/examples/example2.rs index 0144a95..854b024 100644 --- a/examples/example2.rs +++ b/examples/example2.rs @@ -28,7 +28,7 @@ fn main() { let re = dt.insert_one_pt(22.2, 33.3, 4.4); match re { Ok(_v) => println!("Inserted new point"), - Err(v) => println!("Duplicate of vertex #{}, not inserted", v), + Err((v, _b)) => println!("Duplicate of vertex #{}, not inserted", v), } //-- remove it let re = dt.remove(6); diff --git a/examples/readme_snippet.rs b/examples/readme_snippet.rs index 580e96d..6210a86 100644 --- a/examples/readme_snippet.rs +++ b/examples/readme_snippet.rs @@ -24,7 +24,7 @@ fn main() { "Inserted new point, now the DT has {} vertices", dt.number_of_vertices() ), - Err(v) => println!("Duplicate of vertex #{}, not inserted", v), + Err((v, _b)) => println!("Duplicate of vertex #{}, not inserted", v), } //-- remove it match dt.remove(6) { diff --git a/src/lib.rs b/src/lib.rs index 619704b..669e285 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,7 @@ //! "Inserted new point, now the DT has {} vertices", //! dt.number_of_vertices() //! ), -//! Err(v) => println!("Duplicate of vertex #{}, not inserted", v), +//! Err((v, _b)) => println!("Duplicate of vertex #{}, not inserted", v), //! } //! //-- remove it //! match dt.remove(6) { @@ -540,8 +540,9 @@ impl Triangulation { /// Insert the point (`px`, `py`, `pz`) in the triangulation. /// Returns the vertex ID of the point if the vertex didn't exist. - /// If there was a vertex at that location, an Error is thrown with the already - /// existing vertex ID. + /// If there was a vertex at that location, an Error is thrown with a tuple + /// indicating 1) the vertex ID of the existing vertex; 2) true/false whether the + /// z-value and attributes were updated. pub fn insert_one_pt(&mut self, px: f64, py: f64, pz: f64) -> Result { if !self.is_init { return self.insert_one_pt_init_phase(px, py, pz); diff --git a/tests/duplicates.rs b/tests/duplicates.rs index 0725626..51e64f5 100755 --- a/tests/duplicates.rs +++ b/tests/duplicates.rs @@ -20,33 +20,33 @@ fn duplicate_alltests() { dt.set_duplicates_handling(startin::DuplicateHandling::First); let re = dt.insert_one_pt(5.0, 5.0, 20.0); - assert_eq!(Err(5), re); + assert_eq!(Err((5, false)), re); match re { Ok(_) => (), - Err(i) => assert_eq!(dt.get_point(i).unwrap()[2], 10.0), + Err((i, _b)) => assert_eq!(dt.get_point(i).unwrap()[2], 10.0), } dt.set_duplicates_handling(startin::DuplicateHandling::Last); let re = dt.insert_one_pt(5.0, 5.0, 20.0); - assert_eq!(Err(5), re); + assert_eq!(Err((5, true)), re); match re { Ok(_) => (), - Err(i) => assert_eq!(dt.get_point(i).unwrap()[2], 20.0), + Err((i, _b)) => assert_eq!(dt.get_point(i).unwrap()[2], 20.0), } dt.set_duplicates_handling(startin::DuplicateHandling::Highest); - let re = dt.insert_one_pt(5.0, 5.0, 20.0); - assert_eq!(Err(5), re); + let re = dt.insert_one_pt(5.0, 5.0, 21.0); + assert_eq!(Err((5, true)), re); match re { Ok(_) => (), - Err(i) => assert_eq!(dt.get_point(i).unwrap()[2], 20.0), + Err((i, _b)) => assert_eq!(dt.get_point(i).unwrap()[2], 21.0), } dt.set_duplicates_handling(startin::DuplicateHandling::Lowest); let re = dt.insert_one_pt(5.0, 5.0, 5.0); - assert_eq!(Err(5), re); + assert_eq!(Err((5, true)), re); match re { Ok(_) => (), - Err(i) => assert_eq!(dt.get_point(i).unwrap()[2], 5.0), + Err((i, _b)) => assert_eq!(dt.get_point(i).unwrap()[2], 5.0), } } diff --git a/tests/init_construction.rs b/tests/init_construction.rs index f1983c8..7aa22a0 100755 --- a/tests/init_construction.rs +++ b/tests/init_construction.rs @@ -43,7 +43,7 @@ fn duplicates() { let _re = dt.insert_one_pt(2.2, 2.3, 4.5); let re2 = dt.insert_one_pt(2.2, 2.3, 4.5); assert!(re2.is_err()); - assert_eq!(2, re2.unwrap_err()); + assert_eq!((2, false), re2.unwrap_err()); assert_eq!(2, dt.number_of_vertices()); assert_eq!(0, dt.number_of_triangles()); }