<commit_before>__copyright__ = "Copyright (C) 2013 <NAME> - Released under terms of the AGPLv3 License"
import random
import numpy

class _objectOrder(object):
	def __init__(self, order, todo):
		self.order = order
		self.todo = todo

class _objectOrderFinder(object):
	def __init__(self, scene, offset, leftToRight, frontToBack, gantryHeight):
		self._scene = scene
		self._offset = offset - numpy.array([0.1,0.1])
		self._objs = scene.objects()
		self._leftToRight = leftToRight
		self._frontToBack = frontToBack
		initialList = []
		for n in xrange(0, len(self._objs)):
			if scene.checkPlatform(self._objs[n]):
				initialList.append(n)
		for n in initialList:
			if self._objs[n].getSize()[2] > gantryHeight and len(initialList) > 1:
				self.order = None
				return
		if len(initialList) == 0:
			self.order = []
			return


		self._hitMap = [None] * (max(initialList)+1)
		for a in initialList:
			self._hitMap[a] = [False] * (max(initialList)+1)
			for b in initialList:
				self._hitMap[a][b] = self._checkHit(a, b)

		initialList.sort(self._objIdxCmp)

		n = 0
		self._todo = [_objectOrder([], initialList)]
		while len(self._todo) > 0:
			n += 1
			current = self._todo.pop()
			#print len(self._todo), len(current.order), len(initialList), current.order
			for addIdx in current.todo:
				if not self._checkHitFor(addIdx, current.order) and not self._checkBlocks(addIdx, current.todo):
					todoList = current.todo[:]
					todoList.remove(addIdx)
					order = current.order[:] + [addIdx]
					if len(todoList) == 0:
						self._todo = None
						self.order = order
						return
					self._todo.append(_objectOrder(order, todoList))
		self.order = None

	def _objIdxCmp(self, a, b):
		scoreA = sum(self._hitMap[a])
		scoreB = sum(self._hitMap[b])
		return scoreA - scoreB

	def _checkHitFor(self, addIdx, others):
		for idx in others:
			if self._hitMap[addIdx][idx]:
				return True
		return False

	def _checkBlocks(self, addIdx, others):
		for idx in others:
			if addIdx != idx and self._hitMap[idx][addIdx]:
				return True
		return False

	def _checkHit(self, addIdx, idx):
		addPos = self._scene._objectList[addIdx].getPosition()
		addSize = self._scene._objectList[addIdx].getSize()
		pos = self._scene._objectList[idx].getPosition()
		size = self._scene._objectList[idx].getSize()

		if self._leftToRight:
			if addPos[0] - addSize[0] / 2 - self._offset[0] <= pos[0] + size[0] / 2:
				return False
		else:
			if addPos[0] + addSize[0] / 2 + self._offset[0] <= pos[0] - size[0] / 2:
				return False

		if self._frontToBack:
			if addPos[1] - addSize[1] / 2 - self._offset[1] >= pos[1] + size[1] / 2:
				return False
		else:
			if addPos[1] + addSize[1] / 2 + self._offset[1] >= pos[1] - size[1] / 2:
				return False

		return True

class Scene(object):
	def __init__(self):
		self._objectList = []
		self._sizeOffsets = numpy.array([0.0,0.0], numpy.float32)
		self._machineSize = numpy.array([100,100,100], numpy.float32)
		self._headOffsets = numpy.array([18.0,18.0], numpy.float32)
		self._leftToRight = False
		self._frontToBack = True<commit_msg>Fix object print order bug for UM2.<commit_after>__copyright__ = "Copyright (C) 2013 <NAME> - Released under terms of the AGPLv3 License"
import random
import numpy

class _objectOrder(object):
	def __init__(self, order, todo):
		self.order = order
		self.todo = todo

class _objectOrderFinder(object):
	def __init__(self, scene, offset, leftToRight, frontToBack, gantryHeight):
		self._scene = scene
		self._offset = offset - numpy.array([0.1,0.1])
		self._objs = scene.objects()
		self._leftToRight = leftToRight
		self._frontToBack = frontToBack
		initialList = []
		for n in xrange(0, len(self._objs)):
			if scene.checkPlatform(self._objs[n]):
				initialList.append(n)
		for n in initialList:
			if self._objs[n].getSize()[2] > gantryHeight and len(initialList) > 1:
				self.order = None
				return
		if len(initialList) == 0:
			self.order = []
			return


		self._hitMap = [None] * (max(initialList)+1)
		for a in initialList:
			self._hitMap[a] = [False] * (max(initialList)+1)
			for b in initialList:
				self._hitMap[a][b] = self._checkHit(a, b)

		initialList.sort(self._objIdxCmp)

		n = 0
		self._todo = [_objectOrder([], initialList)]
		while len(self._todo) > 0:
			n += 1
			current = self._todo.pop()
			#print len(self._todo), len(current.order), len(initialList), current.order
			for addIdx in current.todo:
				if not self._checkHitFor(addIdx, current.order) and not self._checkBlocks(addIdx, current.todo):
					todoList = current.todo[:]
					todoList.remove(addIdx)
					order = current.order[:] + [addIdx]
					if len(todoList) == 0:
						self._todo = None
						self.order = order
						return
					self._todo.append(_objectOrder(order, todoList))
		self.order = None

	def _objIdxCmp(self, a, b):
		scoreA = sum(self._hitMap[a])
		scoreB = sum(self._hitMap[b])
		return scoreA - scoreB

	def _checkHitFor(self, addIdx, others):
		for idx in others:
			if self._hitMap[addIdx][idx]:
				return True
		return False

	def _checkBlocks(self, addIdx, others):
		for idx in others:
			if addIdx != idx and self._hitMap[idx][addIdx]:
				return True
		return False

	def _checkHit(self, addIdx, idx):
		addPos = self._scene._objectList[addIdx].getPosition()
		addSize = self._scene._objectList[addIdx].getSize()
		pos = self._scene._objectList[idx].getPosition()
		size = self._scene._objectList[idx].getSize()

		if self._leftToRight:
			if addPos[0] - addSize[0] / 2 - self._offset[0] >= pos[0] + size[0] / 2:
				return False
		else:
			if addPos[0] + addSize[0] / 2 + self._offset[0] <= pos[0] - size[0] / 2:
				return False

		if self._frontToBack:
			if addPos[1] - addSize[1] / 2 - self._offset[1] >= pos[1] + size[1] / 2:
				return False
		else:
			if addPos[1] + addSize[1] / 2 + self._offset[1] <= pos[1] - size[1] / 2:
				return False

		return True

class Scene(object):
	def __init__(self):
		self._objectList = []
		self._sizeOffsets = numpy.array([0.0,0.0], numpy.float32)
		self._machineSize = numpy.array([100,100,100], numpy.float32)
		self._headOffsets = numpy.array([18.0,18.0], numpy.float32)
		self._leftToRight = False
		self._frontToBack = True
{'fraction_non_alphanumeric': 0.14056420233463035, 'fraction_numerical': 0.023508430609597925, 'mean_word_length': 3.596870342771982, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7023648', 'n_tokens_mistral': 2595, 'n_tokens_neox': 2231, 'n_words': 521}