本文整理汇总了C#中Direction.NextCounterClockwise方法的典型用法代码示例。如果您正苦于以下问题:C# Direction.NextCounterClockwise方法的具体用法?C# Direction.NextCounterClockwise怎么用?C# Direction.NextCounterClockwise使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Direction
的用法示例。
在下文中一共展示了Direction.NextCounterClockwise方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WalkContour
/// <summary>
/// Try to visit all the spans. May be needed in filtering small regions.
/// </summary>
/// <param name="regions">an array of region values</param>
/// <param name="spanRef">The span to start walking from.</param>
/// <param name="dir">The direction to start walking in.</param>
/// <param name="cont">A collection of regions to append to.</param>
private void WalkContour(RegionId[] regions, CompactSpanReference spanRef, Direction dir, List<RegionId> cont)
{
Direction startDir = dir;
int starti = spanRef.Index;
CompactSpan ss = spans[starti];
RegionId curReg = RegionId.Null;
if (ss.IsConnected(dir))
{
int dx = spanRef.X + dir.GetHorizontalOffset();
int dy = spanRef.Y + dir.GetVerticalOffset();
int di = cells[dx + dy * width].StartIndex + CompactSpan.GetConnection(ref ss, dir);
curReg = regions[di];
}
cont.Add(curReg);
int iter = 0;
while (++iter < 40000)
{
CompactSpan s = spans[spanRef.Index];
if (IsSolidEdge(regions, ref spanRef, dir))
{
//choose the edge corner
RegionId r = RegionId.Null;
if (s.IsConnected(dir))
{
int dx = spanRef.X + dir.GetHorizontalOffset();
int dy = spanRef.Y + dir.GetVerticalOffset();
int di = cells[dx + dy * width].StartIndex + CompactSpan.GetConnection(ref s, dir);
r = regions[di];
}
if (r != curReg)
{
curReg = r;
cont.Add(curReg);
}
dir = dir.NextClockwise(); //rotate clockwise
}
else
{
int di = -1;
int dx = spanRef.X + dir.GetHorizontalOffset();
int dy = spanRef.Y + dir.GetVerticalOffset();
if (s.IsConnected(dir))
{
CompactCell dc = cells[dx + dy * width];
di = dc.StartIndex + CompactSpan.GetConnection(ref s, dir);
}
if (di == -1)
{
//shouldn't happen
return;
}
spanRef = new CompactSpanReference(dx, dy, di);
dir = dir.NextCounterClockwise(); //rotate counterclockwise
}
if (starti == spanRef.Index && startDir == dir)
break;
}
//remove adjacent duplicates
if (cont.Count > 1)
{
for (int j = 0; j < cont.Count;)
{
//next element
int nj = (j + 1) % cont.Count;
//adjacent duplicate found
if (cont[j] == cont[nj])
cont.RemoveAt(j);
else
j++;
}
}
}