OpenRA.Map.DistanceToEdge C# (CSharp) Method

DistanceToEdge() public method

public DistanceToEdge ( OpenRA.WPos pos, OpenRA.WVec dir ) : WDist
pos OpenRA.WPos
dir OpenRA.WVec
return WDist
        public WDist DistanceToEdge(WPos pos, WVec dir)
        {
            var projectedPos = pos - new WVec(0, pos.Z, pos.Z);
            var x = dir.X == 0 ? int.MaxValue : ((dir.X < 0 ? ProjectedTopLeft.X : ProjectedBottomRight.X) - projectedPos.X) / dir.X;
            var y = dir.Y == 0 ? int.MaxValue : ((dir.Y < 0 ? ProjectedTopLeft.Y : ProjectedBottomRight.Y) - projectedPos.Y) / dir.Y;
            return new WDist(Math.Min(x, y) * dir.Length);
        }