コード例 #1
0
 def bounding_box(self):
     box_list = map(lambda vertex: BoundingBox(vertex, vertex),
                    self.vertices)
     box_base = BoundingBox.from_boxes(box_list).translate(self.origin)
     box_origin = box_base.origin
     box_corner = box_base.corner + Point(0, 0, self.height)
     return BoundingBox(box_origin, box_corner)
コード例 #2
0
 def test_normalize_on_creation(self):
     box = BoundingBox(Point(20, 30), Point(10, 40))
     self.assertEqual(box.origin, Point(10, 30))
     self.assertEqual(box.corner, Point(20, 40))
     other_box = BoundingBox(Point(25, 13), Point(82, 9))
     self.assertEqual(other_box.origin, Point(25, 9))
     self.assertEqual(other_box.corner, Point(82, 13))
コード例 #3
0
 def test_node_bounding_boxes(self):
     points_list = [Point(10, 20), Point(-15, 10), Point(40, -20)]
     road = Road.from_control_points(points_list)
     road.add_lane(10)
     road.add_lane(20)
     width = road.width()
     expected_box_list = [
         BoundingBox(Point(10 - width / 2, 20 - width / 2),
                     Point(10 + width / 2, 20 + width / 2)),
         BoundingBox(Point(-15 - width / 2, 10 - width / 2),
                     Point(-15 + width / 2, 10 + width / 2)),
         BoundingBox(Point(40 - width / 2, -20 - width / 2),
                     Point(40 + width / 2, -20 + width / 2))
     ]
     self.assertEqual(road._node_bounding_boxes(), expected_box_list)
コード例 #4
0
 def bounding_box(self):
     box_list = self._box_list_from_list(self.roads)
     box_list.extend(self._box_list_from_list(self.blocks))
     box_list.extend(self._box_list_from_list(self.buildings))
     if self.ground_plane is not None:
         box_list.append(self.ground_plane.bounding_box())
     return BoundingBox.from_boxes(box_list)
コード例 #5
0
 def test_bounding_box_with_lanes_with_positive_and_negative_offsets(self):
     road = Road.from_control_points(
         [Point(30, 25), Point(90, -30),
          Point(-25, 50)])
     road.add_lane(20)
     road.add_lane(-30)
     expected_box = BoundingBox(Point(-52, -57), Point(117, 77))
     self.assertEqual(road.bounding_box(), expected_box)
コード例 #6
0
 def test_from_boxes_with_five_boxes(self):
     box_1 = BoundingBox(Point(-20, -10), Point(-10, 10))
     box_2 = BoundingBox(Point(20, 5), Point(30, 15))
     box_3 = BoundingBox(Point(-15, 0), Point(10, 20))
     box_4 = BoundingBox(Point(55, 15), Point(45, 16))
     box_5 = BoundingBox(Point(-5, -10), Point(5, 0))
     box_list = [box_1, box_2, box_3, box_4, box_4]
     expected_merge = BoundingBox(Point(-20, -10), Point(55, 20))
     self.assertEqual(BoundingBox.from_boxes(box_list), expected_merge)
コード例 #7
0
 def test_bounding_box_with_one_point_block_not_centered_at_0_0(self):
     origin = Point(34, 68)
     block = Block.square(origin, 0)
     self.assertEqual(block.bounding_box(), BoundingBox(origin, origin + Point(0, 0, 0.15)))
コード例 #8
0
 def test_eq_on_different_objects(self):
     box_1 = BoundingBox(Point(10, 20), Point(30, 40))
     box_2 = BoundingBox(Point(55, 15), Point(45, 16))
     self.assertFalse(box_1 == box_2)
コード例 #9
0
ファイル: building_test.py プロジェクト: rachillesf/terminus
 def test_bounding_box(self):
     building = Building(Point(10, 20), [Point(15, 30), Point(15, -5),
                                         Point(40, 30), Point(40, -5)], 15)
     self.assertEqual(building.bounding_box(),
                      BoundingBox(Point(25, 15), Point(50, 50, 15)))
コード例 #10
0
ファイル: road_node.py プロジェクト: rachillesf/terminus
 def bounding_box(self, width):
     if width < 0:
         raise ValueError('width should be a non negative number')
     box_origin = Point(self.center.x - width / 2, self.center.y - width / 2)
     box_corner = Point(self.center.x + width / 2, self.center.y + width / 2)
     return BoundingBox(box_origin, box_corner)
コード例 #11
0
 def test_width(self):
     box = BoundingBox(Point(25, 40), Point(30, 50))
     self.assertEqual(box.width(), 5)
コード例 #12
0
 def test_merge_with_negative_values(self):
     box_1 = BoundingBox(Point(10, -30), Point(20, -10))
     box_2 = BoundingBox(Point(-20, 10), Point(-10, 20))
     expected_merge = BoundingBox(Point(-20, -30), Point(20, 20))
     self.assertEqual(box_1.merge(box_2), expected_merge)
コード例 #13
0
 def test_from_boxes_with_one_box(self):
     box = BoundingBox(Point(17, 4), Point(59, 7))
     self.assertEqual(BoundingBox.from_boxes([box]), box)
