<commit_before>from ed2d.physics import gjk
from ed2d.glmath import vector

class SimplexVerts(object):
	def __init__(self):
		self.p1 = vector.Vector(2)
		self.p2 = vector.Vector(2)
		self.p = vector.Vector(2)
		self.u = 1
		self.index1 = 0
		self.index2 = 0

	def copy(self, v):
		self.p1 = v.p1
		self.p2 = v.p2
		self.p = v.p
		self.u = v.u
		self.index1 = v.index1
		self.index2 = v.index2

class Simplex(object):
	def __init__(self):
		self.verts = [SimplexVerts(), SimplexVerts(), SimplexVerts()]
		self.count = 0
		self.divisor = 1

	def __getitem__(self, key):
		return self.verts[key]

	def getCount(Self):
		return len(verts)

	def copy(self, v):
		self.verts = v.verts
		self.count = v.count
		self.divisor = v.divisor

	def getSearchPosition(self):
		pass

class Edge(object):
	def __init__(self, index1, index2):
		self.index1 = index1
		self.index2 = index2
		self.next = Edge()
		self.prev = Edge()

class Polytope(object):
	def __init__(self, simplex):
		self.verts = []
		
		for i in range(simplex.count()):
			self.verts[i] = SimplexVerts()
			self.verts[i].copy(simplex.vertices[i])

		self.edgeHead = None
		self.edgeTail = None

		if (simplex.count() is 2):
			self.insertEdge(self.edgeTail, Edge(0, 1))
			self.insertEdge(self.edgeTail, Edge(1, 0))
		elif (simplex.count() is 3):
			a = simplex.vertices[0].p
			b = simplex.vertices[1].p
			c = simplex.vertices[2].p

			ab = b - a
			bc = c - b

			if ab.cross(bc) > 0:
				self.insertEdge(self.edgeTail, Edge(0, 1))
				self.insertEdge(self.edgeTail, Edge(1, 2))
				self.insertEdge(self.edgeTail, Edge(2, 0))
			else:
				self.insertEdge(self.edgeTail, Edge(0, 2))
				self.insertEdge(self.edgeTail, Edge(2, 1))
				self.insertEdge(self.edgeTail, Edge(1, 0))

	def insertEdge(self, prevEdge, newEdge):
		if self.edgeHead is None:
			self.edgeHead = newEdge
			self.edgeHead = newEdge
		else:
			newEdge.prev = prevEdge
			newEdge.next = prevEdge.next
			newEdge.next.prev = newEdge
			newEdge.next = newEdge

			if prevEdge == self.edgeTail:
				self.EdgeTail = newEdge

	def deleteEdge(self, edge):
		if edge == self.edgeHead:
			self.edgeHead = edge.next

	def getClosestEdge(self):
		pass

class EPA(object):
	def __init__(self, poly1, xf1, poly2, xf2, simplex):
		self.poly1 = poly1
		self.poly2 = poly2
		self.xf1 = xf1
		self.xf2 = xf2
		self.simplex = simplex
		self.polytope = genPolytope(self.simplex)

		self.edgeHistory = []
		self.closestEdge = 0
		self.v = self.polytope.verts

		self.save1 = []<commit_msg>More progress on the EPA, adding in the missing functions.<commit_after>from ed2d.physics import gjk
from ed2d.glmath import vector

class SimplexVerts(object):
	def __init__(self):
		self.p1 = vector.Vector(2)
		self.p2 = vector.Vector(2)
		self.p = vector.Vector(2)
		self.u = 1
		self.index1 = 0
		self.index2 = 0

	def copy(self, v):
		self.p1 = v.p1
		self.p2 = v.p2
		self.p = v.p
		self.u = v.u
		self.index1 = v.index1
		self.index2 = v.index2

