def test_ray_box_intersection_shape_pairwise(self):
     r = 10000
     box_center = tf.random.uniform([r, 3],
                                    minval=-1000.0,
                                    maxval=1000.0,
                                    dtype=tf.float32)
     box_size = tf.random.uniform([r, 3],
                                  minval=1.0,
                                  maxval=100.0,
                                  dtype=tf.float32)
     box_rotation_matrix = tf.tile(
         tf.expand_dims(tf.constant([[1, 0, 0], [0, 1, 0], [0, 0, 1]],
                                    dtype=tf.float32),
                        axis=0), [r, 1, 1])
     rays_start_point = tf.random.uniform([r, 3],
                                          minval=-1000.0,
                                          maxval=1000.0,
                                          dtype=tf.float32)
     rays_end_point = tf.random.uniform([r, 3],
                                        minval=-1000.0,
                                        maxval=1000.0,
                                        dtype=tf.float32)
     intersection_points, intersection_indices = box_utils.ray_box_intersection(
         box_center=box_center,
         box_rotation_matrix=box_rotation_matrix,
         box_length=box_size[:, 0],
         box_height=box_size[:, 1],
         box_width=box_size[:, 2],
         rays_start_point=rays_start_point,
         rays_end_point=rays_end_point)
     num_intersecting_rays = intersection_points.shape[0]
     self.assertAllEqual(intersection_points.shape,
                         np.array([num_intersecting_rays, 2, 3]))
     self.assertAllEqual(intersection_indices.shape,
                         np.array([num_intersecting_rays]))
 def test_ray_box_intersection(self):
     rays_start_point = tf.constant([[-1, 0, 0], [0, 0, 0], [-5, 0, 0]],
                                    dtype=tf.float32)
     rays_end_point = tf.constant([[1, 0, 0], [0, 1, 0], [-5, 1, 0]],
                                  dtype=tf.float32)
     box_center = tf.constant([0, 0, 0], dtype=tf.float32)
     box_rotation_matrix = tf.constant([[1, 0, 0], [0, 1, 0], [0, 0, 1]],
                                       dtype=tf.float32)
     box_size = tf.constant([2.0, 4.0, 6.0], dtype=tf.float32)
     intersection_points, intersection_indices = box_utils.ray_box_intersection(
         box_center=box_center,
         box_rotation_matrix=box_rotation_matrix,
         box_length=box_size[0],
         box_width=box_size[1],
         box_height=box_size[2],
         rays_start_point=rays_start_point,
         rays_end_point=rays_end_point)
     self.assertAllClose(
         intersection_points.numpy(),
         np.array([[[-1, 0, 0], [1, 0, 0]], [[0, -2, 0], [0, 2, 0]]]))
     self.assertAllEqual(intersection_indices.numpy(), np.array([0, 1]))