public static DirFlags Rotate(this DirFlags flag, Rot4 rot = Rot4.CCW90) { int f = (int)flag, r = (int)rot; int shifted = f << r; return((DirFlags)((shifted & 0xF) | ((shifted & 0xF0) >> 4))); }
/// <summary>Convert flag into a direction, if multiple flags are set, return the first set direction.</summary> /// <param name="flag">The flag.</param> /// <exception cref="System.ArgumentException">Flag has no bit set.</exception> public static Dir ToDir(this DirFlags flag) { foreach (Dir d in CWMap) { if (flag.HasFlag(FlagMap[(int)d])) { return(d); } } throw new ArgumentException("Flag has no bit set."); }
internal void Reset() { isStartOrGoal = false; mIsDiagonalOn = false; mIsStraightOn = false; mIsWallOn = false; mBase.color = Color.white; for (int i = 0b10000000; i > 0; i >>= 1) { EDirFlags dir = (EDirFlags)i; int index = DirFlags.ToArrayIndex(dir); dirImages[index].color = InvisibleColor; dirTexts[index].text = string.Empty; } }
public FastRay2d(Ray2d ray) { Ray = ray; DirFlags = ray.Direction.DirFlags(); InvDir = 1.0 / ray.Direction; }
private void Indicate(bool mIsStraightOn, bool mIsDiagonalOn, bool mIsWallOn) { for (int i = 0b10000000; i > 0; i >>= 1) { EDirFlags dir = (EDirFlags)i; int dist = mBakedBlock.GetDistance(dir); int index = DirFlags.ToArrayIndex(dir); if (dist > 0) { if ((dir & StraightDirs) == dir) { if (mIsStraightOn) { dirImages[index].color = InvisibleColor; dirTexts[index].text = dist.ToString(); } else { dirImages[index].color = InvisibleColor; dirTexts[index].text = string.Empty; } } if ((dir & DiagonalDirs) == dir) { if (mIsDiagonalOn) { dirImages[index].color = InvisibleColor; dirTexts[index].text = dist.ToString(); } else { dirImages[index].color = InvisibleColor; dirTexts[index].text = string.Empty; } } } else if (dist == 0) { if (mIsWallOn) { dirImages[index].color = Color.red; dirTexts[index].text = dist.ToString(); } else { dirImages[index].color = InvisibleColor; dirTexts[index].text = string.Empty; } } else { if ((dir & StraightDirs) == dir) { if (mIsWallOn && mIsStraightOn) { dirImages[index].color = Color.yellow; dirTexts[index].text = dist.ToString(); } else { dirImages[index].color = InvisibleColor; dirTexts[index].text = string.Empty; } } if ((dir & DiagonalDirs) == dir) { if (mIsWallOn && mIsDiagonalOn) { dirImages[index].color = Color.yellow; dirTexts[index].text = dist.ToString(); } else { dirImages[index].color = InvisibleColor; dirTexts[index].text = string.Empty; } } } } }
public bool Step(int stepCount) { for (int step = stepCount; step > 0; --step) { if (mOpenList.Count == 0) { return(false); } AStarNode curr = mOpenList.Dequeue(); if (curr == mGoal) { return(true); } mCloseList.Add(curr); for (int i = 0b10000000; i > 0; i >>= 1) { EDirFlags dir = (EDirFlags)i; Int2 dp = DirFlags.ToPos(dir); AStarNode adjacent = GetNodeOrNull(curr.Position + dp); if (adjacent == null) { continue; } if (IsWall(adjacent.Position)) { continue; } if (DirFlags.IsDiagonal(dir)) { // for prevent corner cutting if (IsWall(curr.Position + new Int2(dp.X, 0)) || IsWall(curr.Position + new Int2(0, dp.Y))) { continue; } } if (mCloseList.Contains(adjacent)) { continue; } int nextG = G(curr, adjacent); if (!mOpenList.Contains(adjacent)) { adjacent.Parent = curr; adjacent.G = nextG; adjacent.H = H(adjacent, mGoal); mOpenList.Enqueue(adjacent, adjacent.F); } else if (nextG < adjacent.G) { adjacent.Parent = curr; adjacent.G = nextG; adjacent.H = H(adjacent, mGoal); mOpenList.UpdatePriority(adjacent, adjacent.F); } } } return(false); }