-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
from __future__ import annotations | ||
|
||
import itertools | ||
from typing import Optional, cast | ||
|
||
import numpy as np | ||
import pytest | ||
import rerun as rr | ||
from rerun.components import ( | ||
Color, | ||
ColorBatch, | ||
LatLonBatch, | ||
) | ||
from rerun.datatypes import ( | ||
Rgba32ArrayLike, | ||
Float32ArrayLike, | ||
DVec2DArrayLike, | ||
) | ||
|
||
from .common_arrays import ( | ||
colors_arrays, | ||
colors_expected, | ||
dvec2ds_arrays as positions_arrays, | ||
dvec2ds_expected as positions_expected, | ||
radii_arrays, | ||
radii_expected, | ||
) | ||
|
||
|
||
def test_geopoints() -> None: | ||
all_arrays = itertools.zip_longest( | ||
positions_arrays, | ||
radii_arrays, | ||
colors_arrays, | ||
) | ||
|
||
for positions, radii, colors in all_arrays: | ||
positions = positions if positions is not None else positions_arrays[-1] | ||
|
||
# make Pyright happy as it's apparently not able to track typing info through zip_longest | ||
positions = cast(DVec2DArrayLike, positions) | ||
radii = cast(Optional[Float32ArrayLike], radii) | ||
colors = cast(Optional[Rgba32ArrayLike], colors) | ||
|
||
print(f"rr.GeoPoints(\n {positions}\n radii={radii!r}\n colors={colors!r}\n)") | ||
arch = rr.GeoPoints( | ||
positions, | ||
radii=radii, | ||
colors=colors, | ||
) | ||
print(f"{arch}\n") | ||
|
||
assert arch.positions == positions_expected(positions, LatLonBatch) | ||
assert arch.radii == radii_expected(radii) | ||
assert arch.colors == colors_expected(colors) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"data", | ||
[ | ||
[0, 128, 0, 255], | ||
[0, 128, 0], | ||
np.array((0, 128, 0, 255)), | ||
[0.0, 0.5, 0.0, 1.0], | ||
np.array((0.0, 0.5, 0.0, 1.0)), | ||
], | ||
) | ||
def test_geopoint_single_color(data: Rgba32ArrayLike) -> None: | ||
pts = rr.GeoPoints(np.zeros((5, 2)), colors=data) | ||
|
||
assert pts.colors == ColorBatch(Color([0, 128, 0, 255])) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"data", | ||
[ | ||
[[0, 128, 0, 255], [128, 0, 0, 255]], | ||
[[0, 128, 0], [128, 0, 0]], | ||
np.array([[0, 128, 0, 255], [128, 0, 0, 255]]), | ||
np.array([0, 128, 0, 255, 128, 0, 0, 255], dtype=np.uint8), | ||
np.array([8388863, 2147483903], dtype=np.uint32), | ||
np.array([[0, 128, 0], [128, 0, 0]]), | ||
[[0.0, 0.5, 0.0, 1.0], [0.5, 0.0, 0.0, 1.0]], | ||
[[0.0, 0.5, 0.0], [0.5, 0.0, 0.0]], | ||
np.array([[0.0, 0.5, 0.0, 1.0], [0.5, 0.0, 0.0, 1.0]]), | ||
np.array([[0.0, 0.5, 0.0], [0.5, 0.0, 0.0]]), | ||
np.array([0.0, 0.5, 0.0, 1.0, 0.5, 0.0, 0.0, 1.0]), | ||
# Note: Sequence[int] is interpreted as a single color when they are 3 or 4 long. For other lengths, they | ||
# are interpreted as list of packed uint32 colors. Note that this means one cannot pass an len=N*4 flat list of | ||
# color components. | ||
[8388863, 2147483903], | ||
], | ||
) | ||
def test_point2d_multiple_colors(data: Rgba32ArrayLike) -> None: | ||
pts = rr.GeoPoints(np.zeros((5, 2)), colors=data) | ||
|
||
assert pts.colors == ColorBatch([ | ||
Color([0, 128, 0, 255]), | ||
Color([128, 0, 0, 255]), | ||
]) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_geopoints() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters