本文整理汇总了C#中Segment.LengthSquared方法的典型用法代码示例。如果您正苦于以下问题:C# Segment.LengthSquared方法的具体用法?C# Segment.LengthSquared怎么用?C# Segment.LengthSquared使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Segment
的用法示例。
在下文中一共展示了Segment.LengthSquared方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Partition
public double[][][] Partition()
{
if (_data != null)
{
_data = _data.OrderByDescending(d => d).ToArray();
List<double[]> p1 = new List<double[]>();
List<double[]> p2 = new List<double[]>();
bool first = true;
for (int i = 0; i < _data.GetLength(0); i += 2)
{
p1.Add(new double[] { _data[((first) ? i : i + 1)] });
p2.Add(new double[] { _data[((first) ? i + 1 : i)] });
first = !first;
}
if (_data.GetLength(0) == p1.Count + p2.Count + 1)
p1.Add(new double[] { _data[_data.GetLength(0) - 1] });
double[][][] r = new double[2][][];
r[0] = p1.ToArray();
r[1] = p2.ToArray();
return r;
}
List<double[]> part1 = new List<double[]>();
List<double[]> part2 = new List<double[]>();
ClosestPair cp = new ClosestPair();
cp.Points.AddRange(_points);
bool one = true;
while (cp.Points.Count > 1)
{
Segment split = cp.TargetedSearch();
Segment comp1 = new Segment(split.P1, Point.Center(split.P1.Dimension));
Segment comp2 = new Segment(split.P2, Point.Center(split.P1.Dimension));
Point max;
Point min;
if (comp1.LengthSquared() > comp2.LengthSquared())
{
max = split.P1;
min = split.P2;
}
else
{
max = split.P2;
min = split.P1;
}
if (one)
{
part1.Add(max.Coordinates);
part2.Add(min.Coordinates);
}
else
{
part1.Add(min.Coordinates);
part2.Add(max.Coordinates);
}
one = !one;
cp.Points.Remove(split.P1);
cp.Points.Remove(split.P2);
}
if (cp.Points.Count == 1)
part1.Add(cp.Points[0].Coordinates);
double[][][] part = new double[2][][];
part[0] = part1.ToArray();
part[1] = part2.ToArray();
return part;
}