Skip to content

CDT: Multiple constraint edge insertion (outer + holes) #91

Description

@mkofler96

Context

Part of the CDT implementation. Depends on Issues #1#5. A polygon with holes has multiple boundary rings. All edges from all rings must be inserted as constraints. Order: outer boundary first, then holes. Within each ring, edges can be processed in any order without affecting correctness.

Problem

Implement the loop that iterates over all n edges of each boundary ring and calls insert_constraint for each. Inserting a constraint that already exists must be a no-op (idempotent).

Acceptance Criteria

  • A polygon with outer boundary and one rectangular hole produces a triangulation where all 4 outer edges AND all 4 hole edges are present as triangle edges.
  • Inserting the same constraint twice is a no-op (no panic, no duplicate triangles).
  • All boundary ring edges present after full insertion pass.

Red-Green Tests

#[test]
fn all_outer_edges_present_after_insertion() {
    let outer = vec![
        Point2::new(0.0, 0.0), Point2::new(3.0, 0.0),
        Point2::new(3.0, 3.0), Point2::new(0.0, 3.0),
    ];
    let mesh = triangulate_constrained(&outer, &[]);
    // All 4 boundary edges must appear
    assert!(has_edge(&mesh.triangles, 0, 1));
    assert!(has_edge(&mesh.triangles, 1, 2));
    assert!(has_edge(&mesh.triangles, 2, 3));
    assert!(has_edge(&mesh.triangles, 3, 0));
}

#[test]
fn hole_edges_present_after_insertion() {
    let outer = vec![
        Point2::new(0.0, 0.0), Point2::new(4.0, 0.0),
        Point2::new(4.0, 4.0), Point2::new(0.0, 4.0),
    ];
    let hole = vec![
        Point2::new(1.0, 1.0), Point2::new(3.0, 1.0),
        Point2::new(3.0, 3.0), Point2::new(1.0, 3.0),
    ];
    let mesh = triangulate_constrained(&outer, &[hole.as_slice()]);
    // Hole vertices are indices 4-7 in the combined point array
    // All 4 hole edges must be present
    let n = outer.len(); // 4
    assert!(has_edge(&mesh.triangles, n,   n+1));
    assert!(has_edge(&mesh.triangles, n+1, n+2));
    assert!(has_edge(&mesh.triangles, n+2, n+3));
    assert!(has_edge(&mesh.triangles, n+3, n));
}

#[test]
fn duplicate_constraint_is_noop() {
    let outer = vec![
        Point2::new(0.0, 0.0), Point2::new(2.0, 0.0),
        Point2::new(1.0, 2.0),
    ];
    // triangulate_constrained inserts each edge once; calling it again on
    // the same polygon must produce the same result.
    let mesh1 = triangulate_constrained(&outer, &[]);
    let mesh2 = triangulate_constrained(&outer, &[]);
    assert_eq!(mesh1.triangles.len(), mesh2.triangles.len());
}

Location

crates/kofem-mesh/src/cdt.rs — constraint insertion loop in triangulate_constrained

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions