Jypeli 10
The simple game programming library
MatrixHelper.cs
Siirry tämän tiedoston dokumentaatioon.
1#region MIT License
2/*
3 * Copyright (c) 2005-2008 Jonathan Mark Porter. http://physics2d.googlepages.com/
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22#endregion
23
24
25
26
27#if UseDouble
28using Scalar = System.Double;
29#else
30using Scalar = System.Single;
31#endif
32using System;
33
34using System.Text;
35namespace AdvanceMath
36{
37 internal static class MatrixHelper
38 {
39 public static string CreateMatrixFormatString(int RowCount, int ColumnCount)
40 {
41 return CreateFormatString(RowCount, ColumnCount, "|", "|\n", "", 1);
42 }
43 public static string CreateMatrixFormatableString(int RowCount, int ColumnCount)
44 {
45 return CreateFormatableString(RowCount, ColumnCount, "|", "|\n", "", 1);
46 }
47 public static string CreateVectorFormatString(int Count)
48 {
49 return CreateFormatString(1, Count, "(", ")", ",", 1);
50 }
51 public static string CreateVectorFormatableString(int Count)
52 {
53 return CreateFormatableString(1, Count, "(", ")", ",", 1);
54 }
55
56 public static string CreateFormatableString(
57 int rowCount, int columnCount,
58 string leftParenth, string rightParenth,
59 string divider, int whitespacecount)
60 {
61 return GenerateFormatStringInternal(rowCount, columnCount, leftParenth, rightParenth, divider,whitespacecount, "{{", ":{0}}}");
62 }
63 public static string CreateFormatString(
64 int rowCount, int columnCount,
65 string leftParenth, string rightParenth,
66 string divider, int whitespacecount)
67 {
68 return GenerateFormatStringInternal(rowCount, columnCount, leftParenth, rightParenth,divider, whitespacecount, "{", "}");
69 }
70 private static string GenerateFormatStringInternal(
71 int rowCount, int columnCount,
72 string leftParenth, string rightParenth,
73 string divider, int whitespacecount,
74 string openBracket, string closeBracket)
75 {
76 StringBuilder builder = new StringBuilder(
77 rowCount * (leftParenth.Length + rightParenth.Length) +
78 rowCount * columnCount * (1 + divider.Length + openBracket.Length + closeBracket.Length + whitespacecount));
79
80 int index = 0;
81 for (int row = 0; row < rowCount; ++row)
82 {
83 builder.Append(leftParenth);
84 builder.Append(' ', whitespacecount);
85 for (int col = 0; col < columnCount; ++col)
86 {
87 builder.Append(openBracket);
88 builder.Append(index);
89 builder.Append(closeBracket);
90 if (col != columnCount - 1)
91 {
92 builder.Append(divider);
93 }
94 builder.Append(' ', whitespacecount);
95 index++;
96 }
97 builder.Append(rightParenth);
98 }
99 return builder.ToString();
100 }
101
102
103
104
105
106 }
107}
System.Single Scalar
Definition: Clamped.cs:29
static string GenerateFormatStringInternal(int rowCount, int columnCount, string leftParenth, string rightParenth, string divider, int whitespacecount, string openBracket, string closeBracket)
Definition: MatrixHelper.cs:70
static string CreateMatrixFormatableString(int RowCount, int ColumnCount)
Definition: MatrixHelper.cs:43
static string CreateMatrixFormatString(int RowCount, int ColumnCount)
Definition: MatrixHelper.cs:39
static string CreateFormatString(int rowCount, int columnCount, string leftParenth, string rightParenth, string divider, int whitespacecount)
Definition: MatrixHelper.cs:63
static string CreateVectorFormatableString(int Count)
Definition: MatrixHelper.cs:51
static string CreateVectorFormatString(int Count)
Definition: MatrixHelper.cs:47
static string CreateFormatableString(int rowCount, int columnCount, string leftParenth, string rightParenth, string divider, int whitespacecount)
Definition: MatrixHelper.cs:56