class Simplex(object):
	def __init__(self):
		self.verts = [SimplexVerts(), SimplexVerts(), SimplexVerts()]
		self.count = 0
		self.divisor = 1

	def __getitem__(self, key):
		return self.verts[key]

	def getCount(Self):
		return len(verts)

	def copy(self, v):
		self.verts = v.verts
		self.count = v.count
		self.divisor = v.divisor

	def getSearchPosition(self):
		if self.count is 1:
			return -self.verts[0].p

		if self.count is 2:
			ab = self.verts[1].p - self.verts[0].p
			sgn = vector.cross(self.verts[0].p, ab)

			if sgn > 0:
				return vector.lperp(ab)
			else:
				return vector.rperp(ab)

		return self.Vector(2)

	def getClosestPoint(self):
		if self.count is 1:
			return self.verts[0].p 

		if self.count is 2:
			return vector.lerp(self.verts[0].p , self.verts[1].p, self.verts[1].u / self.divisor)

		if self.count is 3:
			s = 1 / self.verts[0].p
			p = self.verts[0].p * (self.verts[0].u * s)
			p += self.verts[1].p * (self.verts[1].u * s)
			p += self.verts[2].p * (self.verts[2].u * s)
			return p

		return self.Vector(2)

class Edge(object):
	def __init__(self, index1, index2):
		self.index1 = index1
		self.index2 = index2
		self.next = Edge()
		self.prev = Edge()

class Polytope(object):
	def __init__(self, simplex):
		self.verts = []
		
		for i in range(simplex.count()):
			self.verts[i] = SimplexVerts()
			self.verts[i].copy(simplex.vertices[i])

		self.edgeHead = None
		self.edgeTail = None

		if (simplex.count() is 2):
			self.insertEdge(self.edgeTail, Edge(0, 1))
			self.insertEdge(self.edgeTail, Edge(1, 0))
		elif (simplex.count() is 3):
			a = simplex.vertices[0].p
			b = simplex.vertices[1].p
			c = simplex.vertices[2].p

			ab = b - a
			bc = c - b

			if ab.cross(bc) > 0:
				self.insertEdge(self.edgeTail, Edge(0, 1))
				self.insertEdge(self.edgeTail, Edge(1, 2))
				self.insertEdge(self.edgeTail, Edge(2, 0))
			else:
				self.insertEdge(self.edgeTail, Edge(0, 2))
				self.insertEdge(self.edgeTail, Edge(2, 1))
				self.insertEdge(self.edgeTail, Edge(1, 0))

	def insertEdge(self, prevEdge, newEdge):
		if self.edgeHead is None:
			self.edgeHead = newEdge
			self.edgeHead = newEdge
		else:
			newEdge.prev = prevEdge
			newEdge.next = prevEdge.next
			newEdge.next.prev = newEdge
			newEdge.next = newEdge

			if prevEdge == self.edgeTail:
				self.EdgeTail = newEdge

	def deleteEdge(self, edge):
		if edge is self.edgeHead:
			self.edgeHead = edge.next

		if edge is self.edgeTail:
			self.edgeTail = edge.prev

		edge.prev.next = edge.next
		edge.next.prev = edge.prev

	def getClosestEdge(self):
		firstEdge = self.edgeHead

		if (firstEdge.distsq is None):
			a = self.verts[firstEdge.index1].p
			b = self.verts[firstEdge.index2].p
			ab = b - a

			v = -ab.dot(a)

			if v <= 0:
				cp = vector.Vector(2, data = [a.x , a.y])
				firstEdge.distsq = cp.lengthsq()
				firstEdge.dir = cp
			else:
				u = ab.dot(b)
				if u <= 0:
					cp = vector.Vector(2, data = [b.x , b.y])
					firstEdge.distsq = cp.lengthsq()
					firstEdge.dir = cp
				else:
					s = 1 / ab.lengthsq()
					vp = vector.lerp(a , b, v * s)
					firstEdge.distsq = cp.lengthsq()
					firstEdge.dir = vector.rperp(ab)

		closestEdge = firstEdge

		

class EPA(object):
	def __init__(self, poly1, xf1, poly2, xf2, simplex):
		#xf1 is the center of polygon 1 and xf2 is the center of the polygon 2
		self.poly1 = poly1
		self.poly2 = poly2
		self.xf1 = xf1
		self.xf2 = xf2
		self.simplex = simplex
		self.polytope = genPolytope(self.simplex)

		self.edgeHistory = []
		self.closestEdge = 0
		self.v = self.polytope.verts

		self.save1 = []
{'fraction_non_alphanumeric': 0.140819144040497, 'fraction_numerical': 0.025003834944009817, 'mean_word_length': 3.0246913580246915, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '6675602', 'n_tokens_mistral': 3017, 'n_tokens_neox': 2586, 'n_words': 587}