Skip to content

Fix: Core logic improvements and bug fixes#6

Open
JorenB wants to merge 1 commit intomainfrom
bugfix/core-logic-improvements
Open

Fix: Core logic improvements and bug fixes#6
JorenB wants to merge 1 commit intomainfrom
bugfix/core-logic-improvements

Conversation

@JorenB
Copy link
Owner

@JorenB JorenB commented May 26, 2025

This commit addresses several potential issues and improves the robustness of the CDT simulation code.

Key changes include:

  1. RNG Seeding: Standardized random number generator seeding for Universe::rng, ensuring it's seeded from main like Simulation::rng. Addresses a TODO comment.

  2. verticesFour Management:

    • insertVertex: Correctly updates the verticesFour bag for the newly inserted vertex and its relevant neighbors by evaluating isFourVertex.
    • removeVertex: Ensures verticesFour is updated for neighbors affected by a vertex removal.
    • flipLink: Systematically updates verticesFour for all four vertices involved in an edge flip using isFourVertex. The setVertices calls within flipLink were also updated to reflect a standard robust edge flip procedure.
  3. Universe::check() Enhancement: The verticesFour verification in Universe::check() now iterates over all active vertices in the simulation (using Vertex::items()) and asserts that their status (per isFourVertex) matches their presence in the verticesFour bag.

  4. Universe::vertices List: Universe::updateVertexData now populates Universe::vertices with all unique active vertices. This ensures that Universe::exportGeometry exports the complete geometry.

  5. Robust Geometry I/O:

    • Universe::importGeometry now returns a boolean status indicating success or failure instead of asserting on errors.
    • It handles file open errors, read errors, and count mismatches gracefully, printing informative messages.
    • main.cpp now checks this return status and proceeds accordingly, allowing for fallback to new universe creation if import fails.

The trianglesFlip logic within the move functions was largely preserved to limit the scope of this set of changes, though the corrected setVertices in flipLink should contribute to its correctness. Further investigation into trianglesFlip invariants might be beneficial in the future.

This commit addresses several potential issues and improves the robustness
of the CDT simulation code.

Key changes include:

1.  RNG Seeding: Standardized random number generator seeding for
    `Universe::rng`, ensuring it's seeded from main like `Simulation::rng`.
    Addresses a TODO comment.

2.  `verticesFour` Management:
    - `insertVertex`: Correctly updates the `verticesFour` bag for the newly
      inserted vertex and its relevant neighbors by evaluating `isFourVertex`.
    - `removeVertex`: Ensures `verticesFour` is updated for neighbors
      affected by a vertex removal.
    - `flipLink`: Systematically updates `verticesFour` for all four
      vertices involved in an edge flip using `isFourVertex`. The
      `setVertices` calls within `flipLink` were also updated to reflect a
      standard robust edge flip procedure.

3.  `Universe::check()` Enhancement: The `verticesFour` verification in
    `Universe::check()` now iterates over all active vertices in the
    simulation (using `Vertex::items()`) and asserts that their status
    (per `isFourVertex`) matches their presence in the `verticesFour` bag.

4.  `Universe::vertices` List: `Universe::updateVertexData` now populates
    `Universe::vertices` with all unique active vertices. This ensures
    that `Universe::exportGeometry` exports the complete geometry.

5.  Robust Geometry I/O:
    - `Universe::importGeometry` now returns a boolean status indicating
      success or failure instead of asserting on errors.
    - It handles file open errors, read errors, and count mismatches
      gracefully, printing informative messages.
    - `main.cpp` now checks this return status and proceeds accordingly,
      allowing for fallback to new universe creation if import fails.

The `trianglesFlip` logic within the move functions was largely preserved
to limit the scope of this set of changes, though the corrected
`setVertices` in `flipLink` should contribute to its correctness.
Further investigation into `trianglesFlip` invariants might be beneficial
in the future.
@JorenB JorenB self-assigned this May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant