From 30eaf3bc72ac0bc10c44050a4ffe0256f24888dc Mon Sep 17 00:00:00 2001 From: Andrey Kunchev Date: Fri, 6 Dec 2019 23:23:33 +0200 Subject: [PATCH] add vector parse --- src/Avalonia.Visuals/Vector.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Visuals/Vector.cs b/src/Avalonia.Visuals/Vector.cs index 576d2daaaa..d99fbe8e65 100644 --- a/src/Avalonia.Visuals/Vector.cs +++ b/src/Avalonia.Visuals/Vector.cs @@ -4,6 +4,7 @@ using System; using System.Globalization; using Avalonia.Animation.Animators; +using Avalonia.Utilities; using JetBrains.Annotations; namespace Avalonia @@ -85,6 +86,22 @@ namespace Avalonia public static Vector operator /(Vector vector, double scale) => Divide(vector, scale); + /// + /// Parses a string. + /// + /// The string. + /// The . + public static Vector Parse(string s) + { + using (var tokenizer = new StringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage: "Invalid Vector.")) + { + return new Vector( + tokenizer.ReadDouble(), + tokenizer.ReadDouble() + ); + } + } + /// /// Length of the vector /// @@ -166,9 +183,9 @@ namespace Avalonia } /// - /// Returns the string representation of the point. + /// Returns the string representation of the vector. /// - /// The string representation of the point. + /// The string representation of the vector. public override string ToString() { return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", _x, _y);