我是Swift的新手,并尝试编写一个用于矢量计算的litte命令行工具。当我运行它时,程序被中断并显示绿线。我试过了,但无法摆脱它。你有什么想法? mormod
func isLineParallelTo(l: Line) -> Bool{
if(self.directionVector.isLinearlyDependentTo(v: l.directionVector)){
let pointToTest = Point(name: "p", x: l.positionVector.x, y: l.positionVector.y, z: l.positionVector.z)
//println("\(pointToTest.displayPoint())")
println("\(self.isPointOnLine(pointToTest))") //says false
let b:Bool = self.isPointOnLine(pointToTest)
if(b){ //Thread 1: breakpoint 1.1
return false
}
else{
return true
}
}
else{
return false
}
}
整个代码(行)
import Foundation
class Line {
let name: String
let positionVector: Vector
let directionVector: Vector
func isPointOnLine(p: Point) -> Bool{
let pv = Vector(name: "pv", x: p.x, y: p.y, z: p.z)
let pvMinusPosition = Vector(name: "pvMinusPosition", x: pv.x-self.positionVector.x, y: pv.y-self.positionVector.y, z: pv.z-self.positionVector.z)
if(pvMinusPosition.isLinearlyDependentTo(v: directionVector)){
return true
}
else{
return false;
}
}
//TODO: are lines parallel?
func isLineParallelTo(l: Line) -> Bool{
if(self.directionVector.isLinearlyDependentTo(v: l.directionVector)){
let pointToTest = Point(name: "p", x: l.positionVector.x, y: l.positionVector.y, z: l.positionVector.z)
println("\(pointToTest.displayPoint())")
println("\(self.isPointOnLine(pointToTest))")
let b:Bool = self.isPointOnLine(pointToTest)
if(b){
return false
}
else{
return true
}
}
else{
return false
}
}
//TODO: are lines equal?
//TODO: are lines 'windschief'?
init(name: String, position positionVector: Vector, direction directionVector: Vector){
self.name = name;
self.positionVector = positionVector;
self.directionVector = directionVector;
}
}