本文整理汇总了C#中Segment.Length方法的典型用法代码示例。如果您正苦于以下问题:C# Segment.Length方法的具体用法?C# Segment.Length怎么用?C# Segment.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Segment
的用法示例。
在下文中一共展示了Segment.Length方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BruteForce
private Segment BruteForce(List<Point> points)
{
//Trace.Assert(points.Count >= 2);
int count = points.Count;
// Seed the result - doesn't matter what points are used
// This just avoids having to do null checks in the main loop below
var result = new Segment(points[0], points[1]);
var bestLength = result.Length();
for (int i = 0; i < count; i++)
for (int j = i + 1; j < count; j++)
if (Segment.Length(points[i], points[j]) < bestLength)
{
result = new Segment(points[i], points[j]);
bestLength = result.Length();
}
return result;
}
示例2: getFollowingTitle
private FollowingTitle getFollowingTitle(Graphics g, LinePath part, double length, string label, TitleStyle titleStyle, BoundingRectangle viewBox, double scaleFactor)
{
StringFormat format = StringFormat.GenericTypographic;
SizeF sizeF;
PointF zeroPoint = new PointF(0, 0);
using (Font f = titleStyle.GetFont())
{
sizeF = g.MeasureString(label, f, zeroPoint, format);
// label length must be less than the length of the line
if (sizeF.Width / scaleFactor < length)
{
LinePath tempPart = new LinePath();
foreach (ICoordinate p in part.Vertices)
tempPart.Vertices.Add(p);
int vertexNumber = 0;
ICoordinate centerPoint = getDistantPoint(tempPart.Vertices, length / 2, out vertexNumber);
// if the point of the proposed mid-label misses the display area of the map, the inscription does not appear
if (!viewBox.ContainsPoint(centerPoint))
return null;
// simplify the line
tempPart.Weed(sizeF.Height / scaleFactor / 2);
//get the center point of the simplified line
centerPoint = getDistantPoint(tempPart.Vertices, length / 2, out vertexNumber);
List<double> leftPointsRotationDeltas = new List<double>();
List<double> rightPointsRotationDeltas = new List<double>();
// coordinates of points on the left of the middle of the inscription
IList<ICoordinate> leftPoints =
getLeftPoints(tempPart.Vertices,
centerPoint,
sizeF.Width / 2 / scaleFactor,
vertexNumber,
sizeF.Height / 2 / scaleFactor,
leftPointsRotationDeltas);
// coordinates of the points to the right of the middle of the inscription
IList<ICoordinate> rightPoints =
getRightPoints(tempPart.Vertices,
centerPoint,
sizeF.Width / 2 / scaleFactor,
vertexNumber,
sizeF.Height / 2 / scaleFactor,
rightPointsRotationDeltas);
//coordinates of the vertices of the broken line, which will be located along the inscription
List<ICoordinate> points = leftPoints.ToList();
points.AddRange(rightPoints);
// shifts of the inscriptions associated with break lines
List<double> rotationDeltas = leftPointsRotationDeltas;
rotationDeltas.AddRange(rightPointsRotationDeltas);
for (int i = 0; i < points.Count; i++)
points[i] = PlanimetryEnvironment.NewCoordinate((points[i].X - viewBox.MinX) * scaleFactor,
(viewBox.MaxY - points[i].Y) * scaleFactor);
for (int i = 0; i < rotationDeltas.Count; i++)
rotationDeltas[i] = rotationDeltas[i] * scaleFactor;
//determine the direction of following labels (direct or reverse)
double forwardWeight = 0;
double backwardWeight = 0;
for (int i = 1; i < points.Count; i++)
{
Segment s = new Segment(PlanimetryEnvironment.NewCoordinate(points[i].X, points[i].Y),
PlanimetryEnvironment.NewCoordinate(points[i - 1].X, points[i - 1].Y));
int quadNumber = pointQuadrantNumber(PlanimetryEnvironment.NewCoordinate(s.V1.X - s.V2.X, s.V1.Y - s.V2.Y));
if (quadNumber == 1 || quadNumber == 4)
forwardWeight += s.Length();
else
backwardWeight += s.Length();
}
if (backwardWeight > forwardWeight)
{
points.Reverse();
rotationDeltas.Reverse();
}
// inscriptions along the route should not be a large number of points
if (label.Length > points.Count - 2)
{
List<int> subStringLengths = new List<int>();
List<double> deltas = new List<double>();
LinePath p1 = new LinePath(points.ToArray());
double l = p1.Length();
// partition of the inscription on the straight parts, the calculation of displacement
int startIndex = 0;
for (int i = 1; i < points.Count; i++)
{
//.........这里部分代码省略.........
示例3: TargetedSearch
private Segment TargetedSearch(List<Point> points)
{
//Trace.Assert(points.Count >= 2);
int count = points.Count;
points.Sort((lhs, rhs) => lhs.Coordinates[0].CompareTo(rhs.Coordinates[0]));
var result = new Segment(points[0], points[1]);
var bestLength = result.Length();
for (int i = 0; i < count; i++)
{
var from = points[i];
for (int j = i + 1; j < count; j++)
{
var to = points[j];
var dx = to.Coordinates[0] - from.Coordinates[0];
if (dx >= bestLength)
{
break;
}
if (Segment.Length(from, to) < bestLength)
{
result = new Segment(from, to);
bestLength = result.Length();
}
}
}
return result;
}