Skip to content

Commit

Permalink
Add a function to add extra_attributes to vertices that have some alr…
Browse files Browse the repository at this point in the history
…eady
  • Loading branch information
hugoledoux committed Apr 23, 2024
1 parent 0c50dac commit b7382f3
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,21 +818,46 @@ impl Triangulation {
pub fn set_vertex_attributes(&mut self, vi: usize, a: Value) -> Result<bool, StartinError> {
match self.is_vertex_removed(vi) {
Err(why) => Err(why),

Ok(_b) => match &mut self.attributes {
Some(x) => {
*x.get_mut(vi).unwrap() = a;
return Ok(true);
}
None => {
*self.attributes.as_mut().unwrap().get_mut(vi).unwrap() = a;
return Ok(true);
return Err(StartinError::TinHasNoAttributes);
}
},
}
}

/// Returns a [`Vec`]<[`Vec`]<[`f64`]>> of all the vertices
pub fn add_vertex_attribute(&mut self, vi: usize, mut a: Value) -> Result<bool, StartinError> {
match self.is_vertex_removed(vi) {
Err(why) => Err(why),
Ok(_b) => match &mut self.attributes {
Some(x) => {
let v = x.get_mut(vi).unwrap();
if v.is_object() == false && v.is_null() == false {
return Ok(false);
}
if v.is_null() {
*v = json!({});
}
let vo = v.as_object_mut().unwrap();
if a.is_object() == false {
return Ok(false);
}
let ao = a.as_object_mut().unwrap();
vo.append(ao);
Ok(true)
}
None => {
return Err(StartinError::TinHasNoAttributes);
}
},
}
}

/// Returns a [`Vec`]<[`Vec`]<[`Value`]>> of all the vertex attributes
/// (including the infinite one and the removed ones)
pub fn all_attributes(&self) -> Option<Vec<Value>> {
self.attributes.clone()
Expand Down

0 comments on commit b7382f3

Please sign in to comment.