import numpy as np import pytest from k1link.height_slice import height_mask from k1link.missions.live_scene import clip_reference, clip_query def test_both_sides_are_inclusive_reversible_and_do_not_mutate_source(): points = np.array([[1., 0, -2], [2., 0, 0], [3., 0, 2], [4., 0, 6]]) original = points.copy() np.testing.assert_equal(clip_reference(points, 2, 0), points[1:3]) np.testing.assert_equal(clip_reference(points, None, 2), points[2:]) np.testing.assert_equal(clip_reference(points, 0), points[:2]) np.testing.assert_equal(clip_reference(points, None), original) np.testing.assert_equal(points, original) def test_query_slices_in_calibrated_world_height_without_changing_local_coordinates(): points = np.array([[0., 0, -5], [0., 0, -3], [0., 0, 1]]) matrix = np.eye(4); matrix[2, 3] = 5 np.testing.assert_equal(clip_query(points, matrix, 3, 1), points[1:2]) np.testing.assert_equal(clip_query(points, matrix, None), points) def test_invalid_bounds_rejected_and_empty_band_and_cloud_are_supported(): points = np.array([[0., 0, 0], [0., 0, 2], [0., 0, np.nan]]) np.testing.assert_equal(height_mask(points, 2, 2), [False, True, False]) assert not height_mask(points, 3, 4).any() assert len(height_mask(np.empty((0, 3)), 0, 3)) == 0 for low, high in [(4, 3), (float('inf'), None), (None, float('nan'))]: with pytest.raises(ValueError): height_mask(points, low, high)