# Path: geosolver/matfunc.py
# class Vec(Table):
#     def dot( self, otherVec ):  return reduce(operator.add, map(operator.mul, self, otherVec), 0.0)
#     def norm( self ):  return math.sqrt(abs( self.dot(self.conjugate()) ))
#     def normSquared( self ):  return abs( self.dot(self.conjugate()) )
#     def normalize( self ):  return self / self.norm()
#     def outer( self, otherVec ):  return Mat([otherVec*x for x in self])
#     def cross( self, otherVec ):
#         'Compute a Vector or Cross Product with another vector'
#         assert len(self) == len(otherVec) == 3, 'Cross product only defined for 3-D vectors'
#         u, v = self, otherVec
#         return Vec([ u[1]*v[2]-u[2]*v[1], u[2]*v[0]-u[0]*v[2], u[0]*v[1]-u[1]*v[0] ])
#     def house( self, index ):
#         'Compute a Householder vector which zeroes all but the index element after a reflection'
#         v = Vec( Table([0]*index).concat(self[index:]) ).normalize()
#         t = v[index]
#         sigma = 1.0 - t**2
#         if sigma != 0.0:
#             t = v[index] = t<=0 and t-1.0 or -sigma / (t + 1.0)
#             v /= t
#         return v, 2.0 * t**2 / (sigma + t**2)
#     def polyval( self, x ):
#         'Vec([6,3,4]).polyval(5) evaluates to 6*x**2 + 3*x + 4 at x=5'
#         return reduce( lambda cum,c: cum*x+c, self, 0.0 )
#     def ratval( self, x ):
#         'Vec([10,20,30,40,50]).ratfit(5) evaluates to (10*x**2 + 20*x + 30) / (40*x**2 + 50*x + 1) at x=5.'
#         degree = len(self) / 2
#         num, den = self[:degree+1], self[degree+1:] + [1]
#         return num.polyval(x) / den.polyval(x)


from includes import *
from camera import *
from cameraHandler import *
from prototypeObjects import *
from sceneObjects import *
from parameters import Settings
from geosolver.matfunc import Vec
	from OpenGL.GL import *
	from OpenGL.GLU import *
import viewport
		glPushMatrix()
		glLoadIdentity()
		glEnable(GL_COLOR_MATERIAL)
	
	def endOverlay(self):
		glMatrixMode(GL_PROJECTION)
		glPopMatrix()

		glMatrixMode(GL_MODELVIEW)
		glPopMatrix()

	def drawGrid(self):
		if self.viewportType == ViewportType.PERSPECTIVE or self.viewportType == ViewportType.SOLUTION:
			self.sceneObjects.drawBackgroundgrid3D(600, 600, self.settings.sketcherData.gridWidth, self.settings.sketcherData.gridHeight, self.gridColor, False)
		else:
			self.sceneObjects.drawBackgroundgrid2D(self.settings.sketcherData.gridWidth, self.settings.sketcherData.gridHeight, self.gridColor, False)

	def drawSelection(self):
		if self.currentTool != None and self.currentTool.multipleSelect and self.currentTool.selectionStarted:
			self.sceneObjects.drawSelection(self.currentTool.beginSelPoint.x(), self.currentTool.beginSelPoint.y(), self.currentTool.endSelPoint.x(), self.currentTool.endSelPoint.y())
			"""glPushMatrix()
			glDisable(GL_LIGHTING)
			glRectf(self.currentTool.beginSelPoint.x(), self.currentTool.beginSelPoint.y(), self.currentTool.endSelPoint.x(), self.currentTool.endSelPoint.y())
			glEnable(GL_LIGHTING)
			glPopMatrix() """
	
	def drawViewportAxis(self):	
		glPushMatrix()	
		#glScalef(self.scaleAxis,self.scaleAxis,1.0)
		glTranslatef(20.0, self.camera.getWindowHeight()-40.0, -50.0)

