坐标转化和前端保持一致
parent
11cd52dbd8
commit
eaea13a4b3
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.ljsd.jieling.util;
|
||||||
|
|
||||||
|
public class ToolsUtil {
|
||||||
|
|
||||||
|
|
||||||
|
public static int xy2Pos(int x, int y) {
|
||||||
|
return (x << 8) | y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[] pos2XY(int pos) {
|
||||||
|
int[] xy = new int[2];
|
||||||
|
xy[0] = (pos >> 8) & 0xff;
|
||||||
|
xy[1] = pos & 0xff;
|
||||||
|
return xy;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int xx = 12;
|
||||||
|
int yy = 5;
|
||||||
|
int pos = xy2Pos(xx,yy);
|
||||||
|
System.out.println("======> pos : "+pos);
|
||||||
|
int[] xy = pos2XY(pos);
|
||||||
|
System.out.println("=======> nX : "+xy[0]+" , nY : "+xy[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue