gpt4 book ai didi

Swift - 让常数值消失并进入下一行

转载 作者:行者123 更新时间:2023-11-30 12:27:44 24 4
gpt4 key购买 nike

我正在尝试将天气雷达图像叠加到 map 上。我获取图像及其世界数据文件,它告诉我将其覆盖在 map 上的位置。我必须根据与图像关联的数据计算图像的mapRect。我的 mapRect 似乎没有正确通过,所以我按照我的 let deltaX 和 deltaY 常量分解了代码。 deltaX 处有一个断点,因此我可以看到发生了什么。当我跨过 deltaX 时,它会正确分配该值。当我跨过 deltaY 时,deltaX 的数据消失,然后是 deltaY 的数据消失。

功能如下:

func parseWorldFileData(worldFileStringToParse: String) -> (worldFileDataStruct) {

worldFileDataToParse = worldFileStringToParse.components(separatedBy: "\n") //componentsSeparatedByString("\n")

for i in 0...5 {
worldFileDataToParse[i] = String(worldFileDataToParse[i].characters.dropLast(2))
}

if self.worldFileDataToParse.count >= 6 {

worldFileData.xDimension = Double(self.worldFileDataToParse[0])!
worldFileData.rotationParam1 = Double(self.worldFileDataToParse[1])!
worldFileData.rotationParam2 = Double(self.worldFileDataToParse[2])!
worldFileData.yDimension = Double(self.worldFileDataToParse[3])!
worldFileData.xCoordinate = (Double(self.worldFileDataToParse[4])! as CLLocationDegrees)
worldFileData.yCoordinate = (Double(self.worldFileDataToParse[5])! as CLLocationDegrees)
worldFileData.easternLongitude = (self.worldFileData.xCoordinate + ((Double(self.worldFileData.imageWidth)) * self.worldFileData.xDimension) as CLLocationDegrees)
worldFileData.southernLatitude = (self.worldFileData.yCoordinate + ((Double(self.worldFileData.imageHeight)) * self.worldFileData.yDimension) as CLLocationDegrees)
let deltaX = fabs(self.worldFileData.xCoordinate - self.worldFileData.easternLongitude)
let deltaY = fabs(self.worldFileData.yCoordinate - self.worldFileData.southernLatitude)
worldFileData.boundingMapRect = MKMapRectMake(self.worldFileData.xCoordinate, //topLeft.x
self.worldFileData.yCoordinate, //topLeft.y
deltaX, //fabs(topLeft.x-topRight.x)
deltaY) //fabs(topLeft.y - bottomLeft.y)
worldFileData.midCoordinate = CLLocationCoordinate2D(latitude:((self.worldFileData.southernLatitude + (self.worldFileData.yCoordinate - self.worldFileData.southernLatitude)/2) as CLLocationDegrees), longitude: ((self.worldFileData.xCoordinate + (self.worldFileData.easternLongitude - self.worldFileData.xCoordinate)/2) as CLLocationDegrees))

} else { print("Error parsing WorldData file.") }


return worldFileData
}

就在跨过 deltaX 之前,数据是:

worldFileStringToParse  String  "0.00925265225497161\r\n0.000000\r\n0.000000\r\n-0.00925265225497161\r\n-80.2491661765359\r\n41.5148515181108\r\n"  
self WeatherFun.WorldFileDataModel 0x000060000033b260
worldFileDataToParse [String] 7 values
worldFileData WeatherFun.WorldFileDataModel.worldFileDataStruct
xDimension Double 0.0092526522549715995
rotationParam1 Double 0
rotationParam2 Double 0
yDimension Double -0.0092526522549715995
xCoordinate CLLocationDegrees -80.249166176534999
yCoordinate CLLocationDegrees 41.51485151811
imageHeight Double 183.33333333333334
imageWidth Double 200
easternLongitude CLLocationDegrees -78.398635725540686
southernLatitude CLLocationDegrees 39.818531938031875
boundingMapRect MKMapRect
midCoordinate CLLocationCoordinate2D
deltaX CLLocationDegrees
deltaY CLLocationDegrees

deltaX处步骤后的数据如下:

worldFileStringToParse  String  "0.00925265225497161\r\n0.000000\r\n0.000000\r\n-0.00925265225497161\r\n-80.2491661765359\r\n41.5148515181108\r\n"  
self WeatherFun.WorldFileDataModel 0x000060000033b260
worldFileDataToParse [String] 7 values
worldFileData WeatherFun.WorldFileDataModel.worldFileDataStruct
xDimension Double 0.0092526522549715995
rotationParam1 Double 0
rotationParam2 Double 0
yDimension Double -0.0092526522549715995
xCoordinate CLLocationDegrees -80.249166176534999
yCoordinate CLLocationDegrees 41.51485151811
imageHeight Double 183.33333333333334
imageWidth Double 200
easternLongitude CLLocationDegrees -78.398635725540686
southernLatitude CLLocationDegrees 39.818531938031875
boundingMapRect MKMapRect
midCoordinate CLLocationCoordinate2D
deltaX CLLocationDegrees 1.850530450994313
deltaY CLLocationDegrees

当跨过deltaY时,数据为:

worldFileStringToParse  String  "0.00925265225497161\r\n0.000000\r\n0.000000\r\n-0.00925265225497161\r\n-80.2491661765359\r\n41.5148515181108\r\n"  
self WeatherFun.WorldFileDataModel 0x000060000033b260
worldFileDataToParse [String] 7 values
worldFileData WeatherFun.WorldFileDataModel.worldFileDataStruct
xDimension Double 0.0092526522549715995
rotationParam1 Double 0
rotationParam2 Double 0
yDimension Double -0.0092526522549715995
xCoordinate CLLocationDegrees -80.249166176534999
yCoordinate CLLocationDegrees 41.51485151811
imageHeight Double 183.33333333333334
imageWidth Double 200
easternLongitude CLLocationDegrees -78.398635725540686
southernLatitude CLLocationDegrees 39.818531938031875
boundingMapRect MKMapRect
midCoordinate CLLocationCoordinate2D
deltaX CLLocationDegrees
deltaY CLLocationDegrees 1.696319580078125

当我进入boundingMapRect计算时,这是我的数据:

worldFileStringToParse  String  "0.00925265225497161\r\n0.000000\r\n0.000000\r\n-0.00925265225497161\r\n-80.2491661765359\r\n41.5148515181108\r\n"  
self WeatherFun.WorldFileDataModel 0x000060000033b260
worldFileDataToParse [String] 7 values
worldFileData WeatherFun.WorldFileDataModel.worldFileDataStruct
xDimension Double 0.0092526522549715995
rotationParam1 Double 0
rotationParam2 Double 0
yDimension Double -0.0092526522549715995
xCoordinate CLLocationDegrees -80.249166176534999
yCoordinate CLLocationDegrees 41.51485151811
imageHeight Double 183.33333333333334
imageWidth Double 200
easternLongitude CLLocationDegrees -78.398635725540686
southernLatitude CLLocationDegrees 39.818531938031875
boundingMapRect MKMapRect
midCoordinate CLLocationCoordinate2D
deltaX CLLocationDegrees
deltaY CLLocationDegrees

有人知道发生了什么吗?计算似乎是正确的,因为覆盖图的 mapRect 应跨越 map 上的该距离。然而,当输入boundingMapRect的计算时,我的deltaX似乎消失了。救命!!!

最佳答案

进一步追踪后,数据又出现了。我不确定为什么会发生这种情况,这有点令人不安,但我对 future 的建议是坚持到底。

关于Swift - 让常数值消失并进入下一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43969220/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com