| | 1 | | using System.Collections.Generic; |
| | 2 | |
|
| | 3 | | namespace Morpho25.Geometry |
| | 4 | | { |
| | 5 | | /// <summary> |
| | 6 | | /// Matrix 2D class. |
| | 7 | | /// </summary> |
| | 8 | | public class Matrix2d |
| | 9 | | { |
| | 10 | | private readonly string[,] _values; |
| | 11 | |
|
| | 12 | | /// <summary> |
| | 13 | | /// Get a value. |
| | 14 | | /// </summary> |
| | 15 | | /// <param name="x">X index.</param> |
| | 16 | | /// <param name="y">Y index.</param> |
| | 17 | | /// <returns>Value.</returns> |
| | 18 | | public string this[int x, int y] |
| | 19 | | { |
| 3 | 20 | | get { return _values[x, y]; } |
| 3 | 21 | | set { _values[x, y] = value; } |
| | 22 | | } |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Create a new Matrix 2D. |
| | 26 | | /// </summary> |
| | 27 | | /// <param name="x">Size in X.</param> |
| | 28 | | /// <param name="y">Size in Y.</param> |
| 0 | 29 | | public Matrix2d(int x, int y) |
| 0 | 30 | | { |
| 0 | 31 | | _values = new string[x, y]; |
| 0 | 32 | | } |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Create a new Matrix 2D. |
| | 36 | | /// </summary> |
| | 37 | | /// <param name="x">Size in X.</param> |
| | 38 | | /// <param name="y">Size in Y.</param> |
| | 39 | | /// <param name="value">Default value to use.</param> |
| 1 | 40 | | public Matrix2d(int x, int y, string value) |
| 1 | 41 | | { |
| 1 | 42 | | _values = new string[x, y]; |
| 22 | 43 | | for (int i = 0; i < x; i++) |
| 220 | 44 | | for (int j = 0; j < y; j++) |
| 100 | 45 | | { |
| 100 | 46 | | _values[i, j] = value; |
| 100 | 47 | | } |
| 1 | 48 | | } |
| | 49 | | /// <summary> |
| | 50 | | /// Get X size. |
| | 51 | | /// </summary> |
| | 52 | | /// <returns>X size.</returns> |
| | 53 | | public int GetLengthX() |
| 1 | 54 | | { |
| 1 | 55 | | return _values.GetLength(0); |
| 1 | 56 | | } |
| | 57 | | /// <summary> |
| | 58 | | /// Get Y size. |
| | 59 | | /// </summary> |
| | 60 | | /// <returns>Y size.</returns> |
| | 61 | | public int GetLengthY() |
| 1 | 62 | | { |
| 1 | 63 | | return _values.GetLength(1); |
| 1 | 64 | | } |
| | 65 | | /// <summary> |
| | 66 | | /// Merge multiple Matrix 2D matrix. |
| | 67 | | /// </summary> |
| | 68 | | /// <param name="matrixList">Collection of matrix to merge.</param> |
| | 69 | | /// <param name="mask">Value to use for merging.</param> |
| | 70 | | /// <returns></returns> |
| | 71 | | public static Matrix2d MergeMatrix(List<Matrix2d> matrixList, |
| | 72 | | string mask) |
| 0 | 73 | | { |
| 0 | 74 | | Matrix2d result = new Matrix2d(matrixList[0].GetLengthX(), |
| 0 | 75 | | matrixList[0].GetLengthY(), mask); |
| | 76 | |
|
| 0 | 77 | | foreach (Matrix2d matrix in matrixList) |
| 0 | 78 | | { |
| 0 | 79 | | for (int i = 0; i < matrix.GetLengthX(); i++) |
| 0 | 80 | | { |
| 0 | 81 | | for (int j = 0; j < matrix.GetLengthY(); j++) |
| 0 | 82 | | { |
| 0 | 83 | | if (matrix[i, j] != mask) |
| 0 | 84 | | { |
| 0 | 85 | | result[i, j] = matrix[i, j]; |
| 0 | 86 | | } |
| 0 | 87 | | } |
| 0 | 88 | | } |
| 0 | 89 | | } |
| 0 | 90 | | return result; |
| 0 | 91 | | } |
| | 92 | | } |
| | 93 | | } |