# Path: geosolver/matfunc.py
# class Vec(Table):
#     def dot( self, otherVec ):  return reduce(operator.add, map(operator.mul, self, otherVec), 0.0)
#     def norm( self ):  return math.sqrt(abs( self.dot(self.conjugate()) ))
#     def normSquared( self ):  return abs( self.dot(self.conjugate()) )
#     def normalize( self ):  return self / self.norm()
#     def outer( self, otherVec ):  return Mat([otherVec*x for x in self])
#     def cross( self, otherVec ):
#         'Compute a Vector or Cross Product with another vector'
#         assert len(self) == len(otherVec) == 3, 'Cross product only defined for 3-D vectors'
#         u, v = self, otherVec
#         return Vec([ u[1]*v[2]-u[2]*v[1], u[2]*v[0]-u[0]*v[2], u[0]*v[1]-u[1]*v[0] ])
#     def house( self, index ):
#         'Compute a Householder vector which zeroes all but the index element after a reflection'
#         v = Vec( Table([0]*index).concat(self[index:]) ).normalize()
#         t = v[index]
#         sigma = 1.0 - t**2
#         if sigma != 0.0:
#             t = v[index] = t<=0 and t-1.0 or -sigma / (t + 1.0)
#             v /= t
#         return v, 2.0 * t**2 / (sigma + t**2)
#     def polyval( self, x ):
#         'Vec([6,3,4]).polyval(5) evaluates to 6*x**2 + 3*x + 4 at x=5'
#         return reduce( lambda cum,c: cum*x+c, self, 0.0 )
#     def ratval( self, x ):
#         'Vec([10,20,30,40,50]).ratfit(5) evaluates to (10*x**2 + 20*x + 30) / (40*x**2 + 50*x + 1) at x=5.'
#         degree = len(self) / 2
#         num, den = self[:degree+1], self[degree+1:] + [1]
#         return num.polyval(x) / den.polyval(x)


# Path: workbench/glViewer.py
from includes import *
from camera import *
from cameraHandler import *
from prototypeObjects import *
from sceneObjects import *
from parameters import Settings
from geosolver.matfunc import Vec
	from OpenGL.GL import *
	from OpenGL.GLU import *
import viewport

		glPushMatrix()
		glLoadIdentity()
		glEnable(GL_COLOR_MATERIAL)
	
	def endOverlay(self):
		glMatrixMode(GL_PROJECTION)
		glPopMatrix()

		glMatrixMode(GL_MODELVIEW)
		glPopMatrix()

	def drawGrid(self):
		if self.viewportType == ViewportType.PERSPECTIVE or self.viewportType == ViewportType.SOLUTION:
			self.sceneObjects.drawBackgroundgrid3D(600, 600, self.settings.sketcherData.gridWidth, self.settings.sketcherData.gridHeight, self.gridColor, False)
		else:
			self.sceneObjects.drawBackgroundgrid2D(self.settings.sketcherData.gridWidth, self.settings.sketcherData.gridHeight, self.gridColor, False)

	def drawSelection(self):
		if self.currentTool != None and self.currentTool.multipleSelect and self.currentTool.selectionStarted:
			self.sceneObjects.drawSelection(self.currentTool.beginSelPoint.x(), self.currentTool.beginSelPoint.y(), self.currentTool.endSelPoint.x(), self.currentTool.endSelPoint.y())
			"""glPushMatrix()
			glDisable(GL_LIGHTING)
			glRectf(self.currentTool.beginSelPoint.x(), self.currentTool.beginSelPoint.y(), self.currentTool.endSelPoint.x(), self.currentTool.endSelPoint.y())
			glEnable(GL_LIGHTING)
			glPopMatrix() """
	
	def drawViewportAxis(self):	
		glPushMatrix()	
		#glScalef(self.scaleAxis,self.scaleAxis,1.0)
		glTranslatef(20.0, self.camera.getWindowHeight()-40.0, -50.0)

		rotAxis = Vec([0.0,0.0,0.0])