其他分享
首页 > 其他分享> > 2021-07-04学习总结

2021-07-04学习总结

作者:互联网

菜鸡学Python——学习总结

关于2021.7.4的python编译的学习总结
链接: https://blog.csdn.net/river_rain/article/details/113856897?spm=1001.2014.3001.5501.

用切片法创建列表副本

这其实是python编译的基本功,然而实战中却忘了。

 visited_voxels.append(current_voxel)

此处会将列表current_voxel的地址作为参数,由于在循环中会不断地使用该语句来将新数据放入列表visited_voxels中,会导致visited_voxels中的每一个元素都是current_voxel的地址。所以应该这么写:

 visited_voxels.append(current_voxel[:])

现在才是创立了current_voxel的副本,将其中的元素放入visited_voxels

用函数调用解决臃肿

...
 countinue = 0
    for i in range(0,len(last_voxel)):
        if last_voxel[i] != current_voxel[i]:
            countinue = 1
    while countinue:
        if tMaxX < tMaxY:
            if tMaxX < tMaxZ:
                current_voxel[0] += stepX
                tMaxX += tDeltaX
            else:
                current_voxel[2] += stepZ
                tMaxX += tDeltaZ
        else:
            if tMaxY < tMaxZ:
                current_voxel[1] += stepY
                tMaxY += tDeltaY
            else:
                current_voxel[2] += stepZ
                tMaxZ += tDeltaZ

        visited_voxels.append(current_voxel[:])
       
        countinue = 0
        for i in range(0,len(last_voxel)):
            if last_voxel[i] != current_voxel[i]:
                countinue = 1

这段不美观且有重复性内容,应用函数调用的方式来简化

 def loop(last_voxel,current_voxel):
    
    countinue = 0
    for i in range(0,len(last_voxel)):
        if last_voxel[i] != current_voxel[i]:
            countinue = 1
    return countinue
 ...   
 while loop(last_voxel[:],current_voxel[:]):
        if tMaxX < tMaxY:
            if tMaxX < tMaxZ:
                current_voxel[0] += stepX
                tMaxX += tDeltaX
            else:
                current_voxel[2] += stepZ
                tMaxX += tDeltaZ
        else:
            if tMaxY < tMaxZ:
                current_voxel[1] += stepY
                tMaxY += tDeltaY
            else:
                current_voxel[2] += stepZ
                tMaxZ += tDeltaZ

        visited_voxels.append(current_voxel[:])

编译环境的不同

笔者当时是用的VS来编译的,此处的DBL_MAX因为并没用被实际使用所以没有报错,程序也可以正常运行,但笔者的朋友却是用的pycharm,DBL_MAX因为没有实际赋值而报错。这种编译环境的问题以后需要注意,可能会引发交接问题:“为什么我的电脑可以运行,你的不能?”

tMaxX = ((int(next_voxel_boundary_x) - ray_start[0])/ray[0] if ray[0] != 0 else DBL_MAX)

标签:voxel,last,07,04,countinue,current,2021,tMaxX,voxels
来源: https://blog.csdn.net/river_rain/article/details/118557091