Skip to main content

geop_core_topology/argument_validation/
same_loop.rs

1use crate::{CoedgeId, Model};
2use geop_core_math::{
3    geop_error::{GeopError, GeopResult},
4    scalars::Scalar,
5};
6
7/// Validates that `coedge2` lies on the loop traced by following `next` from
8/// `coedge1` (i.e. they bound the same face boundary loop).
9pub fn validate_same_loop<S: Scalar>(
10    model: &Model<S>,
11    coedge1: CoedgeId,
12    coedge2: CoedgeId,
13) -> GeopResult<()> {
14    let mut cursor = coedge1;
15    loop {
16        if cursor == coedge2 {
17            return Ok(());
18        }
19        cursor = model.get_coedge(cursor)?.next;
20        if cursor == coedge1 {
21            break;
22        }
23    }
24    Err(GeopError::new(
25        "coedge1 and coedge2 must belong to the same loop",
26    ))
27}