本文整理汇总了C#中Point.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# Point.ToList方法的具体用法?C# Point.ToList怎么用?C# Point.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point
的用法示例。
在下文中一共展示了Point.ToList方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadPoints
//Allow the user to import an array of points to be used to draw a signature in the view, with new
//lines indicated by a PointF.Empty in the array.
public void LoadPoints (Point [] loadedPoints)
{
if (loadedPoints == null || loadedPoints.Count () == 0)
return;
var startIndex = 0;
var emptyIndex = loadedPoints.ToList ().IndexOf (new Point (-10000, -10000));
if (emptyIndex == -1)
emptyIndex = loadedPoints.Count ();
//Clear any existing paths or points.
strokes = new List<Stroke> ();
points = new List<Point []> ();
do {
//Create a new path and set the line options
currentStroke = new Stroke ();
currentStroke.DrawingAttributes.Color = strokeColor;
currentStroke.DrawingAttributes.Width = lineWidth;
currentStroke.DrawingAttributes.Height = lineWidth;
currentPoints = new List<Point> ();
//Move to the first point and add that point to the current_points array.
currentStroke.StylusPoints.Add (GetPoint (loadedPoints [startIndex]));
currentPoints.Add (loadedPoints [startIndex]);
//Iterate through the array until an empty point (or the end of the array) is reached,
//adding each point to the current_path and to the current_points array.
for (var i = startIndex + 1; i < emptyIndex; i++) {
currentStroke.StylusPoints.Add (GetPoint (loadedPoints [i]));
currentPoints.Add (loadedPoints [i]);
}
//Add the current_path and current_points list to their respective Lists before
//starting on the next line to be drawn.
strokes.Add (currentStroke);
points.Add (currentPoints.ToArray ());
//Obtain the indices for the next line to be drawn.
startIndex = emptyIndex + 1;
if (startIndex < loadedPoints.Count () - 1) {
emptyIndex = loadedPoints.ToList ().IndexOf (new Point (-10000, -10000), startIndex);
if (emptyIndex == -1)
emptyIndex = loadedPoints.Count ();
} else
emptyIndex = startIndex;
} while (startIndex < emptyIndex);
//Obtain the image for the imported signature and display it in the image view.
image.Source = GetImage (false);
//Display the clear button.
btnClear.Visibility = Visibility.Visible;
}
示例2: DirectedGraph
public DirectedGraph(Point[] points)
: this()
{
Vertices = points.ToList();
BuildEdges();
}
示例3: _addSeriesAsPolyline
private IEnumerable<Shape> _addSeriesAsPolyline(Point[] points, Brush color, double storkeThickness,
bool animate = true)
{
if (points.Length < 2) return Enumerable.Empty<Shape>();
var addedFigures = new List<Shape>();
var l = 0d;
for (var i = 1; i < points.Length; i++)
{
var p1 = points[i - 1];
var p2 = points[i];
l += Math.Sqrt(
Math.Pow(Math.Abs(p1.X - p2.X), 2) +
Math.Pow(Math.Abs(p1.Y - p2.Y), 2)
);
}
var f = points.First();
var p = points.Where(x => x != f);
var g = new PathGeometry
{
Figures = new PathFigureCollection(new List<PathFigure>
{
new PathFigure
{
StartPoint = f,
Segments = new PathSegmentCollection(
p.Select(x => new LineSegment {Point = new Point(x.X, x.Y)}))
}
})
};
var path = new Path
{
Stroke = color,
StrokeThickness = storkeThickness,
Data = g,
StrokeEndLineCap = PenLineCap.Round,
StrokeStartLineCap = PenLineCap.Round,
StrokeDashOffset = l,
StrokeDashArray = new DoubleCollection { l, l },
ClipToBounds = true
};
var sp = points.ToList();
sp.Add(new Point(points.Max(x => x.X), ToPlotArea(Chart.Min.Y, AxisTags.Y)));
Chart.Canvas.Children.Add(path);
addedFigures.Add(path);
var draw = new DoubleAnimationUsingKeyFrames
{
BeginTime = TimeSpan.FromSeconds(0),
KeyFrames = new DoubleKeyFrameCollection
{
new SplineDoubleKeyFrame
{
KeyTime = TimeSpan.FromMilliseconds(1),
Value = l
},
new SplineDoubleKeyFrame
{
KeyTime = TimeSpan.FromMilliseconds(750),
Value = 0
}
}
};
Storyboard.SetTarget(draw, path);
Storyboard.SetTargetProperty(draw, new PropertyPath(Shape.StrokeDashOffsetProperty));
var sbDraw = new Storyboard();
sbDraw.Children.Add(draw);
var animated = false;
if (!Chart.DisableAnimation)
{
if (animate)
{
sbDraw.Begin();
animated = true;
}
}
if (!animated) path.StrokeDashOffset = 0;
return addedFigures;
}
示例4: ConvertCorner
private List<Point> ConvertCorner(Point ptCorner, Corner corner, bool bLeftToRight)
{
Dictionary<string, Point> news = new Dictionary<string, Point>(4);
news.Add("top", new Point(ptCorner.X, ptCorner.Y - CornerGap));
news.Add("bottom", new Point(ptCorner.X, ptCorner.Y + CornerGap));
news.Add("left", new Point(ptCorner.X - CornerGap, ptCorner.Y));
news.Add("right", new Point(ptCorner.X + CornerGap, ptCorner.Y));
Point[] retConner = new Point[2];
switch (corner)
{
case Corner.LeftTop:
retConner[0] = news["left"];
retConner[1] = news["top"];
break;
case Corner.RightTop:
retConner[0] = news["top"];
retConner[1] = news["right"];
break;
case Corner.RightBottom:
retConner[0] = news["bottom"];
retConner[1] = news["right"];
break;
case Corner.LeftBottom:
retConner[0] = news["left"];
retConner[1] = news["bottom"];
break;
default:
return null;
}
if (!bLeftToRight)
Swap(ref retConner[0], ref retConner[1]);
return retConner.ToList();
}
示例5: GetIntersectedPolygon
/// <summary>
/// This clips the subject polygon against the clip polygon (gets the intersection of the two polygons).
/// </summary>
/// <remarks>
/// Based on the psuedocode from: http://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman
/// </remarks>
/// <param name="subjectPoly">Can be concave or convex.</param>
/// <param name="clipPoly">Must be convex.</param>
/// <returns>The intersection of the two polygons (or null).</returns>
public static Point[] GetIntersectedPolygon(Point[] subjectPoly, Point[] clipPoly)
{
if (subjectPoly.Length < 3 || clipPoly.Length < 3)
{
throw new ArgumentException($"The polygons passed in must have at least 3 points: Subject: {subjectPoly.Length}, Clip: {clipPoly.Length}");
}
List<Point> outputList = subjectPoly.ToList();
// Make sure it's clockwise;
if (!IsClockwise(subjectPoly))
{
outputList.Reverse();
}
// Walk around the clip polygon clockwise;
foreach (Edge clipEdge in IterateEdgesClockwise(clipPoly))
{
List<Point> inputList = outputList.ToList(); // clone it;
outputList.Clear();
if (inputList.Count == 0)
{
break;
}
Point s = inputList[inputList.Count - 1];
foreach (Point e in inputList)
{
if (IsInside(clipEdge, e))
{
if (!IsInside(clipEdge, s))
{
Point? point = GetIntersect(s, e, clipEdge.From, clipEdge.To);
if (point == null)
{
throw new ApplicationException("Line segments don't intersect"); // may be colinear, or may be a bug;
}
else
{
outputList.Add(point.Value);
}
}
outputList.Add(e);
}
else if (IsInside(clipEdge, s))
{
Point? point = GetIntersect(s, e, clipEdge.From, clipEdge.To);
if (point == null)
{
throw new ApplicationException("Line segments don't intersect");
// may be colinear, or may be a bug;
}
else
{
outputList.Add(point.Value);
}
}
s = e;
}
}
return outputList.ToArray();
}
示例6: GetIntersectedPolygon
/// <summary>
/// This clips the subject polygon against the clip polygon (gets the intersection of the two polygons)
/// </summary>
/// <remarks>
/// Based on the psuedocode from:
/// http://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman
/// </remarks>
/// <param name="subjectPoly">Can be concave or convex</param>
/// <param name="clipPoly">Must be convex</param>
/// <returns>The intersection of the two polygons (or null)</returns>
public static Point[] GetIntersectedPolygon(Point[] subjectPoly, Point[] clipPoly)
{
if (subjectPoly.Length < 3 || clipPoly.Length < 3)
{
throw new ArgumentException(string.Format("The polygons passed in must have at least 3 points: subject={0}, clip={1}", subjectPoly.Length.ToString(), clipPoly.Length.ToString()));
}
List<Point> outputList = subjectPoly.ToList();
// Make sure it's clockwise
if (!IsClockwise(subjectPoly))
{
outputList.Reverse();
}
// Walk around the clip polygon clockwise
foreach (Edge clipEdge in IterateEdgesClockwise(clipPoly))
{
List<Point> inputList = outputList.ToList(); // clone it
outputList.Clear();
if (inputList.Count == 0)
{
// Sometimes when the polygons don't intersect, this list goes to zero. Jump out to avoid an index out of range exception
break;
}
Point S = inputList[inputList.Count - 1];
foreach (Point E in inputList)
{
if (IsInside(clipEdge, E))
{
if (!IsInside(clipEdge, S))
{
Point? point = GetIntersect(S, E, clipEdge.From, clipEdge.To);
if (point == null)
{
throw new ApplicationException("Line segments don't intersect"); // may be colinear, or may be a bug
}
else
{
outputList.Add(point.Value);
}
}
outputList.Add(E);
}
else if (IsInside(clipEdge, S))
{
Point? point = GetIntersect(S, E, clipEdge.From, clipEdge.To);
if (point == null)
{
throw new ApplicationException("Line segments don't intersect"); // may be colinear, or may be a bug
}
else
{
outputList.Add(point.Value);
}
}
S = E;
}
}
// Exit Function
return outputList.ToArray();
}
示例7: BorderPoints
public static List<List<Point>> BorderPoints(List<Point> points)
{
var dictionary = new List<KeyValuePair<double, List<Point>>>();
var border = new List<List<Point>>();
var tmp = points.ToList();
tmp.Sort((t1, t2) => Math.Sign(t1.Y - t2.Y));
while (tmp.Count > 0) {
var v = tmp[0];
var near = tmp.TakeWhile(t => Math.Abs(t.Y - v.Y) < 20).ToList();
foreach (var n in near) {
tmp.Remove(n);
}
//near.Sort((n1, n2) => Math.Sign(n1.GetVector3().sqrMagnitude - n2.GetVector3().sqrMagnitude));
if (near.Count > 1) {
var lengthes = new List<double>();
var tmp2 = new Point[near.Count];
near.CopyTo(tmp2);
var max = Math.Sqrt(near.Count);
for (int i = 0; i < max && near.Count > 0; i++) {
var first = near.First();
var last = near.Last();
near.Remove(first);
near.Remove(last);
lengthes.Add((first.GetColor() - last.GetColor()).SqrLength());
}
var median = lengthes.Median();
dictionary.Add(new KeyValuePair<double, List<Point>>(median, tmp2.ToList()));
}
}
for (int i = 0; i < dictionary.Count; i++) {
var nears = dictionary[i].Value;
var distance = dictionary.Min(d => {
if (d.Value == nears) {
return double.MaxValue;
} else {
var col1 = Functions.AverageColor(d.Value.Select(s => s.GetColor()).ToList());
var col2 = Functions.AverageColor(nears.Select(s => s.GetColor()).ToList());
return (col1 - col2).SqrLength();
}
});
if (distance > 0.001) {
border.Add(dictionary[i].Value);
}
}
return border;
}