diff --git a/fj-kernel/src/shape/api.rs b/fj-kernel/src/shape/api.rs index 07b0175b7..89d2edb9a 100644 --- a/fj-kernel/src/shape/api.rs +++ b/fj-kernel/src/shape/api.rs @@ -92,6 +92,21 @@ impl Shape { .find(|obj| &obj.get() == object) } + /// Get handle of an identical object, if it exists, or add the object + /// + /// In any case, returns a handle that refers to an object that is identical + /// to the provided object. + pub fn get_handle_or_insert(&mut self, object: T) -> ValidationResult + where + T: Object, + { + if let Some(handle) = self.get_handle(&object) { + return Ok(handle); + } + + self.insert(object) + } + /// Access the shape's geometry pub fn geometry(&mut self) -> Geometry { Geometry {