Esempio n. 1
0
 def setUp(self):
     self.qn = _QuadNode(
         [_Node(99, 3, 7, 2, 0, "red"),
          _Node(100, 2, 9, 3, 0, "blue")], 5, 50)
     cells = {}
     self.x, self.y = (3, 3)
     self.num_x, self.num_y = 5, 5
     self.min_x, self.min_y = 0, 0
     self.max_size = 1.5
Esempio n. 2
0
    def test_is_overlapping_any_node_and_index(self):
        to_check = _Node(0, 2, 2, 1, -1, "blue")
        others = [
            _Node(1, 5, 5, 1, -1, "blue"),
            _Node(2, 6, 6, 1, -1, "blue"),
            _Node(3, 7, 7, 1, -1, "blue"),
        ]
        ov_idx, idx = 0, len(others)
        ov_idx, overlapping_node = is_overlapping_any_node_and_index(
            to_check, to_check.x, to_check.y, others, ov_idx, idx)
        self.assertEqual(2, ov_idx)

        ov_idx, overlapping_node = is_overlapping_any_node_and_index(
            to_check, to_check.x, to_check.y, others, 2, 3)
        self.assertEqual(2, ov_idx)
Esempio n. 3
0
    def test_overlap_check_list(self):

        to_check = _Node(0, 2, 2, 1, -1, "blue")
        others = [
            _Node(1, 5, 5, 1, -1, "blue"),
            _Node(2, 6, 6, 1, -1, "blue"),
            _Node(3, 7, 7, 1, -1, "blue"),
        ]
        overlapping_node = self.qn.is_overlapping_any_node(
            to_check, to_check.x, to_check.y, others)
        self.assertIsNone(overlapping_node)
        others += [_Node(4, 3, 3, 1, -1, "red")]
        overlapping_node = self.qn.is_overlapping_any_node(
            to_check, to_check.x, to_check.y, others)
        self.assertIsNotNone(overlapping_node)
        self.assertEqual(overlapping_node.node_id, 4)
Esempio n. 4
0
 def test_get_cell_stats(self):
     g = _GridBuckets(10)
     n0 = _Node(0, 1, 1, 10, 1, "blue")
     n1 = _Node(1, 2, 1, 10, 1, "blue")
     n2 = _Node(2, 40, -20, 10, 1, "blue")
     n3 = _Node(3, -33, -33, 1, 1, "blue")
     n4 = _Node(4, -193, 78, 1, 1, "blue")
     g.add_node(n0)
     g.add_node(n1)
     g.add_node(n2)
     g.add_node(n3)
     g.add_node(n4)
     stats = g.get_grid_cell_stats()
     self.assertEqual(3, len(stats), "Correct size list")
     self.assertEqual(254, stats[0][1], "empty cells")
     self.assertEqual(6, stats[1][1], "one item in cell")
     self.assertEqual(4, stats[2][1], "two items in cell")
Esempio n. 5
0
    def test_add_node(self):
        g = _GridBuckets(10)
        n0 = _Node(0, 1, 1, 10, 1, "blue")
        n1 = _Node(1, 2, 1, 10, 1, "blue")
        n2 = _Node(2, 40, -20, 10, 1, "blue")

        g.add_node(n0)
        nodes = g.get_potential_overlapping_nodes_by_node(n0)
        self.assertSetEqual(nodes, {n0})

        g.add_node(n1)
        nodes = g.get_potential_overlapping_nodes_by_node(n1)
        self.assertSetEqual(nodes, {n0, n1})

        g.add_node(n2)
        nodes = g.get_potential_overlapping_nodes_by_node(n1)
        self.assertSetEqual(nodes, {n0, n1})
Esempio n. 6
0
 def setUp(self):
     self.qn = _QuadNode(
         [_Node(99, 3, 7, 2, 0, "red"),
          _Node(100, 2, 9, 3, 0, "blue")], 5, 50)
Esempio n. 7
0
    def test_get_nodes_just_outside_box(self):
        others = [
            _Node(0, 6, 4.9, 1, 7, "blue"),
            _Node(1, 4, 4, 1, -1, "blue"),
            _Node(2, 4, 7.1, 1, -1, "blue"),
            _Node(3, 11, 7.1, 1, -1, "blue"),
            _Node(4, 7.1, 11, 1, -1, "blue"),
            _Node(5, 6, 6, 1, -1, "blue"),
            _Node(6, 9, 9, 1, -1, "blue"),
            _Node(7, 2.5, 7.1, 1, -1, "blue"),
            _Node(8, 7.1, 15, 1, -1, "blue"),
            _Node(9, 7.1, -3, 1, -1, "blue"),
        ]
        local_quad = _QuadNode(
            [_Node(99, 5, 5, 1, 0, "red"),
             _Node(100, 10, 10, 1, 0, "blue")], 5, 50)
        just_outside = local_quad.get_nodes_near_lines(others)

        self.assertEqual(5, len(just_outside))