且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

一条线穿过的所有点

更新时间:2023-11-23 09:43:22

好吧,就实现一个显而易见的简单算法:从线的一端开始,找到它穿过起始方块的哪一侧,跳转到对应的相邻方块... 等等.步行直到到达终点广场.

Well, just implement the obvious straightforward algorithm: start from one end of the line, find which side of the starting square it crosses, jump to the corresponding adjacent square... and so on. Walk until you reach the finish square.

以整数实现它的最简单方法是切换到超像素精度:只需将所有内容乘以一个常数因子.当您发现没有足够的整数范围来充分乘以它时,困难的部分就开始了……我不知道您的情况是否如此.

The simplest way to implement it in integers would be to switch to superpixel precision: just multiply everything by a constant factor. The difficult part begins when you discover that you don't have enough integer range to multiply it sufficiently... I don't know whether this is the case in your case.