# 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 singleton import *
from prototypeObjects import *
from geosolver.matfunc import Vec
                dcName = "l" + str(self.prototypeManager.objectNr)
                newDistance = Distance(dcName,self.pointBegin, self.pointEnd)            
                self.prototypeManager.addObject(newDistance)
                self.pointBegin = self.pointEnd
                self.pointEnd = None
                self.removeGhosts()
            
            self.createGhosts(self.pointBegin)
            self.needUpdate = True
            
        elif mouseEvent.buttons() == QtCore.Qt.RightButton:
            self.needUpdate = True
            self.removeGhosts()
            self.pointBegin.selected = False
            self.pointEnd = None
            self.pointBegin = None
        else:
            self.prototypeManager.objectSelected.selected = False

    def createPoint(self, viewPortType, camera, mouseEvent):    
        createPoint = PlacePointTool()
        createPoint.handleMousePress(mouseEvent, camera, viewPortType, -1)
        if createPoint.newPoint != None:
            if self.pointBegin == None:
                self.pointBegin = createPoint.newPoint
            elif self.pointEnd == None:
                self.pointEnd = createPoint.newPoint
    
    def createGhosts(self, point):
        pName = "p" + str(self.prototypeManager.objectNr)

# 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/tools.py
from includes import *
from singleton import *
from prototypeObjects import *
from geosolver.matfunc import Vec

                dcName = "l" + str(self.prototypeManager.objectNr)
                newDistance = Distance(dcName,self.pointBegin, self.pointEnd)            
                self.prototypeManager.addObject(newDistance)
                self.pointBegin = self.pointEnd
                self.pointEnd = None
                self.removeGhosts()
            
            self.createGhosts(self.pointBegin)
            self.needUpdate = True
            
        elif mouseEvent.buttons() == QtCore.Qt.RightButton:
            self.needUpdate = True
            self.removeGhosts()
            self.pointBegin.selected = False
            self.pointEnd = None
            self.pointBegin = None
        else:
            self.prototypeManager.objectSelected.selected = False

    def createPoint(self, viewPortType, camera, mouseEvent):    
        createPoint = PlacePointTool()
        createPoint.handleMousePress(mouseEvent, camera, viewPortType, -1)
        if createPoint.newPoint != None:
            if self.pointBegin == None:
                self.pointBegin = createPoint.newPoint
            elif self.pointEnd == None:
                self.pointEnd = createPoint.newPoint
    
    def createGhosts(self, point):
        pName = "p" + str(self.prototypeManager.objectNr)

        self.ghostPoint = Point(pName, Vec([point.position[0], point.position[1], point.position[2]]), 5.0)