def __init__(self, width, height, order, flip=False): self.order = order if flip: Square.__init__(self, width, height) else: Square.__init__(self, height, width)
def test_perimeter_returns_four_times_its_side(self): square = Square(0 , 0 , 5) self.assertEqual(20, square.perimeter()) square.width =3 self.assertEqual(20, square.perimeter())
def example_3(resolution: int = 100, save: bool = False): obstacle1 = Square(np.array([40, 40]), 30) obstacle2 = Square(np.array([60, 60]), 25) grid_ = BrushfireGrid(resolution, [obstacle1, obstacle2], animate_calculation=save, results_name='Example3') grid_.plot_distances(save=save) grid_.plot_voronoi_boundary(save=save) grid_.plot_voronoi_diagram(save=save) plt.show()
def example_4(resolution: int = 100, save: bool = False): obstacle1 = Square(np.array([40, 40]), 30) obstacle2 = Square(np.array([60, 60]), 25) grid_ = BrushfireGrid(resolution, [obstacle1, obstacle2], results_name='Example4') start = np.array([[10, 40], [60, 20], [40, 60]]) goal = np.array([70, 80]) grid_.plot_path_on_distances(start, goal, save=save) grid_.plot_path_on_gvd(start, goal, save=save) grid_.plot_path_on_real(start, goal, save=save) plt.show()
def test_square_constructor(): s = Square(1, 5, 2, 12) assert s.x == 1 assert s.y == 5 assert s.a == 2 assert s.angle == 12
def example_1(resolution: int = 100, save: bool = False): obstacle = Square(np.array([50, 50]), 50) grid = BrushfireGrid(resolution, [obstacle], animate_calculation=save, results_name='Example1') grid.plot_distances(save=save) grid.plot_voronoi_boundary(save=save) grid.plot_voronoi_diagram(save=save) plt.show()
def __init__(self, resolution: int, obstacles: List[Polygon], animate_calculation: bool = False, results_name: str = None): self.resolution = resolution self.side_length = 100 self.pixel_width = self.side_length / self.resolution self.pixel_shape = Square(np.array([0, 0]), self.pixel_width) self._corners = [(0, 0), (self.resolution - 1, self.resolution - 1), (0, self.resolution - 1), (self.resolution - 1, 0)] self._obstacles = obstacles self._expanded_obstacles = [] self._pixel_values = self._instantiate_pixel_values() self._voronoi_boundary = np.zeros((resolution, resolution), dtype=bool) self._pixel_ownership = self._instantiate_pixel_ownership() self._animate = animate_calculation results_dir = os.path.join(os.pardir, 'results') if not os.path.exists(results_dir): os.makedirs(results_dir) results_name = results_name if results_name is not None else datetime_name( ) self._results_dir = os.path.join(results_dir, results_name) if not os.path.exists(self._results_dir): os.makedirs(self._results_dir) if animate_calculation: self._tmp_dir = os.path.join(self._results_dir, 'tmp') if not os.path.exists(self._tmp_dir): os.makedirs(self._tmp_dir) self._calculate()
from geometry import Triangle, Circle, Point, Square if __name__ == '__main__': figure_list = [ Triangle(Point(0, 0), Point(0, 2), Point(3, 4)), Circle(2, Point(0, 0)), Square(Point(0, 0), Point(2, 2)) ] for figure in figure_list: figure.figure_square() figure.figure_perimeter() print(f'{figure.square},{figure.perimeter}')
def return_shape(): return choice([Rectangle(), Square(), Cube()])
def test_square_perimeter(): square_p = Square(4, 20, 4, 0) assert square_p.perimeter() == 32
def test_square_area(): s = Square(1, 5, 2, 12) assert s.area() == 16