Go方法参数和float64数组出现意外错误

Go方法参数和float64数组出现意外错误,go,Go,编译以下代码时 package camera type camera struct { position [3]float64 viewWidth int viewHeight int } func (c camera) SwitchToCartesianThreeSpace(x, y int) [3]float64 { // LINE 9 var x3 float64 = 0 // view is set to the origin var y3 f

编译以下代码时

package camera

type camera struct {
    position [3]float64
    viewWidth int
    viewHeight int
}

func (c camera) SwitchToCartesianThreeSpace(x, y int) [3]float64 { // LINE 9
    var x3 float64 = 0 // view is set to the origin
    var y3 float64 = float64(x) - (float64(c.viewWidth) / 2)
    var z3 float64 = float64(-y) + (float64(c.viewHeight) / 2)
    result := [3]float64{x3, y3, z3}                               // LINE 13
    return result
}
…出现以下错误

camera/camera.go:9: undefined: x
camera/camera.go:9: undefined: y
camera/camera.go:11: undefined: x
camera/camera.go:12: undefined: y
camera/camera.go:13: cannot use x3 (type float64) as type [3]float64 in array element
camera/camera.go:13: cannot use y3 (type float64) as type [3]float64 in array element
camera/camera.go:13: cannot use z3 (type float64) as type [3]float64 in array element
到目前为止,我已经写了相当多的Go代码,不明白为什么第9行或第13行出现错误!有人能解释吗?

它编译得很好,具有预期的输出:

c := camera{}
res := c.SwitchToCartesianThreeSpace(2, 3)
// res is [0 2 -3]

您需要尝试使用
camera.go
只包含该代码,或者检查
camera.go
文件如何适合您的应用程序。

但是,这个()编译很好…非常奇怪。包结构似乎有问题。。。谢谢你确认我的理智。