def find(self, area: Area) -> Area: points = area.get_objects(Point2D) segments = self.find_segments_from_points(points) for segment in segments: area.add_object(Segment, segment) return area
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])
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
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])])
def find(self, area: Area): points = list(area.get_objects(Point2D)) if self._segmentation_size > 0: segmentation_coordinators = self._perform_segmentation(points) else: segmentation_coordinators = self._perform_segmentation_simplified(points) for coordinator in segmentation_coordinators: line = Line2D(p1=Point2D(0, coordinator.entity.offset), slope=coordinator.entity.slope) segment_finder = SegmentsInLineFinder() segments = segment_finder.find_segments(line, coordinator.entity.points, self._segment_eps) for segment in segments: area.add_object(Segment, segment) return area
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])
def draw(self, area: Area, draw_points=True, draw_polylines=True, draw_segments=True): if draw_points: point_style, points_kwargs = self.get_style_for('points') self.draw_points(area.get_objects(Point2D), point_style, points_kwargs) if draw_polylines: polylines_style, polylines_kwargs = self.get_style_for('polylines') self.draw_polylines(area.get_objects(Polyline), polylines_style, polylines_kwargs) if draw_segments: segments_style, segments_kwargs = self.get_style_for('segments') self.draw_segments(area.get_objects(Segment), segments_style, segments_kwargs) plt.show()
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
def find(self, area: Area) -> Area: polylines = area.get_objects(Polyline) segments = self.find_segments_in_polylines(polylines) for segment in segments: area.add_object(Segment, segment) return area
def find(self, area: Area) -> Area: points = area.get_objects(Point2D) polylines = self.find_polylines(points) for line in polylines: area.add_object(Polyline, line) return area
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])
def test_get_objects_if_empty(self): a = Area() self.assertListEqual(a.get_objects(Point2D), [])