本文整理汇总了C#中Point2D.ToDirection方法的典型用法代码示例。如果您正苦于以下问题:C# Point2D.ToDirection方法的具体用法?C# Point2D.ToDirection怎么用?C# Point2D.ToDirection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point2D
的用法示例。
在下文中一共展示了Point2D.ToDirection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SearchPath
//.........这里部分代码省略.........
break; // success
if (m.CheckCell(x, y, cell) == false)
break; // obstacle = failure
}
if (x == x1 && y == y1) { //easy path successful.
wpd.path_len = (uint)i;
wpd.path_pos = 0;
return true;
}
if ((flag & 1) == 1)
return false;
i = CalcIndex(x0, y0);
tp[i].x = (short)x0;
tp[i].y = (short)y0;
tp[i].dist = 0;
tp[i].before = 0;
tp[i].cost = (short)CalcCost(tp[i], x1, y1);
tp[i].flag = 0;
heap[0] = 0;
PushHeapPath(heap, tp, CalcIndex(x0, y0));
xs = m.Width - 1; // ‚ ‚ç‚©‚¶‚ß‚PŒ¸ŽZ‚µ‚Ä‚¨‚
ys = m.Height - 1;
while (true) {
int e = 0, f = 0;
int dist;
int cost;
int[] dc = new int[4];
if (heap[0] == 0)
return false;
rp = PopHeapPath(heap, tp);
x = tp[rp].x;
y = tp[rp].y;
dist = tp[rp].dist + 10;
cost = tp[rp].cost;
if (x == x1 && y == y1)
break;
// dc[0] : y++
// dc[1] : x--
// dc[2] : y--
// dc[3] : x++
if (y < ys && m.CheckCell(x, y + 1, cell)) {
f |= 1;
dc[0] = (y >= y1 ? 20 : 0);
e += AddPath(heap, tp, x, y + 1, dist, rp, cost + dc[0]); // (x, y+1)
}
if (x > 0 && m.CheckCell(x - 1, y, cell)) {
f |= 2;
dc[1] = (x <= x1 ? 20 : 0);
e += AddPath(heap, tp, x - 1, y, dist, rp, cost + dc[1]); // (x-1, y )
}
if (y > 0 && m.CheckCell(x, y - 1, cell)) {
f |= 4;
dc[2] = (y <= y1 ? 20 : 0);
e += AddPath(heap, tp, x, y - 1, dist, rp, cost + dc[2]); // (x , y-1)
}
if (x < xs && m.CheckCell(x + 1, y, cell)) {
f |= 8;
dc[3] = (x >= x1 ? 20 : 0);
e += AddPath(heap, tp, x + 1, y, dist, rp, cost + dc[3]); // (x+1, y )
}
if ((f & (2 + 1)) == (2 + 1) && m.CheckCell(x - 1, y + 1, cell))
e += AddPath(heap, tp, x - 1, y + 1, dist + 4, rp, cost + dc[1] + dc[0] - 6); // (x-1, y+1)
if ((f & (2 + 4)) == (2 + 4) && m.CheckCell(x - 1, y - 1, cell))
e += AddPath(heap, tp, x - 1, y - 1, dist + 4, rp, cost + dc[1] + dc[2] - 6); // (x-1, y-1)
if ((f & (8 + 4)) == (8 + 4) && m.CheckCell(x + 1, y - 1, cell))
e += AddPath(heap, tp, x + 1, y - 1, dist + 4, rp, cost + dc[3] + dc[2] - 6); // (x+1, y-1)
if ((f & (8 + 1)) == (8 + 1) && m.CheckCell(x + 1, y + 1, cell))
e += AddPath(heap, tp, x + 1, y + 1, dist + 4, rp, cost + dc[3] + dc[0] - 6); // (x+1, y+1)
tp[rp].flag = 1;
if (e > 0 || heap[0] >= MAX_HEAP - 5)
return false;
}
if (!(x == x1 && y == y1)) // will never happen...
return false;
for (len = 0, i = rp; len < 100 && i != CalcIndex(x0, y0); i = tp[i].before, len++) {
}
if (len == 100 || len >= wpd.path.Length)
return false;
wpd.path_len = (uint)len;
wpd.path_pos = 0;
for (i = rp, j = len - 1; j >= 0; i = tp[i].before, j--) {
dx = tp[i].x - tp[tp[i].before].x;
dy = tp[i].y - tp[tp[i].before].y;
Point2D p = new Point2D(dx, dy);
wpd.path[j] = p.ToDirection();
}
return true;
}