110,535
社区成员
发帖
与我相关
我的任务
分享
class LayCityLabel
{
public delegate void A(List<int> i);
public A LabelFilter
{
get;
set;
}
}
class Program
{
public static void ThoroughCollisionDetection(List<int> labels)
{
foreach (int item in labels)
{
Console.WriteLine(item);
}
}
static void Main(string[] args)
{
LayCityLabel layCityLabel = new LayCityLabel();
layCityLabel.LabelFilter = ThoroughCollisionDetection;
layCityLabel.LabelFilter(new List<int>() { 1, 2, 3, 4 });
Console.Read();
}
}
using System.Collections.Generic;
namespace SharpMap.Rendering
{
/// <summary>
/// Class defining delegate for label collision detection and static predefined methods
/// </summary>
public class LabelCollisionDetection
{
#region Delegates
/// <summary>
/// Delegate method for filtering labels. Useful for performing custom collision detection on labels
/// </summary>
/// <param name="labels"></param>
/// <returns></returns>
public delegate void LabelFilterMethod(List<BaseLabel> labels);
#endregion
#region Label filter methods
/// <summary>
/// Simple and fast label collision detection.
/// </summary>
/// <param name="labels"></param>
public static void SimpleCollisionDetection(List<BaseLabel> labels)
{
labels.Sort(); // sort labels by intersectiontests of labelbox
//remove labels that intersect other labels
for (int i = labels.Count - 1; i > 0; i--)
if (labels[i].CompareTo(labels[i - 1]) == 0)
{
if (labels[i].Priority == labels[i - 1].Priority) continue;
if (labels[i].Priority > labels[i - 1].Priority)
labels.RemoveAt(i - 1);
else
labels.RemoveAt(i);
}
}
/// <summary>
/// Thorough label collision detection.
/// </summary>
/// <param name="labels"></param>
public static void ThoroughCollisionDetection(List<BaseLabel> labels)
{
labels.Sort(); // sort labels by intersectiontests of labelbox
//remove labels that intersect other labels
for (int i = labels.Count - 1; i > 0; i--)
{
if (!labels[i].Show) continue;
for (int j = i - 1; j >= 0; j--)
{
if (!labels[j].Show) continue;
if (labels[i].CompareTo(labels[j]) == 0)
if (labels[i].Priority >= labels[j].Priority)
{
labels[j].Show = false;
//labels.RemoveAt(j);
//i--;
}
else
{
labels[i].Show = false;
//labels.RemoveAt(i);
//i--;
break;
}
}
}
}
#endregion
}
}