<commit_before>from .shape import Shape
from .shape import Pane

from .stroke_info import StrokeInfoFactory

strokeInfoFactory=StrokeInfoFactory()

class Stroke(Shape):
	def __init__(self, startPoint, strokeInfo, statePane=None):
		self.startPoint=startPoint
		self.strokeInfo=strokeInfo

		strokePath=strokeInfo.getStrokePath()
		boundary=strokePath.computeBoundaryWithStartPoint(startPoint)

		self.infoPane = Pane(*boundary)
		if statePane:
			self.statePane=statePane
		else:
			self.statePane=self.infoPane

	def getStartPoint(self):
		return self.startPoint

	def getStrokeInfo(self):
		return self.strokeInfo

	def getName(self):
		return self.getStrokeInfo().getName()

	def getStrokePath(self):
		return self.getStrokeInfo().getStrokePath()

	def getInfoPane(self):
		return self.infoPane

	def getStatePane(self):
		return self.statePane

	def draw(self, drawingSystem):
		startPoint = self.getStartPoint()

		stroke=self
		drawingSystem.onPreDrawStroke(stroke)
		drawingSystem.setPane(stroke.getInfoPane(), stroke.getStatePane())

		drawingSystem.startDrawing(startPoint)
		drawingSystem.draw(stroke.getStrokePath())
		drawingSystem.endDrawing()
		drawingSystem.onPostDrawStroke(stroke)

	def computeBoundary(self):
		startPoint=self.getStartPoint()
		strokePath=self.getStrokePath()
		return strokePath.computeBoundaryWithStartPoint(startPoint)

	def generateCopyToApplyNewPane(self, sgTargetPane, newSgTargetPane):
		sTargetPane=self.getStatePane()
		newSTargetPane=sgTargetPane.transformRelativePaneByTargetPane(sTargetPane, newSgTargetPane)

		strokeCopy=Stroke(self.startPoint, self.strokeInfo, newSTargetPane)
		return strokeCopy

def generateStroke(name, startPoint, parameterList):
	strokeInfo = strokeInfoFactory.generateStrokeInfo(name, parameterList)
	return Stroke(startPoint, strokeInfo)

class StrokeGroupInfo:
	def __init__(self, strokeList, statePane=None):
		self.strokeList=strokeList

		if not statePane:
			def mergeBoundaryList(boundaryList):
				from xie.graphics.shape import mergeBoundary
				r = boundaryList[0]
				for b in boundaryList[1:]:
					r = mergeBoundary(r, b)
				return r

			boundaryList=[stroke.computeBoundary() for stroke in strokeList]
			bBox=mergeBoundaryList(boundaryList)
			statePane=Pane(*bBox)

		self.statePane=statePane

	def getStrokeList(self):
		return self.strokeList

	def getStatePane(self):
		return self.statePane

	@classmethod
	def generateInstance(cls, strokeList, pane=None):
		return StrokeGroupInfo(strokeList, pane)

