Function collapse_edge

Source
pub fn collapse_edge<T: CoordsFloat>(
    t: &mut Transaction,
    map: &CMap2<T>,
    e: EdgeIdType,
) -> TransactionClosureResult<VertexIdType, EdgeCollapseError>
Expand description

Collapse an edge separating two triangles.

+-----+-----+       +-----+-----+
|    / \    |        \    |    /
|   /   \   |         \  2-3  /
1  2     3  4          1  |  4
| /       \ |           \ | /
|/         \|            \|/
+-----------+  -->        +
|\    e    /|            /|\
| \       / |           / | \
5  6     7  8          5  |  8
|   \   /   |         /  6-7  \
|    \ /    |        /    |    \
+-----+-----+       +-----+-----+

This function expects to operate on a triangular mesh. The edge may be collapsed to one of the existing vertices, or to the average of their value; this is determined by the anchoring of the mesh to its geometry. If no anchoring attributes are present, the edge is always collapsed to the average value.

§Arguments

  • t: &mut Transaction – Associated transaction.
  • map: &mut CMap2 – Edited map.
  • e: EdgeIdType – Edge to move.

§Return / Errors

Upon success, this function will return the ID of the new vertex formed after the collapse. Depending on the anchoring constraints, it may be placed on one of the two previously existing vertex, or to their average value.

This function will abort and raise an error if:

  • the transaction cannot be completed,
  • one internal sew operation fails,
  • the collapse cannot be completed; see [EdgeCollapseError] for more information.

The returned error can be used in conjunction with transaction control to avoid any modifications in case of failure at attribute level. The user can then choose to retry or abort as he wishes using Transaction::with_control_and_err.

Note that the function will return `StmError::Retry` if it attempts to read a missing vertex. If used within a transaction which retries indefinitely (e.g. `atomically_with_err`), it can lead to an infinite loop.

This will not happen unless the map ends up in an incorrect state where topological vertices have no associated coordinates.