コード例 #1
0
 def test_get_objects_separate_lists(self):
     a = Area()
     point = Point2D(1, 1)
     segment = Segment(Point2D(3, 3), Point2D(4, 4))
     a.add_object(Point2D, point)
     a.add_object(Segment, segment)
     self.assertListEqual(a.get_objects(Point2D), [point])
     self.assertListEqual(a.get_objects(Segment), [segment])
コード例 #2
0
    def test_find_simple(self):
        point = Point2D(1, 1)
        polyline = Polyline()
        polyline.add(point)

        area = Area()
        area.add_object(Point2D, point)

        finder = PolylinesFinder(epsilon=0.5)
        finder.find(area)
        self.assertListEqual(area.get_objects(Polyline), [polyline])
コード例 #3
0
def get_square_area():
    top = [Point2D(x, 0) for x in range(0, 5)]
    right = [Point2D(4, y) for y in range(1, 5)]
    bottom = [Point2D(x, 4) for x in range(3, 0, -1)]
    left = [Point2D(0, y) for y in range(4, 0, -1)]
    square = top + right + bottom + left

    area = Area()
    for point in square:
        area.add_object(Point2D, point)

    return area
コード例 #4
0
    def test_find_simple(self):
        points = [Point2D(0, 0), Point2D(1, 1), Point2D(2, 2), Point2D(3, 3)]
        area = Area()
        polyline = Polyline()
        for point in points:
            polyline.add(point)

        area.add_object(Polyline, polyline)
        finder = RDPSegmentsFinder(epsilon=0.5)
        finder.find(area)

        self.assertListEqual(area.get_objects(Segment),
                             [Segment(points[0], points[-1])])
コード例 #5
0
    def get_area(file_path, ignore_zero_point=True, merge_duplicates=True):
        timestamped_points_lists = XYFileReader.get_data(file_path)
        if len(timestamped_points_lists) != 1:
            raise NotImplemented(
                "Area construction is not supported for files with not one instance of data"
            )

        area = Area()
        timestamped_points = next(iter(timestamped_points_lists.values()))

        previous_point = None
        zero_point = Point2D(0, 0)

        for point in timestamped_points:
            if (not merge_duplicates
                    or point != previous_point) and (not ignore_zero_point
                                                     or point != zero_point):
                area.add_object(Point2D, point)
            previous_point = point

        return area
コード例 #6
0
 def test_get_objects_not_empty(self):
     a = Area()
     point = Point2D(1, 1)
     a.add_object(Point2D, point)
     self.assertListEqual(a.get_objects(Point2D), [point])
コード例 #7
0
 def test_get_objects_if_empty(self):
     a = Area()
     self.assertListEqual(a.get_objects(Point2D), [])