class StrokeGroup(Shape):
	def __init__(self, strokeGroupInfo, infoPane):
		self.strokeGroupInfo=strokeGroupInfo

		self.infoPane=infoPane
		self.statePane=infoPane

	def getInfoPane(self):
		return self.infoPane

	def getStrokeList(self):
		return self.strokeGroupInfo.getStrokeList()

	def getCount(self):
		return len(self.getStrokeList())

	def draw(self, drawingSystem):
		strokeList = self.getStrokeList();

		for stroke in strokeList:
			stroke.draw(drawingSystem)

	@classmethod
	def generateInstanceByInfo(cls, strokeGroupInfo, infoPane=None):
		if not infoPane:
			infoPane=strokeGroupInfo.getStatePane()
		return StrokeGroup(strokeGroupInfo, infoPane)

	@classmethod
	def generateInstanceByStrokeList(cls, strokeList, pane=None):
		strokeGroupInfo=StrokeGroupInfo.generateInstance(strokeList, pane)
		return StrokeGroup.generateInstanceByInfo(strokeGroupInfo)

	@classmethod
	def generateInstanceByStrokeGroupPane(cls, sg, pane):
		newSgTargetPane=pane
		sgInfoPane=sg.getInfoPane()

		strokeList=[s.generateCopyToApplyNewPane(sgInfoPane, newSgTargetPane) for s in sg.getStrokeList()]

		strokeGroupInfo=StrokeGroupInfo.generateInstance(strokeList)

		infoPane=newSgTargetPane
		strokeGroup=StrokeGroup.generateInstanceByInfo(strokeGroupInfo, infoPane)

		return strokeGroup

	@classmethod
	def generateInstanceByStrokeGroupPanePairList(cls, strokeGroupPanePairList):
		def computeBBox(paneList):
			left=min(map(lambda pane: pane.getLeft(), paneList))
			top=min(map(lambda pane: pane.getTop(), paneList))
			right=max(map(lambda pane: pane.getRight(), paneList))
			bottom=max(map(lambda pane: pane.getBottom(), paneList))
			return Pane(left, top, right, bottom)

		resultStrokeList=[]
		paneList=[]
		for strokeGroup, pane in strokeGroupPanePairList:
			strokeGroup=StrokeGroup.generateInstanceByStrokeGroupPane(strokeGroup, pane)
			resultStrokeList.extend(strokeGroup.getStrokeList())
			paneList.append(strokeGroup.getInfoPane())

		pane=computeBBox(paneList)
		strokeGroupInfo=StrokeGroupInfo.generateInstance(resultStrokeList, pane)
		strokeGroup=StrokeGroup.generateInstanceByInfo(strokeGroupInfo)

		return strokeGroup

class Character(Shape):
	def __init__(self, name, strokeGroup, tag=None):
		self.name = name
		self.strokeGroup = strokeGroup
		self.tag = tag

	def getName(self):
		return self.name

	def getStrokeGroup(self):
		return self.strokeGroup

	def getTag(self):
		return self.tag

	def draw(self, drawingSystem):<commit_msg>Refactoring. StrokeGroupInfo.generateInstance() by removing the parameter, pane.<commit_after>from .shape import Shape
from .shape import Pane

from .stroke_info import StrokeInfoFactory

strokeInfoFactory=StrokeInfoFactory()

class Stroke(Shape):
	def __init__(self, startPoint, strokeInfo, statePane=None):
		self.startPoint=startPoint
		self.strokeInfo=strokeInfo

		strokePath=strokeInfo.getStrokePath()
		boundary=strokePath.computeBoundaryWithStartPoint(startPoint)

		self.infoPane = Pane(*boundary)
		if statePane:
			self.statePane=statePane
		else:
			self.statePane=self.infoPane

	def getStartPoint(self):
		return self.startPoint

	def getStrokeInfo(self):
		return self.strokeInfo

	def getName(self):
		return self.getStrokeInfo().getName()

	def getStrokePath(self):
		return self.getStrokeInfo().getStrokePath()

	def getInfoPane(self):
		return self.infoPane

	def getStatePane(self):
		return self.statePane

	def draw(self, drawingSystem):
		startPoint = self.getStartPoint()

		stroke=self
		drawingSystem.onPreDrawStroke(stroke)
		drawingSystem.setPane(stroke.getInfoPane(), stroke.getStatePane())

		drawingSystem.startDrawing(startPoint)
		drawingSystem.draw(stroke.getStrokePath())
		drawingSystem.endDrawing()
		drawingSystem.onPostDrawStroke(stroke)

	def computeBoundary(self):
		startPoint=self.getStartPoint()
		strokePath=self.getStrokePath()
		return strokePath.computeBoundaryWithStartPoint(startPoint)

	def generateCopyToApplyNewPane(self, sgTargetPane, newSgTargetPane):
		sTargetPane=self.getStatePane()
		newSTargetPane=sgTargetPane.transformRelativePaneByTargetPane(sTargetPane, newSgTargetPane)

		strokeCopy=Stroke(self.startPoint, self.strokeInfo, newSTargetPane)
		return strokeCopy

def generateStroke(name, startPoint, parameterList):
	strokeInfo = strokeInfoFactory.generateStrokeInfo(name, parameterList)
	return Stroke(startPoint, strokeInfo)

