From 7b8b3cf96fde7b400a178abd08008786dfc74008 Mon Sep 17 00:00:00 2001 From: Tolga Yurtseven <tolgayurt02@outlook.de> Date: Sat, 14 Nov 2020 20:52:22 +0100 Subject: [PATCH] commenting and added docs strings until the rectangular container --- mysite/plots/dataset_creator.py | 4 +- mysite/plots/packing_algo.py | 310 +++++++++++++++++++++++--------- mysite/plots/urls.py | 4 +- 3 files changed, 229 insertions(+), 89 deletions(-) diff --git a/mysite/plots/dataset_creator.py b/mysite/plots/dataset_creator.py index 98d1c7d8..5ccbd19a 100644 --- a/mysite/plots/dataset_creator.py +++ b/mysite/plots/dataset_creator.py @@ -1,5 +1,5 @@ # import pandas as pd -# from .packing_algo import ConvexPolygon, pack_polygons, truncate, End_Container, plot_containers, ConvexContainer +# from .packing_algo import ConvexPolygon, pack_polygons, truncate, RectangularContainer, plot_containers, ConvexContainer # from .polygon_creator import voronoi_polygons_wrapper, rectangle_cutter # # @@ -74,7 +74,7 @@ # 'angle_0_area/opt_area': angle_0_area_div_list, # 'angle_0_not_clipped_area/opt_area': angle_0_not_clipped_area_div_list, # 'opt-area': opt_area_list, 'polygon count': polygon_count_list, -# 'mini-container count': mini_container_count_list, 'end-container': end_container_list} +# 'mini-container count': mini_container_count_list, 'Rectangular-Container': end_container_list} # return rect_containers_data_dict # # diff --git a/mysite/plots/packing_algo.py b/mysite/plots/packing_algo.py index 62eff063..4c05687e 100644 --- a/mysite/plots/packing_algo.py +++ b/mysite/plots/packing_algo.py @@ -238,13 +238,13 @@ class ConvexPolygon(object): slope = truncate(self.__slope, 1) x_data = self.__x_values y_data = self.__y_values - TOOLTIPS = [("index", "$index"), ("(x,y)", "($x{0.0}, $y{0.0})"), ] + tooltips = [("index", "$index"), ("(x,y)", "($x{0.0}, $y{0.0})"), ] if title == "": title = 'height: {} slope: {}'.format(height, slope) else: title = '{} height: {} slope: {}'.format(title, height, slope) fig = figure(title=title, x_axis_label='x', y_axis_label='y', width=plot_width, height=plot_height, - tooltips=TOOLTIPS, ) + tooltips=tooltips, ) if self.plot_fill: poly_fig = fig.patch(x_data, y_data, line_width=1, color=color, alpha=0.9, line_alpha=1, muted_alpha=0.05) else: @@ -381,17 +381,20 @@ class HighClass(object): class Container(object): """Container which holds the packed polygons from one HighClass - Attributes: - hc (HighClass): reference to HighClass object + The Container has fixed height which is dependent from the HighClass max_boundary. + The polygon which will get packed (included/translated) will be in ascending order according to their spine value. Args: hc (HighClass): reference to HighClass object - y_boundary (float): y coordinate boundary for the container + y_boundary (float): y coordinate boundary for the container dependent of the High_Class max_boundary x_boundary (float): x coordinate boundary fot the container Tree (Tree): avl-tree data structure root (TreeNode): the root of the avl-tree datastructure sigma ([ConvexPolygon]): the list of packed convex polygons from the HighClass plot_steps ([Figure]): list of steps which are done to pack the container as plot objects + + Attributes: + hc (HighClass): reference to HighClass object """ def __init__(self, hc: HighClass) -> None: self.hc = hc @@ -482,8 +485,8 @@ class Container(object): self.root = self.Tree.insert_node(self.root, vertex[1], vertex, vertex_neighbour) sigma.append(polygon) self.x_boundary += polygon.width - plot_steps.append( - self.plot_container(sigma_plot_helper, render=False, title="Step {}".format(step_counter))) + plot_steps.append(self.plot_container(sigma_plot_helper, render=False, + title="Step {}".format(step_counter))) step_counter += 1 else: transform_x = (self.x_boundary + abs(polygon.min_x)) + 10 @@ -533,17 +536,34 @@ class Container(object): def plot_container(self, sigma=None, r_l_distances=None, l_r_distances=None, min_distance=None, render=True, title="", box_boundarys_x_values_colors_tuple=None) -> Figure: - # sigma als argument statt self.sigma dient dazu auch zwischen schritte plotten zu lassen + """Creates a plot object of the actual container + + Args: + sigma ([ConvexPolygon]): ConvexPolygons which are already packed into the container + r_l_distances ([(Point_xy, float)]): the tuples represent the vertices visible from left of the polygon + to pack and their distances to the corresponding edges + l_r_distances ([(Point_xy, float)]): the tuples represent the vertices visible from right of all already + packed polygons and their distances to the corresponding edges + min_distance (float): the minimal distance from all distances right to left and left to right + render (bool): if True the plot will be also rendered else not + title (str): the title of the plot default "" + box_boundarys_x_values_colors_tuple (([float],[color])): the boundary x values for the boxes and their + background color, the boxes will later be + extended to the mini-containers + Returns: + fig (Figure): a plot object of the container + """ legend_items = [] legend_polygons = [] legend_spine = [] legend_lr = [] legend_rl = [] legend_vertices = [] - if sigma == None: + if sigma is None: sigma = self.sigma - TOOLTIPS = [("index", "$index"), ("(x,y)", "($x{0.0}, $y{0.0})"), ] - fig = figure(title=title, x_axis_label='x', y_axis_label='y', tooltips=TOOLTIPS, toolbar_location="left") + tooltips = [("index", "$index"), ("(x,y)", "($x{0.0}, $y{0.0})"), ] + fig = figure(title=title, x_axis_label='x', y_axis_label='y', tooltips=tooltips, toolbar_location="left") + # builds the polygon plots for counter, polygon in enumerate(sigma): x_values = polygon.x_values y_values = polygon.y_values @@ -557,7 +577,10 @@ class Container(object): spine_fig = fig.line(x_spine, y_spine, line_color="red", line_width=1, alpha=0.01, muted_color="red", muted_alpha=1) legend_spine.append(spine_fig) - if box_boundarys_x_values_colors_tuple != None: + # mark the boxes with their background color, these boxes will later be extend to mini-containers + if title == "": + fig.title.text = 'Hc_{}-Container height: {} '.format(self.hc.i, truncate(self.y_boundary, 1)) + if box_boundarys_x_values_colors_tuple is not None: box_boundarys_x_values = box_boundarys_x_values_colors_tuple[0] background_c_list = box_boundarys_x_values_colors_tuple[1] for counter, boundary in enumerate(box_boundarys_x_values[0:-1]): @@ -566,11 +589,8 @@ class Container(object): right=next_boundary, fill_color=background_c_list[counter], fill_alpha=0.1) fig.add_layout(color_box) fig.line([next_boundary, next_boundary], [0, self.y_boundary], line_dash="dotted") - fig.title.text = 'Hc-Container{} height: {} -> Mini Containers'.format(self.hc.i, - truncate(self.y_boundary, 1)) - if title == "": - fig.title.text = 'Hc-Container{} height: {} '.format(self.hc.i, truncate(self.y_boundary, 1)) - if r_l_distances != None: + fig.title.text = 'Hc_{}-Container to Mini Containers'.format(self.hc.i, truncate(self.y_boundary, 1)) + if r_l_distances is not None: for vertex_distance_tuple in r_l_distances: vertex_r = vertex_distance_tuple[0] distance = vertex_distance_tuple[1] @@ -591,7 +611,7 @@ class Container(object): render_mode='canvas') fig.add_layout(labels) legend_rl.append(fig_rl) - if l_r_distances != None: + if l_r_distances is not None: for vertex_distance_tuple in l_r_distances: vertex_l = vertex_distance_tuple[0] distance = vertex_distance_tuple[1] @@ -617,9 +637,9 @@ class Container(object): [0, 0, self.y_boundary, self.y_boundary, 0], line_color="black", alpha=0.7, line_width=1, muted_alpha=0.2, ) legend_items.append(("spine", legend_spine)) - if l_r_distances != None: + if l_r_distances is not None: legend_items.append(("distance-lr", legend_lr)) - if r_l_distances != None: + if r_l_distances is not None: legend_items.append(("distance-rl", legend_rl)) legend_items.append(("boundary", [fig_boundary])) legend_items.append(("vertices", legend_vertices)) @@ -632,11 +652,23 @@ class Container(object): return fig def plot_container_steps(self, render=True, colums=2, plot_width=600, plot_height=600) -> Column: + """Build a plot object which includes all container packing steps/plots + + This plot is a grid plot, which means that it is result of merging several plots. + + Args: + render (bool): If True the plot will be rendered else not + colums (int): the number of colums in which the packing steps are listed + plot_width (int): the width of the single plot objects + plot_height (int): the height of the single plot objects + + Returns: + grid_layout(Column): A plot object with all packing steps inside + """ grid = gridplot(self.plot_steps, ncols=colums, plot_width=plot_width, plot_height=plot_height, toolbar_location="left") min_border = (int(self.hc.min_border * 10)) / 10 max_border = (int(self.hc.max_border * 10)) / 10 - # text="<b>Hc_{} height: {}-{} alpha: {}<b> title = Div( text="<b>Highclass Container {}, Polygon height: {}-{} <b>".format(self.hc.i, min_border, max_border)) @@ -646,29 +678,63 @@ class Container(object): return grid_layout -class Mini_Container(object): +class MiniContainer(object): + """An object which holds the polygons from a container box + + The Container which got packed/build from a HighClass got "theoretically" divided into boxes. A mini-container is + an extension of the width of one these boxes. + The purpose is to have mini-containers with fixed widths so they easily can be stacked, when the + RectengularContainer is build. + + Args: + max_width (float): is the maximum width for all mini-containers which will be created + formula:= (c+1)* max_width_of_all_polygons_to_pack + max_height (float): the y boundary of the Container which was divided into the boxes + max_polygon_width (float): is the value of the max_width_of_all_polygons_to_pack + hc_i (int): the number of the HighClass starting at 0, hc_0 would be the first HighClass + c (float): c = 2.214 helps to build the mini-container max_width for more information look into the paper + + Attributes: + max_polygon_width (float): the value of the max_width_of_all_polygons_to_pack + current_right_boundary (float): the biggest x coordinate value of all the polygons in the mini-container + height (float): the biggest y coordinate value of all the polygons in the mini-container + hc_i (int): the number of the HighClass starting at 0, hc_0 would be the first HighClass + max_height (float): the y boundary of the Container which was divided into the boxes + max_width (float): is the maximum width for all mini-containers which will be created + formula:= (c+1)* max_width_of_all_polygons_to_pack + c (float): c = 2.214 helps to build the mini-container max_width for more information look into the paper + polygons ([ConvexPolygon]): Convex polygons which are in the mini-container + y_offset (float): offset which helps to stack the mini-container to the RectangularContainer + """ def __init__(self, max_width: float, max_height: float, max_polygon_width: float, hc_i: int, c=2.214) -> None: self.max_polygon_width = max_polygon_width self.current_right_boundary = 0 self.height = 0 self.hc_i = hc_i - self.hc_height = max_height + self.max_height = max_height self.max_width = max_width self.c = c self.polygons = [] self.y_offset = 0 - self.plot_steps = [] def plot_container(self, render=True, title="", background_c=None) -> Figure: + """Creates a plot object of the mini-container + + Args: + render (bool): if True the mini-container is also rendered else not + title (str): the title of the plot + background_c (str): a color for the plot background + + Returns: + fig (Figure): a plot object of the mini-container + """ y_offset = self.y_offset legend_polygons = [] legend_spine = [] - legend_lr = [] - legend_rl = [] legend_vertices = [] - TOOLTIPS = [("index", "$index"), ("(x,y)", "($x{0.0}, $y{0.0})"), ] - fig = figure(title=title, x_axis_label='x', y_axis_label='y', tooltips=TOOLTIPS, toolbar_location="left") - if background_c != None: + tooltips = [("index", "$index"), ("(x,y)", "($x{0.0}, $y{0.0})"), ] + fig = figure(title=title, x_axis_label='x', y_axis_label='y', tooltips=tooltips, toolbar_location="left") + if background_c is not None: color_box = BoxAnnotation(left=0, right=self.max_width, bottom=y_offset, top=y_offset + self.height, fill_color=background_c, fill_alpha=0.1) @@ -707,69 +773,142 @@ class Mini_Container(object): return fig -class End_Container(object): - def __init__(self, mini_container_array: [Mini_Container], angle=0) -> None: +class RectangularContainer(object): + """The RectangularContainer which holds the packed polygons which are the result of the packing algorithm, + + For building the RectangularContainer all the MiniContainers will be stacked on each other. + + Args: + mini_container_array ([MiniContainer]): the mini-container to pack + angle (int): the angle of the RectangularContainer default=0°, will be used for optimizations and to build the + convex-container + Attributes: + mini_containers ([MiniContainer]): the mini containers in their final position + initial_mini_containers ([MiniContainer]): a redundant copy of all mini-container in their initial position + polygons ([ConvexPolygon]): the result of the packing algorithm all start polygons packed + x_boundary (float): the x boundary of the RectangularContainer + y_boundary (float): the y boundary of the RectangularContainer + container_not_clipped_area (float): the area of the RectangularContainer without clipping/optimization, + optimizations are clipping the mini-containers y boundary to the highest + vertex of all polygons inside the MiniContainer instead of using the + HighClass boundary of the MiniContainer. + Another optimization is to clip the RectangularContainer x boundary to + the rightest vertex of all polygons inside the RectangularContainer instead + of using the MiniContainer x boundary. + polygon_shells ([[Point_xy]]): a list of all packed polygon shells + x_values_border ([float]): the x values of the RectangularContainer border + y_values_border ([float]): the y values of the RectangularContainer border + container_area (float): the optimized/clipped container area + angle (int): the angle of the RectangularContainer default=0°, will be used for optimizations and to build the + convex-container + plot_steps_all (Tabs): plot object with all steps to pack the RectangularContainer with tabs + + """ + def __init__(self, mini_container_array: [MiniContainer], angle=0) -> None: self.mini_containers = copy.deepcopy(mini_container_array) self.initial_mini_containers = mini_container_array - self.polygons, self.max_width, self.max_height, self.container_not_clipped_area = self.pack_container() + self.polygons, self.x_boundary, self.y_boundary, self.container_not_clipped_area = self.pack_container() self.polygon_shells = self.collect_polygon_shells() - self.x_values_border = [0, 0, self.max_width, self.max_width, 0] - self.y_values_border = [0, self.max_height, self.max_height, 0, 0] - self.container_area = self.max_width * self.max_height + self.x_values_border = [0, 0, self.x_boundary, self.x_boundary, 0] + self.y_values_border = [0, self.y_boundary, self.y_boundary, 0, 0] + self.container_area = self.x_boundary * self.y_boundary self.angle = angle self.plot_steps_all = None def collect_polygon_shells(self): + """Collects the polygon shells of the packed polygons + + Returns: + polygon_shells ([[Point_xy]]): a list of all packed polygon shells + """ polygon_shells = [] for polygon in self.polygons: polygon_shells.append(polygon.shell) return polygon_shells def pack_container(self) -> ([ConvexPolygon], float, float): - y_offset = 0 - end_c_polygons = [] - container_polygon_boundary_width = 0 + """Stacks the mini-containers and build the RectangularContainer + + Returns: + rect_c_polygons ([ConvexPolygon]): packed polygons + x_boundary (float): x boundary of the RectangularContainer + y_boundary (float): the y boundary of the RectangularContainer + container_not_clipped_area (float): area of the not clipped RectangularContainer + """ + x_boundary = 0 + y_boundary = 0 + rect_c_polygons = [] container_not_clipped_area = 0 for mini_container in self.mini_containers: - container_not_clipped_area += mini_container.max_width * mini_container.hc_height + container_not_clipped_area += mini_container.max_width * mini_container.max_height for polygon in mini_container.polygons: - polygon.translation(0, y_offset) - mini_container.y_offset = y_offset - y_offset += mini_container.height - end_c_polygons = end_c_polygons + mini_container.polygons - if container_polygon_boundary_width < mini_container.current_right_boundary: - container_polygon_boundary_width = mini_container.current_right_boundary - return (end_c_polygons, container_polygon_boundary_width, y_offset, container_not_clipped_area) + polygon.translation(0, y_boundary) + mini_container.y_offset = y_boundary + y_boundary += mini_container.height + rect_c_polygons = rect_c_polygons + mini_container.polygons + if x_boundary < mini_container.current_right_boundary: + x_boundary = mini_container.current_right_boundary + return rect_c_polygons, x_boundary, y_boundary, container_not_clipped_area def plot_polygons(self, title="", plot_width=500, plot_height=500, render=True) -> Figure: + """Creates a plot object for all packed polygons + + Args: + title (str): title of the plot + plot_width (int): the width of the plot figure + plot_height (int): the height of the plot figure + render (bool): if True the plot object will be rendered else not + + Returns: + fig (Figure): plot object with all packed polygons + """ if title == "": - title = 'End-Container area: {} not-clipped-area: {} angle:{}'.format(truncate(self.container_area, 1), - truncate( - self.container_not_clipped_area, - 1), self.angle) + title = 'Rectangular-Container area: {} not-clipped-area: {} ' \ + 'angle:{}'.format(truncate(self.container_area, 1), truncate(self.container_not_clipped_area, 1), + self.angle) fig = plot_polygons_in_single_plot(self.polygons, title=title, plot_width=plot_width, plot_height=plot_height, render=render, border=(self.x_values_border, self.y_values_border)) return fig - def plot_steps(self, render=True): + def plot_steps(self, render=True) -> Tabs: + """Plot object with all steps needed to pack the RectangularContainer + + Args: + render (bool): if True the plot object will be rendered else not + + Returns: + plot_steps_all (Tabs): plot object with all steps to pack the RectangularContainer with tabs + """ if render: show(self.plot_steps_all) return self.plot_steps_all def plot_container(self, title="", plot_width=600, plot_height=600, solo_box_border=False, render=True, reverse_legend=True) -> Figure: + """Plot object with all stacked mini-containers with background colors + + Args: + title (str): title of the plot + plot_width (int): plot width + plot_height (int): plot height + solo_box_border (bool): if True shows for every mini-container an own x boundary which is build by the + rightest polygon in this mini-container + render (bool): if True the plot object will be rendered else not + reverse_legend (bool): if True the legend of the plot will be reversed else not + + Returns: + fig (Figure): plot object with all stacked mini-containers with background colors + """ legend_mini_containers = [] legend_spine = [] - legend_lr = [] - legend_rl = [] legend_items = [] legend_vertices = [] - TOOLTIPS = [("index", "$index"), ("(x,y)", "($x{0.0}, $y{0.0})"), ] + tooltips = [("index", "$index"), ("(x,y)", "($x{0.0}, $y{0.0})"), ] if title == "": - title = 'End-Container area: {} not-clipped-area: {} angle:{}'.format( + title = 'Rectangular-Container area: {} not-clipped-area: {} angle:{}'.format( truncate(self.container_area, 1), truncate(self.container_not_clipped_area, 1), self.angle) fig = figure(title=title, x_axis_label='x', y_axis_label='y', width=plot_width, height=plot_height, - toolbar_location="left", tooltips=TOOLTIPS) + toolbar_location="left", tooltips=tooltips) y_offset = 0 colors = itertools.cycle(palette) for counter, mini_container in enumerate(self.mini_containers): @@ -792,9 +931,9 @@ class End_Container(object): legend_vertices.append(fig_circle) if solo_box_border: mini_box_border = mini_container.current_right_boundary - fig.title.text = 'End-Container mini-containers with solo boundarys' + fig.title.text = 'Rectangular-Container mini-containers with solo boundaries' else: - mini_box_border = self.max_width + mini_box_border = self.x_boundary color_box = BoxAnnotation(left=0, right=mini_box_border, bottom=mini_container.y_offset, top=mini_container.y_offset + mini_container.height, fill_color=color, fill_alpha=0.1) @@ -824,15 +963,15 @@ class ConvexContainer(object): def __init__(self, polygons: [ConvexPolygon], steps=90, build_plots=True) -> None: self.angle_0_end_container = pack_polygons(polygons) self.angle_0_end_container_polygons = self.angle_0_end_container.polygons - self.rotate_center = (self.angle_0_end_container.max_width / 2, self.angle_0_end_container.max_height / 2) - self.rotated_end_container_list = [] # Liste aller Endcontainer + self.rotate_center = (self.angle_0_end_container.x_boundary / 2, self.angle_0_end_container.y_boundary / 2) + self.rotated_end_container_list = [] # Liste aller RectangularContainer self.rotated_container_plots = [] self.back_rotated_polygons_plots = [] self.smallest_end_container, self.polygons, self.angle, self.area = self.find_convex_container(steps, build_plots) self.polygon_shells = self.collect_polygon_shells() - self.width = self.smallest_end_container.max_width - self.height = self.smallest_end_container.max_height + self.width = self.smallest_end_container.x_boundary + self.height = self.smallest_end_container.y_boundary self.boundarys_x_values, self.boundarys_y_values = self.set_boundarys() self.plot_steps_all = self.build_plot_steps() @@ -843,7 +982,7 @@ class ConvexContainer(object): convex_c_panels.append(smallest_c_tab) rotated_c = self.plot_rotated_containers(render=False, plot_width=800, plot_height=700) - rotated_c_tab = Panel(child=rotated_c, title="Rotated-End-Containers") + rotated_c_tab = Panel(child=rotated_c, title="Rotated-Rectangular-Containers") convex_c_panels.append(rotated_c_tab) back_rotated_c = self.plot_back_rotated_polygons(render=False, plot_width=800, plot_height=700) @@ -861,7 +1000,7 @@ class ConvexContainer(object): show(self.plot_steps_all) return self.plot_steps_all - def find_convex_container(self, steps: int, build_plots=True) -> (End_Container, [ConvexPolygon], int, float): + def find_convex_container(self, steps: int, build_plots=True) -> (RectangularContainer, [ConvexPolygon], int, float): list_of_area = [] polygons = [] for angle in range(0, 360, steps): @@ -870,8 +1009,8 @@ class ConvexContainer(object): # rotated_end_container.angle=angle self.rotated_end_container_list.append(rotated_end_container) list_of_area.append(rotated_end_container) - if build_plots: # das Flag ist aus Performance gründen da sonst wird jeder End Container zurück rotiert - title = 'End-Container area: {} not-clipped-area: {} angle: {}'.format( + if build_plots: # das Flag ist aus Performance gründen da sonst wird jeder Rectangular-Container zurück rotiert + title = 'Rectangular-Container area: {} not-clipped-area: {} angle: {}'.format( truncate(rotated_end_container.container_area, 1), truncate(rotated_end_container.container_not_clipped_area, 1), rotated_end_container.angle) self.rotated_container_plots.append(rotated_end_container.plot_container(render=False, title=title)) @@ -957,7 +1096,7 @@ def rotate_polygons(polygons: [ConvexPolygon], angle: int, origin=(0, 0)) -> [Co return rotated_polygons -def build_mini_containers_and_plots(container_array: [Container], c=2.214) -> ([Mini_Container], [[Figure]]): +def build_mini_containers_and_plots(container_array: [Container], c=2.214) -> ([MiniContainer], [[Figure]]): mini_container_array = [] mini_container_plots_list = [] colors = itertools.cycle(palette) @@ -982,7 +1121,7 @@ def build_mini_containers_and_plots(container_array: [Container], c=2.214) -> ([ # wichtig zu kucken ob der container noch Polygone enthält da die linkesten Punkte noch in der anderen Box liegen können und eine Box leer sein kann # while len(container_sigma) > 0 and (box_width * box_counter) < (container.x_boundary): while len(container_sigma) > 0: - mini_container = Mini_Container(max_width_mini_container, (container.y_boundary), + mini_container = MiniContainer(max_width_mini_container, (container.y_boundary), container.hc.w_max_polygon, container.hc.i) translation = box_width * (box_counter - 1) min_translation = math.inf @@ -1088,9 +1227,9 @@ def plot_polygons_in_single_plot(polygon_list: [ConvexPolygon], title="", plot_w border=None, reverse_legend=False) -> Figure: polygon_number = len(polygon_list) - TOOLTIPS = [("index", "$index"), ("(x,y)", "($x{0.0}, $y{0.0})"), ] + tooltips = [("index", "$index"), ("(x,y)", "($x{0.0}, $y{0.0})"), ] fig = figure(title=title, x_axis_label='x', y_axis_label='y', width=plot_width, height=plot_height, - tooltips=TOOLTIPS, toolbar_location="left") + tooltips=tooltips, toolbar_location="left") colors = itertools.cycle(palette) legend_items = [] legend_polygons = [] @@ -1139,8 +1278,8 @@ def build_height_classes(polygon_list: [ConvexPolygon]) -> [HighClass]: while polygon_count > 0: hc = HighClass(i, alpha, h_max_polygon, w_max_polygon) hc_polygons = [] - while polygon_count > 0 and hc.min_border < ordered_polygons[0].height and ordered_polygons[ - 0].height <= hc.max_border: + while polygon_count > 0 and hc.min_border < ordered_polygons[0].height and \ + ordered_polygons[0].height <= hc.max_border: hc_polygons.append(ordered_polygons.pop(0)) polygon_count -= 1 hc.set_polygons(hc_polygons) @@ -1158,12 +1297,12 @@ def building_containers(height_classes: [HighClass]) -> [Container]: return containers -def pack_polygons(polygons: [ConvexPolygon], angle=0) -> End_Container: - # building the endcontainer +def pack_polygons(polygons: [ConvexPolygon], angle=0) -> RectangularContainer: + # building the RectangularContainer list_hc = build_height_classes(polygons) list_containers = building_containers(list_hc) list_mini_containers, mini_container_plot_steps = build_mini_containers_and_plots(list_containers) - end_container = End_Container(list_mini_containers, angle) + end_container = RectangularContainer(list_mini_containers, angle) # plots p_tab = polygons_to_tab_plot(polygons) @@ -1175,7 +1314,7 @@ def pack_polygons(polygons: [ConvexPolygon], angle=0) -> End_Container: mc_tab = mini_container_plots_to_tab_plot(mini_container_plot_steps) mc_header_tab = Panel(child=mc_tab, title="Mini-Containers") ec_tab = end_container_to_tab_plot(end_container) - ec_header_tab = Panel(child=ec_tab, title="End-Container") + ec_header_tab = Panel(child=ec_tab, title="Rectangular-Container") all_tabs_with_header = Tabs(tabs=[p_header_tab, hc_header_tab, c_header_tab, mc_header_tab, ec_header_tab]) end_container.plot_steps_all = all_tabs_with_header @@ -1212,7 +1351,7 @@ def hc_to_tab_plot(list_hc: [HighClass], plot_width=450, plot_height=450) -> Tab hc_tab_list = [] for counter, hc in enumerate(list_hc): hc_plot = hc.plot_hc(render=False, plot_width=plot_width, plot_height=plot_height) - tab = Panel(child=hc_plot, title="High-Class {}".format(counter)) + tab = Panel(child=hc_plot, title="High-Class {}".format(hc.i)) hc_tab_list.append(tab) hc_tabs = Tabs(tabs=hc_tab_list) return hc_tabs @@ -1223,29 +1362,30 @@ def containers_to_tab_plot(list_containers: [Container], plot_width=700, plot_he for counter, container in enumerate(list_containers): container_plot = container.plot_container_steps(plot_width=plot_width, colums=3, plot_height=plot_height, render=False) - tab = Panel(child=container_plot, title="Container {}".format(counter, counter)) + tab = Panel(child=container_plot, title="Hc_{} Container".format(container.hc.i)) container_tab_list.append(tab) container_tabs = Tabs(tabs=container_tab_list) return container_tabs -def mini_container_plots_to_tab_plot(mini_container_plot_steps: [Figure], plot_width=700, plot_height=700, - ncols=3) -> Tabs: +def mini_container_plots_to_tab_plot(mini_container_plot_steps: [Figure], plot_width=700, plot_height=700, ncols=3) \ + -> Tabs: mini_plots_tabs = [] for counter, m_plot in enumerate(mini_container_plot_steps): - m_plot_grid = gridplot(m_plot, ncols=3, plot_width=plot_width, plot_height=plot_height, toolbar_location="left") - grid_title = Div(text="<b>Hc{} to Mini-Containers<b>".format(counter)) + title = m_plot[0].title.text + m_plot_grid = gridplot(m_plot, ncols=ncols, plot_width=plot_width, plot_height=plot_height, toolbar_location="left") + grid_title = Div(text="<b>{}<b>".format(title)) mc_layout = layout(grid_title, m_plot_grid) - tab = Panel(child=mc_layout, title="Hc{} Mini-Containers".format(counter)) + tab = Panel(child=mc_layout, title=title) mini_plots_tabs.append(tab) mini_tabs = Tabs(tabs=mini_plots_tabs) return mini_tabs -def end_container_to_tab_plot(end_container: End_Container, plot_width=800, plot_height=800) -> Tabs: +def end_container_to_tab_plot(end_container: RectangularContainer, plot_width=800, plot_height=800) -> Tabs: end_container_tabs = [] polygons_plot = end_container.plot_polygons(render=False, plot_width=plot_width, plot_height=plot_height) - tab = Panel(child=polygons_plot, title="End-Container") + tab = Panel(child=polygons_plot, title="Rectangular-Container") end_container_tabs.append(tab) container_plot = end_container.plot_container(render=False, plot_width=plot_width, plot_height=plot_height) tab = Panel(child=container_plot, title="Show Mini-Containers") diff --git a/mysite/plots/urls.py b/mysite/plots/urls.py index 88cf1676..88d2d49a 100644 --- a/mysite/plots/urls.py +++ b/mysite/plots/urls.py @@ -1,7 +1,7 @@ from django.urls import path from plots.views import PolygonEditView, PackingRectContainer, PackingRotatedRectContainer, PackingConvexContainer, \ - CSVPolygons, ClearPolygons ,CreateConvexPolygons -from . import views + CSVPolygons, ClearPolygons, CreateConvexPolygons + urlpatterns = [ path('', PolygonEditView.as_view(), name='start-page'), -- GitLab