public CircularLinkedList <T> Reverse() { var temp = new CircularLinkedList <T>(); foreach (var current in this) { temp.AddFirst(current); } return(temp); }
private PointF[] GetPointArray(CircularLinkedList <Vector2> list) { var currentNode = list.First; var result = new PointF[list.Count]; for (var i = 0; i < list.Count; i++) { result[i] = ConvertToScreenCoord(currentNode.Value.X, currentNode.Value.Y); currentNode = list.NextOrFirst(currentNode); } return(result); }
private bool IsOnWindow(CircularLinkedList <Vector2> list, Vector2 point) { var cur = list.First; for (var i = 0; i < list.Count; i++) { var prev = cur; cur = list.NextOrFirst(cur); if (IsBelongsLine(prev.Value, cur.Value, point) && IsPointInside(prev.Value, cur.Value, point)) { return(true); } } return(false); }
private bool IsInside(Vector2 point, CircularLinkedList <Vector2> list) { var flag = false; var prev = list.Last; var cur = list.First; for (var i = 0; i < list.Count; i++) { if ((cur.Value.Y <= point.Y && point.Y < prev.Value.Y || prev.Value.Y <= point.Y && point.Y < cur.Value.Y) && point.X > (prev.Value.X - cur.Value.X) * (point.Y - cur.Value.Y) / (prev.Value.Y - cur.Value.Y) + cur.Value.X) { flag = !flag; } prev = cur; cur = list.NextOrFirst(cur); } return(flag); }
private void Draw(CircularLinkedList <Vector2> subject, CircularLinkedList <Vector2> clip) { var graphics = CreateGraphics(); graphics.Clear(Color.White); var resultPolygons = ClippingAlgorithm.Process(subject, clip); if (resultPolygons.Count == 0) { if (subject.Any(p => !IsInside(p, clip) && !IsOnWindow(clip, p))) { if (clip.Any(p => !IsInside(p, subject) && !IsOnWindow(subject, p))) { graphics.FillPolygon(Brushes.PaleVioletRed, GetPointArray(subject)); graphics.DrawPolygon(Pens.Black, GetPointArray(subject)); } else { graphics.FillPolygon(Brushes.PaleVioletRed, GetPointArray(subject)); graphics.FillPolygon(Brushes.White, GetPointArray(clip)); graphics.DrawPolygon(Pens.Black, GetPointArray(subject)); graphics.DrawPolygon(Pens.Black, GetPointArray(clip)); } } } foreach (var polygon in resultPolygons) { graphics.FillPolygon(Brushes.PaleVioletRed, GetPointArray(polygon)); graphics.DrawPolygon(Pens.Black, GetPointArray(polygon)); } graphics.DrawPolygon(Pens.Black, GetPointArray(subject)); graphics.DrawPolygon(Pens.CornflowerBlue, GetPointArray(clip)); }