Skip to content

Commit fd602e3

Browse files
committed
add helper function to round FloatCoordinate to Coordinate
1 parent 2863153 commit fd602e3

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

funlib/geometry/float_coordinate.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import numpy as np
55

6+
from .coordinate import Coordinate
7+
68

79
class FloatCoordinate(tuple):
810
"""A ``tuple`` of numbers or None.
@@ -47,6 +49,10 @@ def dims(self) -> int:
4749

4850
def squeeze(self, dim: int = 0) -> "FloatCoordinate":
4951
return FloatCoordinate(c for i, c in enumerate(self) if i != dim)
52+
53+
def round(self) -> Coordinate:
54+
"""Round to nearest integer and convert to Coordinate."""
55+
return Coordinate(int(round(a)) if a is not None else None for a in self)
5056

5157
def is_multiple_of(self, coordinate: "FloatCoordinate") -> bool:
5258
"""Test if this coordinate is a multiple of the given coordinate."""

0 commit comments

Comments
 (0)