shape/case_enum/
deduplicate_shape.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::Shape;

/// Given a vec of shapes, this inserts a new shape into the list _only if_ there is no shape
/// with the same case. If there _is_ a shape with the same case, it instead adds the location
/// of the new shape to the existing one.
pub(super) fn extend_or_insert_shape(new_shapes: &mut Vec<Shape>, shape: Shape) {
    if let Some(existing_case) = new_shapes
        .iter_mut()
        .find(|existing| existing.case() == shape.case())
    {
        existing_case
            .locations
            .extend(shape.locations.iter().cloned());
    } else {
        new_shapes.push(shape);
    }
}