22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5- using System ;
6- using System . Globalization ;
7- using System . Linq ;
85using System . Numerics ;
96using Windows . UI . Composition ;
107using Windows . UI . Xaml ;
@@ -17,160 +14,6 @@ namespace Microsoft.Toolkit.Uwp.UI
1714 /// </summary>
1815 public static class VisualExtensions
1916 {
20- /// <summary>
21- /// Converts a <see cref="string"/> to <see cref="Vector2"/>
22- /// </summary>
23- /// <param name="str">A string in the format of "float, float"</param>
24- /// <returns><see cref="Vector2"/></returns>
25- public static Vector2 ToVector2 ( this string str )
26- {
27- try
28- {
29- var strLength = str . Count ( ) ;
30- if ( strLength < 1 )
31- {
32- throw new Exception ( ) ;
33- }
34- else if ( str [ 0 ] == '<' && str [ strLength - 1 ] == '>' )
35- {
36- str = str . Substring ( 1 , strLength - 2 ) ;
37- }
38-
39- string [ ] values = str . Split ( ',' ) ;
40-
41- var count = values . Count ( ) ;
42- Vector2 vector ;
43-
44- if ( count == 1 )
45- {
46- vector = new Vector2 ( float . Parse ( values [ 0 ] , CultureInfo . InvariantCulture ) ) ;
47- }
48- else if ( count == 2 )
49- {
50- vector = new Vector2 ( float . Parse ( values [ 0 ] , CultureInfo . InvariantCulture ) , float . Parse ( values [ 1 ] , CultureInfo . InvariantCulture ) ) ;
51- }
52- else
53- {
54- throw new Exception ( ) ;
55- }
56-
57- return vector ;
58- }
59- catch ( Exception )
60- {
61- throw new FormatException ( $ "Cannot convert { str } to Vector2. Use format \" float, float\" ") ;
62- }
63- }
64-
65- /// <summary>
66- /// Converts a <see cref="string"/> to <see cref="Vector3"/>
67- /// </summary>
68- /// <param name="str">A string in the format of "float, float, float"</param>
69- /// <returns><see cref="Vector3"/></returns>
70- public static Vector3 ToVector3 ( this string str )
71- {
72- try
73- {
74- var strLength = str . Count ( ) ;
75- if ( strLength < 1 )
76- {
77- throw new Exception ( ) ;
78- }
79- else if ( str [ 0 ] == '<' && str [ strLength - 1 ] == '>' )
80- {
81- str = str . Substring ( 1 , strLength - 2 ) ;
82- }
83-
84- string [ ] values = str . Split ( ',' ) ;
85-
86- var count = values . Count ( ) ;
87- Vector3 vector ;
88-
89- if ( count == 1 )
90- {
91- vector = new Vector3 ( float . Parse ( values [ 0 ] , CultureInfo . InvariantCulture ) ) ;
92- }
93- else if ( count == 3 )
94- {
95- vector = new Vector3 (
96- float . Parse ( values [ 0 ] , CultureInfo . InvariantCulture ) ,
97- float . Parse ( values [ 1 ] , CultureInfo . InvariantCulture ) ,
98- float . Parse ( values [ 2 ] , CultureInfo . InvariantCulture ) ) ;
99- }
100- else
101- {
102- throw new Exception ( ) ;
103- }
104-
105- return vector ;
106- }
107- catch ( Exception )
108- {
109- throw new FormatException ( $ "Cannot convert { str } to Vector3. Use format \" float, float, float\" ") ;
110- }
111- }
112-
113- /// <summary>
114- /// Converts a <see cref="string"/> to <see cref="Vector4"/>
115- /// </summary>
116- /// <param name="str">A string in the format of "float, float, float, float"</param>
117- /// <returns><see cref="Vector4"/></returns>
118- public static Vector4 ToVector4 ( this string str )
119- {
120- try
121- {
122- var strLength = str . Count ( ) ;
123- if ( strLength < 1 )
124- {
125- throw new Exception ( ) ;
126- }
127- else if ( str [ 0 ] == '<' && str [ strLength - 1 ] == '>' )
128- {
129- str = str . Substring ( 1 , strLength - 2 ) ;
130- }
131-
132- string [ ] values = str . Split ( ',' ) ;
133-
134- var count = values . Count ( ) ;
135- Vector4 vector ;
136-
137- if ( count == 1 )
138- {
139- vector = new Vector4 ( float . Parse ( values [ 0 ] , CultureInfo . InvariantCulture ) ) ;
140- }
141- else if ( count == 4 )
142- {
143- vector = new Vector4 (
144- float . Parse ( values [ 0 ] , CultureInfo . InvariantCulture ) ,
145- float . Parse ( values [ 1 ] , CultureInfo . InvariantCulture ) ,
146- float . Parse ( values [ 2 ] , CultureInfo . InvariantCulture ) ,
147- float . Parse ( values [ 3 ] , CultureInfo . InvariantCulture ) ) ;
148- }
149- else
150- {
151- throw new Exception ( ) ;
152- }
153-
154- return vector ;
155- }
156- catch ( Exception )
157- {
158- throw new FormatException ( $ "Cannot convert { str } to Vector4. Use format \" float, float, float, float\" ") ;
159- }
160- }
161-
162- /// <summary>
163- /// Converts a <see cref="string"/> to <see cref="Quaternion"/>
164- /// </summary>
165- /// <param name="str">A string in the format of "float, float, float, float"</param>
166- /// <returns><see cref="Quaternion"/></returns>
167- public static unsafe Quaternion ToQuaternion ( this string str )
168- {
169- Vector4 vector = str . ToVector4 ( ) ;
170-
171- return * ( Quaternion * ) & vector ;
172- }
173-
17417 /// <summary>
17518 /// Retrieves the <see cref="Visual"/> object of a <see cref="UIElement"/>
17619 /// </summary>
0 commit comments