コード例 #14
0
 def test_merge(self):
     box_1 = BoundingBox(Point(10, 20), Point(20, 30))
     box_2 = BoundingBox(Point(40, -10), Point(50, 0))
     expected_merge = BoundingBox(Point(10, -10), Point(50, 30))
     self.assertEqual(box_1.merge(box_2), expected_merge)
コード例 #15
0
 def test_bounding_box(self):
     block = Block(Point(10, 20),
                   [Point(15, 30), Point(15, -5), Point(40, 30), Point(40, -5)],
                   1)
     self.assertEqual(block.bounding_box(), BoundingBox(Point(25, 15), Point(50, 50, 1)))
コード例 #16
0
ファイル: building_test.py プロジェクト: rachillesf/terminus
 def test_bounding_box_with_one_point_building_not_centered_at_0_0(self):
     origin = Point(34, 68)
     building = Building.square(origin, 0, 14)
     self.assertEqual(building.bounding_box(), BoundingBox(origin, origin + Point(0, 0, 14)))
コード例 #17
0
ファイル: building_test.py プロジェクト: rachillesf/terminus
 def test_bounding_box_with_not_convex_base_building(self):
     building = Building(Point(0, 0),
                         [Point(-15, 0), Point(10, -40), Point(0, 0), Point(15, 30)])
     self.assertEqual(building.bounding_box(), BoundingBox(Point(-15, -40), Point(15, 30, 10)))
コード例 #18
0
ファイル: building_test.py プロジェクト: rachillesf/terminus
 def test_bounding_box_with_pentagonal_base_building(self):
     building = Building(Point(10, 20), [Point(-10, -20), Point(10, -30),
                         Point(20, 10), Point(-5, 30), Point(-20, 5)])
     self.assertEqual(building.bounding_box(),
                      BoundingBox(Point(-10, -10), Point(30, 50) + Point(0, 0, 10)))
コード例 #19
0
 def test_merge_nested_boxes(self):
     box_1 = BoundingBox(Point(20, 20), Point(30, 30))
     box_2 = BoundingBox(Point(10, 10), Point(40, 40))
     self.assertEqual(box_1.merge(box_2), box_2)
コード例 #20
0
 def test_bounding_box_with_pentagonal_base_block(self):
     block = Block(Point(10, 20),
                   [Point(-10, -20), Point(10, -30), Point(20, 10), Point(-5, 30), Point(-20, 5)],
                   2)
     self.assertEqual(block.bounding_box(),
                      BoundingBox(Point(-10, -10), Point(30, 50, 2)))
コード例 #21
0
 def test_merge_bounding_box_with_itself(self):
     box = BoundingBox(Point(30, 45), Point(15, 18))
     self.assertEqual(box.merge(box), box)
コード例 #22
0
 def test_bounding_box_with_not_convex_base_block(self):
     block = Block(Point(0, 0), [Point(-15, 0), Point(10, -40), Point(0, 0), Point(15, 30)])
     self.assertEqual(block.bounding_box(), BoundingBox(Point(-15, -40), Point(15, 30, 0.15)))
コード例 #23
0
 def test_from_boxes_with_two_boxes(self):
     box_1 = BoundingBox(Point(-5, -10), Point(5, 0))
     box_2 = BoundingBox(Point(-5, 10), Point(5, 20))
     box_list = [box_1, box_2]
     expected_merge = BoundingBox(Point(-5, -10), Point(5, 20))
     self.assertEqual(BoundingBox.from_boxes(box_list), expected_merge)
コード例 #24
0
ファイル: road_node_test.py プロジェクト: rachillesf/terminus
 def test_bounding_box(self):
     node = RoadNode(Point(-30, 25))
     expected_box = BoundingBox(Point(-40, 15), Point(-20, 35))
     self.assertEqual(node.bounding_box(20), expected_box)
コード例 #25
0
 def test_from_boxes_with_empty_box_list(self):
     box_list = []
     self.assertRaises(Exception, lambda: BoundingBox.from_boxes(box_list))
コード例 #26
0
ファイル: road_node_test.py プロジェクト: rachillesf/terminus
 def test_bounding_box_with_width_equal_to_zero(self):
     node = RoadNode(Point(18, -30))
     expected_box = BoundingBox(Point(18, -30), Point(18, -30))
     self.assertEqual(node.bounding_box(0), expected_box)
コード例 #27
0
 def test_height(self):
     box = BoundingBox(Point(-10, 18), Point(15, 43))
     self.assertEqual(box.height(), 25)
コード例 #28
0
 def test_eq_on_identical_objects(self):
     box = BoundingBox(Point(10, 10), Point(20, 20))
     self.assertTrue(box == box)
コード例 #29
0
 def bounding_box(self):
     box_origin = Point(-self.size / 2.0, -self.size / 2.0)
     box_corner = Point(self.size / 2.0, self.size / 2.0)
     box = BoundingBox(box_origin, box_corner)
     return box.translate(self.origin)
コード例 #30
0
 def test_eq_on_non_identical_objects(self):
     box = BoundingBox(Point(0, 0), Point(10, 10))
     box_with_same_origin_and_corner = BoundingBox(Point(0, 0),
                                                   Point(10, 10))
     self.assertTrue(box == box_with_same_origin_and_corner)