好的,
這里有一個心理障礙......我有一系列向量
node 0 SCNVector3(x: 8.208711e-08, y: 0.0, z: -1.9389672)
node 1 SCNVector3(x: -0.93896717, y: 0.0, z: -1.0000001)
node 2 SCNVector3(x: -8.208711e-08, y: 0.0, z: -0.06103283)
node 3 SCNVector3(x: 0.93896717, y: 0.0, z: -0.99999994)
node 4 SCNVector3(x: 0.0, y: 0.93896717, z: -1.0)
node 5 SCNVector3(x: 0.0, y: -0.93896717, z: -1.0)
我想選擇 node2 因為它的負數最小。這是一個愚蠢的問題,我知道;對不起。
struct Sats {
var theNode = SCNNode()
var theIndex:Int = 7
}
if cubeNode != nil {
cubeNode.enumerateChildNodes { (node, stop) in
let search = /face(\d )/
if let result = try? search.wholeMatch(in: node.name!) {
print("node \(result.1) \(node.worldPosition) ")
if node.worldPosition.z < -0.05 {
print("eureka \(theOne.theIndex)")
theOne.theNode = node
theOne.theIndex = Int(result.1)!
}
}
}
}
uj5u.com熱心網友回復:
如果所有物件都在一個陣列中,則可以使用min(by:)
. 像許多 Swift 的排序方法一樣,它需要一個帶有兩個值的塊,如果第二個值大于第一個值,則回傳 TRUE:
myVectors.min { $0.x < $1.x }
回傳的值是可選的——它要么是陣列中的最小值,要么nil
是陣列為空。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/529557.html
標籤:迅速
上一篇:如何使SwiftUI按鈕標簽大寫
下一篇:系結值只更改一次