|
@@ -546,12 +546,16 @@ public class PathBuilder {
|
|
|
if (vEndNbr == hLine) { //endLine与通道垂直
|
|
|
int safeOffset = 5;
|
|
|
int[] targetScope = new int[]{Math.max(lineScope[0], endNbr[0] + safeOffset), Math.min(lineScope[1], endNbr[1] - safeOffset)};
|
|
|
+ if(targetScope[1] < targetScope[0]){
|
|
|
+ int tmp = targetScope[0];
|
|
|
+ targetScope[0] = targetScope[1];
|
|
|
+ targetScope[1] = tmp;
|
|
|
+ }
|
|
|
|
|
|
//当前点和线有偏差时,先做调整
|
|
|
int pos = vEndNbr ? currentPoint.x : currentPoint.y;
|
|
|
if(!(pos > targetScope[0] && pos < targetScope[1])){
|
|
|
- //临时避免和节点边线重合
|
|
|
- int target0 = targetScope[0] + random.nextInt(targetScope[1] - targetScope[0]);
|
|
|
+ int target0 = midPosition(targetScope[0], targetScope[1]);
|
|
|
if (vEndNbr) {
|
|
|
moveTo(target0, false);
|
|
|
} else {
|
|
@@ -577,7 +581,12 @@ public class PathBuilder {
|
|
|
if (vEndNbr == hLine) { //endLine与通道垂直
|
|
|
int safeOffset = 5;//临时避免和节点边线重合
|
|
|
int[] targetScope = new int[]{Math.max(lineScope[0], endNbr[0] + safeOffset), Math.min(lineScope[1], endNbr[1] - safeOffset)};
|
|
|
- int target0 = targetScope[0] + random.nextInt(targetScope[1] - targetScope[0]); //TODO 调整&避免重叠
|
|
|
+ if(targetScope[1] < targetScope[0]){
|
|
|
+ int tmp = targetScope[0];
|
|
|
+ targetScope[0] = targetScope[1];
|
|
|
+ targetScope[1] = tmp;
|
|
|
+ }
|
|
|
+ int target0 = midPosition(targetScope[0], targetScope[1]);
|
|
|
moveTo(target0, vDirection);
|
|
|
moveTo(lineTrackPos, hLine);
|
|
|
} else { //endLine与通道平行
|
|
@@ -610,6 +619,15 @@ public class PathBuilder {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private int midPosition(int i1, int i2){
|
|
|
+ int pos = (i1 + i2) / 2;
|
|
|
+ if(i2 > i1){
|
|
|
+ int maxOffset = 5;
|
|
|
+ pos += (random.nextBoolean() ? 1 : -1) * random.nextInt(Math.min(i2 - i1, maxOffset)); //随机调整,避免重合
|
|
|
+ }
|
|
|
+ return pos;
|
|
|
+ }
|
|
|
+
|
|
|
private XY moveTo(int targetPos, boolean vDirection) {
|
|
|
XY point = new XY(currentPoint);
|
|
|
if (vDirection) {
|