public void Reverse() { // Reverse all our segments and swap the order of them. foreach (Segment s in Segments) { s.Reverse(); } Segments.Reverse(); }
/// <summary> /// Normalizes polygon - all polygon's vertices and edges must be in CCW order. /// </summary> public void NormalizePolygon() { if (!CheckIfClockwise()) { return; } Segments = new LinkedList <Segment>(Segments.Reverse()); foreach (var seg in this.Segments) { var tmp = seg.From; seg.From = seg.To; seg.To = tmp; } Vertices = new LinkedList <Vertex>(Vertices.Reverse()); }
/// <inheritdoc/> public override void ReplaceSelectionWithText(string newText) { if (newText == null) { throw new ArgumentNullException("newText"); } using (textArea.Document.RunUpdate()) { TextViewPosition start = new TextViewPosition(document.GetLocation(topLeftOffset), GetVisualColumnFromXPos(startLine, startXPos)); TextViewPosition end = new TextViewPosition(document.GetLocation(bottomRightOffset), GetVisualColumnFromXPos(endLine, endXPos)); int insertionLength; int totalInsertionLength = 0; int firstInsertionLength = 0; int editOffset = Math.Min(topLeftOffset, bottomRightOffset); TextViewPosition pos; if (NewLineFinder.NextNewLine(newText, 0) == SimpleSegment.Invalid) { // insert same text into every line foreach (SelectionSegment lineSegment in Segments.Reverse()) { ReplaceSingleLineText(textArea, lineSegment, newText, out insertionLength); totalInsertionLength += insertionLength; firstInsertionLength = insertionLength; } int newEndOffset = editOffset + totalInsertionLength; pos = new TextViewPosition(document.GetLocation(editOffset + firstInsertionLength)); textArea.Selection = new RectangleSelection(textArea, pos, Math.Max(startLine, endLine), GetXPos(textArea, pos)); } else { string[] lines = newText.Split(NewLineFinder.NewlineStrings, segments.Count, StringSplitOptions.None); int line = Math.Min(startLine, endLine); for (int i = lines.Length - 1; i >= 0; i--) { ReplaceSingleLineText(textArea, segments[i], lines[i], out insertionLength); firstInsertionLength = insertionLength; } pos = new TextViewPosition(document.GetLocation(editOffset + firstInsertionLength)); textArea.ClearSelection(); } textArea.Caret.Position = textArea.TextView.GetPosition(new Point(GetXPos(textArea, pos), textArea.TextView.GetVisualTopByDocumentLine(Math.Max(startLine, endLine)))).GetValueOrDefault(); } }
/// <inheritdoc/> public override void ReplaceSelectionWithText(string newText) { if (newText == null) { throw new ArgumentNullException(nameof(newText)); } using (TextArea.Document.RunUpdate()) { int insertionLength; var firstInsertionLength = 0; var editOffset = Math.Min(_topLeftOffset, _bottomRightOffset); TextViewPosition pos; if (NewLineFinder.NextNewLine(newText, 0) == SimpleSegment.Invalid) { // insert same text into every line foreach (var lineSegment in Segments.Reverse()) { ReplaceSingleLineText(TextArea, lineSegment, newText, out insertionLength); firstInsertionLength = insertionLength; } pos = new TextViewPosition(_document.GetLocation(editOffset + firstInsertionLength)); TextArea.Selection = new RectangleSelection(TextArea, pos, Math.Max(_startLine, _endLine), GetXPos(TextArea, pos)); } else { var lines = newText.Split(NewLineFinder.NewlineStrings, _segments.Count, StringSplitOptions.None); for (var i = lines.Length - 1; i >= 0; i--) { ReplaceSingleLineText(TextArea, _segments[i], lines[i], out insertionLength); firstInsertionLength = insertionLength; } pos = new TextViewPosition(_document.GetLocation(editOffset + firstInsertionLength)); TextArea.ClearSelection(); } TextArea.Caret.Position = new TextViewPosition(Math.Max(_startLine, _endLine), pos.Column); } }