def add_texture(self, width, height, name): TexturePacker.add_texture(self, width, height, name) result = None if self.heuristic == FreeRectChoiceHeuristicEnum.RectBestShortSideFit: result = self._find_position_for_new_node_best_short_side_fit(width, height) elif self.heuristic == FreeRectChoiceHeuristicEnum.RectBestLongSideFit: result = self._find_position_for_new_node_best_long_side_fit(width, height) elif self.heuristic == FreeRectChoiceHeuristicEnum.RectBestAreaFit: result = self._find_position_for_new_node_best_area_fit(width, height) elif self.heuristic == FreeRectChoiceHeuristicEnum.RectBottomLeftRule: result = self._find_position_for_new_node_bottom_left(width, height) elif self.heuristic == FreeRectChoiceHeuristicEnum.RectContactPointRule: result = self._find_position_for_new_node_contact_point(width, height) else: raise NotImplementedError('Unknown MaxRects Heuristic encountered') if result[0] is None: raise PackerError('Failed to fit in %s' % (name)) if (result[0].get_height() == 0): return result[0] if (result[0].y2) > self.bin_height: raise PackerError('Can not fit in vertically %s' % (str(result[0]))) if (result[0].x2) > self.bin_width: raise PackerError('Can not fit in horizontally %s' % (str(result[0]))) self._place_rect(result[0]) return result[0]
def add_texture(self, width, height, name=""): TexturePacker.add_texture(self, width, height, name) self.longestEdge = width if (width > self.longestEdge) else self.longestEdge self.longestEdge = height if (height > self.longestEdge) else self.longestEdge self.totalArea += width * height