Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 修复Swift simd库中的错误(以及缺少的文档?)_Ios_Swift_Sprite Kit_Scenekit_Simd - Fatal编程技术网

Ios 修复Swift simd库中的错误(以及缺少的文档?)

Ios 修复Swift simd库中的错误(以及缺少的文档?),ios,swift,sprite-kit,scenekit,simd,Ios,Swift,Sprite Kit,Scenekit,Simd,我下载了苹果的“”项目,试图了解更多关于GameplayKit,但有一个错误阻止了它的编译。它位于一个似乎使用simd库的扩展中。我做了一些关于SIMD的研究,我可以告诉你,作为一个新手,这些东西我是不懂的。但是我只是想让这段代码正常工作,这样我就可以演示这个项目了 错误是由以下代码中的此行引起的: 让fractionOfComponent=max(0,min(1,ComponentSegment)) 错误消息是: 传递给不带参数的调用的参数 有人能告诉我如何修复这个错误吗 另外,在哪里可以找到

我下载了苹果的“”项目,试图了解更多关于
GameplayKit
,但有一个错误阻止了它的编译。它位于一个似乎使用
simd
库的扩展中。我做了一些关于SIMD的研究,我可以告诉你,作为一个新手,这些东西我是不懂的。但是我只是想让这段代码正常工作,这样我就可以演示这个项目了

错误是由以下代码中的此行引起的:

让fractionOfComponent=max(0,min(1,ComponentSegment))

错误消息是:

传递给不带参数的调用的参数

有人能告诉我如何修复这个错误吗

另外,在哪里可以找到
simd
库的文档?我搜索了一下,但是
simd
库中似乎什么都没有。在没有获得计算机科学学位的情况下,我如何学习如何使用该库中的API

import CoreGraphics
import simd

// Omitting the other extensions here

// Extend `float2` to provide a convenience method for working with pathfinding graphs.
extension float2 {
    /// Calculates the nearest point to this point on a line from `pointA` to `pointB`.
    func nearestPointOnLineSegment(lineSegment: (startPoint: float2, endPoint: float2)) -> float2 {
        // A vector from this point to the line start.
        let vectorFromStartToLine = self - lineSegment.startPoint

        // The vector that represents the line segment.
        let lineSegmentVector = lineSegment.endPoint - lineSegment.startPoint

        // The length of the line squared.
        let lineLengthSquared = distance_squared(lineSegment.startPoint, lineSegment.endPoint)

        // The amount of the vector from this point that lies along the line.
        let projectionAlongSegment = dot(vectorFromStartToLine, lineSegmentVector)

        // Component of the vector from the point that lies along the line.
        let componentInSegment = projectionAlongSegment / lineLengthSquared

        // Clamps the component between [0 - 1].
        let fractionOfComponent = max(0, min(1, componentInSegment))

        return lineSegment.startPoint + lineSegmentVector * fractionOfComponent
    }
}
更新: 多亏了giorashc的回答,我用以下内容替换了有问题的行,从而修复了错误:

let componentMin = Swift.min(1, componentInSegment)
let fractionOfComponent = Swift.max(0, componentMin)

然而,我仍然希望为Swift的
simd
库找到一个好的文档资源(特别是新手可以理解的文档资源)。如果有人知道这样一个资源,那就太棒了。

float2
已经有了一个不带参数的
min
方法。(当您选择在Xcode中转到方法的定义时,会对这些方法进行解释)


尝试使用
Swift.min
显式调用Swift的实现

Compare。谢谢,这很有效!我可以通过以下内容替换有问题的行来修复错误:
let componentMin=Swift.min(1,componentsegment)
let fractionOfComponent=Swift.max(0,componentMin)