-
Notifications
You must be signed in to change notification settings - Fork 4
Vector2<T> #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vector2<T> #1
Changes from 5 commits
234f571
2cf57ef
afd0161
8b54d95
20f979c
a75a07a
4e78495
9cdd39d
9793b3f
2c48437
9e56df3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| private string[] TestTypes = new[] | ||
tannergooding marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| "Vector", | ||
| "Matrix3x2", | ||
| "Matrix4x4", | ||
| "Quaternion", | ||
| "Plane" | ||
| }; | ||
|
|
||
| private string[][] SupportedTypes = new[] | ||
| { | ||
| new[] { "Single", "f" }, | ||
| new[] { "Double", "d" } | ||
| }; | ||
|
|
||
| void TestSingleType(string type) | ||
| { | ||
| if (type == "Vector") | ||
| { | ||
| TestVector(); | ||
| return; | ||
| } | ||
|
|
||
| var file = type + ".template"; | ||
|
|
||
| var templatedText = ReadFile(file); | ||
|
|
||
| GenerateFilesForSupportedType(type, templatedText); | ||
| } | ||
|
|
||
| void TestVector() | ||
| { | ||
| string shared = ReadFile("Vector_All.template"); | ||
|
|
||
| for (var i = 2; i <= 4; i++) | ||
| { | ||
| var arifiedVector = "Vector" + i.ToString(); | ||
|
|
||
| var specific = ReadFile(arifiedVector + ".template").Split('\n'); | ||
| var correct = new StringBuilder(specific.Length); | ||
|
|
||
| // these add indenting to lines which need it | ||
| Console.WriteLine(specific.Length); | ||
| foreach (var line in specific) | ||
| { | ||
| if (!string.IsNullOrWhiteSpace(line)) | ||
| { | ||
| correct.AppendLine(" " + line); | ||
| } | ||
| else | ||
| { | ||
| correct.AppendLine(line); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| var withShared = shared.Replace("{Specifics}", correct.ToString()); | ||
| GenerateFilesForSupportedType(arifiedVector, withShared); | ||
| } | ||
| } | ||
|
|
||
| void GenerateFilesForSupportedType(string typename, string template) | ||
| { | ||
| // Handle non-generic type first | ||
| var nonGenericText = template.Replace("{TestType}", typename); | ||
| nonGenericText = nonGenericText.Replace("{ScalarType}", "Single"); | ||
| nonGenericText = nonGenericText.Replace("{ScalarSuffix}", "f"); | ||
| nonGenericText = nonGenericText.Replace("{AssignX}", ".X = "); // non generic doesn't have With methods | ||
|
|
||
| nonGenericText = nonGenericText.Replace("{GenericSpecific}", ""); | ||
|
|
||
| WriteToTestFile(typename, nonGenericText); | ||
|
|
||
| var genericFile = typename + "_Generic.template"; | ||
|
|
||
| var genericTemplate = template.Replace("{GenericSpecific}", File.Exists(genericFile) ? ReadFile(genericFile) : ""); | ||
|
|
||
| foreach (var supportedType in SupportedTypes) | ||
| { | ||
| // this means we can blindly change everything, including method names (as < and > are not allowed in them) | ||
| // namespace as we put this riiight at the start of the file, before the using | ||
| var alias = typename + supportedType[0]; | ||
| var usingAlias = $"using {alias} = System.Numerics.{typename}<System.{supportedType[0]}>;{Environment.NewLine}"; | ||
| var genericType = typename + '<' + supportedType[0] + '>'; | ||
|
|
||
| var genericText = usingAlias + genericTemplate.Replace("{TestType}", alias); | ||
|
|
||
| genericText = genericText.Replace("{ScalarType}", supportedType[0]); | ||
| genericText = genericText.Replace("{ScalarSuffix}", supportedType[1]); | ||
| genericText = genericText.Replace("{AssignX}", " = b.WithX"); // generic uses with methods | ||
|
|
||
| WriteToTestFile(typename + "_" + supportedType[0], genericText); | ||
| } | ||
| } | ||
|
|
||
| string ReadFile(string name) | ||
| { | ||
| string license = "{EndLicense}"; | ||
| string text = File.ReadAllText(name); | ||
| var ind = text.IndexOf(license); | ||
| if (ind != -1) | ||
| { | ||
| text = text.Substring(ind + license.Length); | ||
| } | ||
| return text; | ||
| } | ||
|
|
||
| void WriteToTestFile(string file, string text) | ||
| { | ||
| File.WriteAllText(Path.Combine("Test", file + "Tests.cs"), text); | ||
| } | ||
|
|
||
| foreach (var type in TestTypes) | ||
| { | ||
| TestSingleType(type); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
| {EndLicense} | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
| {EndLicense} | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
| {EndLicense} | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
| {EndLicense} | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| using Matrix3x2Double = System.Numerics.Matrix3x2<System.Double>; | ||
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| using Matrix3x2Single = System.Numerics.Matrix3x2<System.Single>; | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| using Matrix4x4Double = System.Numerics.Matrix4x4<System.Double>; | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| using Matrix4x4Single = System.Numerics.Matrix4x4<System.Single>; | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| using PlaneDouble = System.Numerics.Plane<System.Double>; | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| using PlaneSingle = System.Numerics.Plane<System.Single>; | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| using QuaternionDouble = System.Numerics.Quaternion<System.Double>; | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| using QuaternionSingle = System.Numerics.Quaternion<System.Single>; | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to need to be autogenerated via the ref assembly generator. Won't block on this though.