本文整理汇总了C#中System.Coordinate.Inbounds方法的典型用法代码示例。如果您正苦于以下问题:C# Coordinate.Inbounds方法的具体用法?C# Coordinate.Inbounds怎么用?C# Coordinate.Inbounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Coordinate
的用法示例。
在下文中一共展示了Coordinate.Inbounds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindElement2
public static Coordinate FindElement2(int[][] matrix, Coordinate origin, Coordinate dest, int x)
{
if (!origin.Inbounds(matrix) || !dest.Inbounds(matrix))
{
return null;
}
if (matrix[origin.row][origin.column] == x)
{
return origin;
}
else if (!origin.IsBefore(dest))
{
return null;
}
/* Set start to start of diagonal and end to the end of the diagonal. Since
* the grid may not be square, the end of the diagonal may not equal dest.
*/
Coordinate start = (Coordinate)origin.Clone();
int diagDist = Math.Min(dest.row - origin.row, dest.column - origin.column);
Coordinate end = new Coordinate(start.row + diagDist, start.column + diagDist);
Coordinate p = new Coordinate(0, 0);
/* Do binary search on the diagonal, looking for the first element greater than x */
while (start.IsBefore(end))
{
p.SetToAverage(start, end);
if (x > matrix[p.row][p.column])
{
start.row = p.row + 1;
start.column = p.column + 1;
}
else {
end.row = p.row - 1;
end.column = p.column - 1;
}
}
/* Split the grid into quadrants. Search the bottom left and the top right. */
return PartitionAndSearch(matrix, origin, dest, start, x);
}