A netizen asked me:
How can I obtain the lattice coordinates in eight directions of a grid? Is there a proper algorithm?
I am like this:
I have read several questions about this writing method:
1. Code is cumbersome and too long
2. It is better to directly use the switch if... elseif...
3. Every time you get the code, you have to make a judgment. In fact, you do not need
4. The variable cache attribute is not used. The attribute is searched again each time.
I thought about it briefly.
I think we can improve the direction, that is, the data format of the direction.
It can improve the efficiency and streamline the code.
Probably as follows:
Copy to ClipboardReference content: [www.bkjia.com] // The direction format is '0, 1', '1,-1 '.
Var Ar = _ this. closeList [_ this. closeId],
ArD = direction. split (','),
NewOpenListItem = {x: Ar. X + ArD [0], y: Ar. Y + ArD [1]}