Duplicate check
pyvoro2.duplicates
Duplicate / near-duplicate point detection.
Voro++ contains an internal "duplicate" safeguard that can terminate the
process (via exit(1)) if it detects two points closer than an absolute
threshold (~1e-5 in container distance units).
This module provides a fast Python-side pre-check to detect such cases before calling into the C++ library.
The check is intentionally simple
- spatial hashing on an integer grid with cell size == threshold
- compare each point only to points in its own grid cell and neighboring 26 cells
Expected complexity is O(n) for typical inputs.
DuplicateError
Bases: ValueError
Raised when near-duplicate points are detected.
duplicate_check(points, *, threshold=1e-05, domain=None, wrap=True, mode='raise', max_pairs=10)
Detect point pairs closer than an absolute threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
Any
|
Array-like of shape (n, 3). |
required |
threshold
|
float
|
Absolute distance threshold. The default (1e-5) matches the effective Voro++ duplicate check (distance < 1e-5). |
1e-05
|
domain
|
Domain | None
|
Optional domain. If provided and |
None
|
wrap
|
bool
|
Whether to remap points into the primary domain when |
True
|
mode
|
Literal['raise', 'warn', 'return']
|
Behavior when duplicates are found:
- 'raise' (default): raise :class: |
'raise'
|
max_pairs
|
int
|
Maximum number of pairs to include in the report. |
10
|
Returns:
| Type | Description |
|---|---|
tuple[DuplicatePair, ...]
|
Tuple of DuplicatePair records (possibly empty). |
:::