class StrokeGroupInfo:
	def __init__(self, strokeList, statePane=None):
		self.strokeList=strokeList

		if not statePane:
			def mergeBoundaryList(boundaryList):
				from xie.graphics.shape import mergeBoundary
				r = boundaryList[0]
				for b in boundaryList[1:]:
					r = mergeBoundary(r, b)
				return r

			boundaryList=[stroke.computeBoundary() for stroke in strokeList]
			bBox=mergeBoundaryList(boundaryList)
			statePane=Pane(*bBox)

		self.statePane=statePane

	def getStrokeList(self):
		return self.strokeList

	def getStatePane(self):
		return self.statePane

	@classmethod
	def generateInstance(cls, strokeList, pane=None):
		return StrokeGroupInfo(strokeList, pane)

class StrokeGroup(Shape):
	def __init__(self, strokeGroupInfo, infoPane):
		self.strokeGroupInfo=strokeGroupInfo

		self.infoPane=infoPane
		self.statePane=infoPane

	def getInfoPane(self):
		return self.infoPane

	def getStrokeList(self):
		return self.strokeGroupInfo.getStrokeList()

	def getCount(self):
		return len(self.getStrokeList())

	def draw(self, drawingSystem):
		strokeList = self.getStrokeList();

		for stroke in strokeList:
			stroke.draw(drawingSystem)

	@classmethod
	def generateInstanceByInfo(cls, strokeGroupInfo, infoPane=None):
		if not infoPane:
			infoPane=strokeGroupInfo.getStatePane()
		return StrokeGroup(strokeGroupInfo, infoPane)

	@classmethod
	def generateInstanceByStrokeList(cls, strokeList, pane=None):
		strokeGroupInfo=StrokeGroupInfo.generateInstance(strokeList)
		return StrokeGroup.generateInstanceByInfo(strokeGroupInfo, pane)

	@classmethod
	def generateInstanceByStrokeGroupPane(cls, sg, pane):
		newSgTargetPane=pane
		sgInfoPane=sg.getInfoPane()

		strokeList=[s.generateCopyToApplyNewPane(sgInfoPane, newSgTargetPane) for s in sg.getStrokeList()]

		strokeGroupInfo=StrokeGroupInfo.generateInstance(strokeList)

		infoPane=newSgTargetPane
		strokeGroup=StrokeGroup.generateInstanceByInfo(strokeGroupInfo, infoPane)

		return strokeGroup

	@classmethod
	def generateInstanceByStrokeGroupPanePairList(cls, strokeGroupPanePairList):
		def computeBBox(paneList):
			left=min(map(lambda pane: pane.getLeft(), paneList))
			top=min(map(lambda pane: pane.getTop(), paneList))
			right=max(map(lambda pane: pane.getRight(), paneList))
			bottom=max(map(lambda pane: pane.getBottom(), paneList))
			return Pane(left, top, right, bottom)

		resultStrokeList=[]
		paneList=[]
		for strokeGroup, pane in strokeGroupPanePairList:
			strokeGroup=StrokeGroup.generateInstanceByStrokeGroupPane(strokeGroup, pane)
			resultStrokeList.extend(strokeGroup.getStrokeList())
			paneList.append(strokeGroup.getInfoPane())

		pane=computeBBox(paneList)
		strokeGroupInfo=StrokeGroupInfo.generateInstance(resultStrokeList)
		strokeGroup=StrokeGroup.generateInstanceByInfo(strokeGroupInfo, pane)

		return strokeGroup

class Character(Shape):
	def __init__(self, name, strokeGroup, tag=None):
		self.name = name
		self.strokeGroup = strokeGroup
		self.tag = tag

	def getName(self):
		return self.name

	def getStrokeGroup(self):
		return self.strokeGroup

	def getTag(self):
		return self.tag

	def draw(self, drawingSystem):
{'fraction_non_alphanumeric': 0.0907906603868123, 'fraction_numerical': 0.0004008417677121956, 'mean_word_length': 6.4812593703148424, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '624645', 'n_tokens_mistral': 3489, 'n_tokens_neox': 3119, 'n_words': 585}