Ejemplo n.º 1
0
 def test_find_in_radius_if_spans_multiple_cells_on_different_levels(self):
     in_range = (
         (0.45, 0.45),
         (0.55, 0.55),
         (0.45, 0.55),
         (0.55, 0.45),
         (0.45, 0.65),
     )
     tree = {
         (0, 0): {
             (0, 0): [(0.45, 0.45), (0.1, 0.1)],
             (0, 1): {
                 (1, 2): [(0.45, 0.55), (0.26, 0.55), (0.45, 0.65)],
                 (0, 2): [(0.1, 0.55)],
             },
             (1, 0): [(0.55, 0.45), (0.9, 0.2)],
             (1, 1): [(0.55, 0.55)]
         }
     }
     list_tree = [
         tree,
         (lvl1 := tree[(0, 0)]),
         lvl1[(0, 1)],
     ]
     assert list_tree == GTreeList.gtree_to_list(tree)
     search_point = (0.5, 0.5)
     found = find_in_radius(list_tree,
                            search_point=search_point,
                            radius=0.2)
     assert set(found) == set(in_range)
Ejemplo n.º 2
0
 def test_find_if_radius_spans_multiple_cells_on_non_contigous_lvls(self):
     in_range = (
         (0.45, 0.45),
         (0.55, 0.55),
         (0.45, 0.55),
         (0.55, 0.45),
         (0.45, 0.65),
     )
     tree = {
         (0, 0): {
             (0, 0): [(0.45, 0.45), (0.1, 0.1)],
             (0, 1): {
                 (1, 2): {
                     (3, 4): [(0.45, 0.55)],
                     (2, 4): [(0.26, 0.55)],
                     (3, 5): [(0.45, 0.65)],
                 },
                 (0, 2): [(0.1, 0.55)],
             },
             (1, 0): [(0.55, 0.45), (0.9, 0.2)],
             (1, 1): [(0.55, 0.55)]
         }
     }
     list_tree = [
         tree,
         (lvl1 := tree[(0, 0)]),
         (lvl2 := lvl1[(0, 1)]),
         lvl2[(1, 2)],
     ]
     assert list_tree == GTreeList.gtree_to_list(tree)
     search_point = (0.49, 0.51)
     found = find_in_radius(list_tree,
                            search_point=search_point,
                            radius=0.2)
     assert set(found) == set(in_range)
Ejemplo n.º 3
0
    def test_points_so_close_they_result_in_many_element_list(self):
        lvl3 = {
            (6, ): [(0.8, )],
            (7, ): [(0.9, ), (0.95, )],
        }
        lvl2_0 = {
            (0, ): [(0.2, )],
            (1, ): [(0.3, ), (0.4, )],
        }
        lvl2_1 = {
            (2, ): [(0.6, )],
            (3, ): lvl3,
        }
        lvl1 = {
            (0, ): lvl2_0,
            (1, ): lvl2_1,
        }
        expected = [
            {
                (0, ): lvl1
            },
            lvl1,
            lvl2_0 | lvl2_1,
            lvl3,
        ]

        inputs = [(0.2, ), (0.3, ), (0.4, ), (0.6, ), (0.8, ), (0.9, ),
                  (0.95, )]
        actual = GTreeList(max_leaf_size=2)(inputs)
        assert actual == expected
Ejemplo n.º 4
0
 def test_deeper_find_volume_is_entirely_in_an_existing_cell(self):
     in_range = ((0.3, 0.3), (0.25, 0.3), (0.3, 0.25))
     tree = {(0, 0): {(0, 0): list(in_range), (1, 1): [(0.5, 0.5)]}}
     list_tree = [
         tree,
         tree[(0, 0)],
     ]
     assert list_tree == GTreeList.gtree_to_list(tree)
     search_point = (0.225, 0.225)
     found = find_in_radius(list_tree,
                            search_point=search_point,
                            radius=0.2)
     assert found == in_range
Ejemplo n.º 5
0
 def test_find_in_radius_if_spans_multiple_cells_on_the_same_level(self):
     in_range = ((0.45, 0.45), (0.55, 0.55), (0.45, 0.55), (0.55, 0.45))
     tree = {
         (0, 0): {
             (0, 0): [(0.45, 0.45), (0.1, 0.1)],
             (0, 1): [(0.45, 0.55)],
             (1, 0): [(0.55, 0.45), (0.9, 0.2)],
             (1, 1): [(0.55, 0.55)]
         }
     }
     list_tree = [tree, tree[(0, 0)]]
     assert list_tree == GTreeList.gtree_to_list(tree)
     search_point = (0.5, 0.5)
     found = find_in_radius(list_tree,
                            search_point=search_point,
                            radius=0.2)
     assert set(found) == set(in_range)
Ejemplo n.º 6
0
 def test_find_in_radius_for_non_contigous_levels_and_zones(self):
     # |------v---------S||----|-v|v-|--x-|-x--|
     # x not in range
     # v in range
     # S search point
     tree = {
         (0, ): {
             (0, ): [(0.3, )],
             (1, ): {
                 (2, ): {
                     (5, ): {
                         (10, ): [(0.67, )],
                         (11, ): [(0.72, )],
                     },
                 },
                 (3, ): {
                     (6, ): [(0.8, )],
                     (7, ): [(0.9, )],
                 },
             },
         },
     }
     list_tree = [
         tree,
         (lvl1 := tree[(0, )]),
         (lvl2 := lvl1[(1, )]),
         (lvl3a := lvl2[(2, )]) | lvl2[(3, )],
         lvl3a[(5, )],
     ]
     assert list_tree == GTreeList.gtree_to_list(tree)
     search_point = (0.49, )
     expected_in_range = ((0.3, ), (0.67, ), (0.72, ))
     found = find_in_radius(list_tree,
                            search_point=search_point,
                            radius=0.3)
     assert found == expected_in_range
Ejemplo n.º 7
0
 def test_1_element_set_results_in_1_element_list(self):
     assert GTreeList(max_leaf_size=1)([(1, )]) == [{(0, ): [(1, )]}]
Ejemplo n.º 8
0
 def test_empty_set_results_in_empty_list(self):
     assert GTreeList(max_leaf_size=1234)([]) == []
Ejemplo n.º 9
0
 def test_3_points_result_in_2_element_list(self):
     lvl1 = {(0, ): [(0.4, )], (1, ): [(0.9, ), (1, )]}
     expected = [{(0, ): lvl1}, lvl1]
     actual = GTreeList(max_leaf_size=2)([(0.4, ), (0.9, ), (1, )])
     assert actual == expected
Ejemplo n.º 10
0
 def test_2_close_points_with_leaf_size_2_result_in_1_element_list(self):
     actual = GTreeList(max_leaf_size=2)([(0.9, ), (1, )])
     assert actual == [{(0, ): [(0.9, ), (1, )]}]