Changeset 17266 for branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/ValueTypeMatrixTransformer.cs
- Timestamp:
- 09/20/19 16:23:42 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/ValueTypeMatrixTransformer.cs
r17263 r17266 8 8 using HeuristicLab.Core; 9 9 10 namespace ParameterTest{10 namespace HeuristicLab.Manufacture { 11 11 public class ValueTypeMatrixTransformer<MatrixType, T> : BaseTransformer 12 12 where MatrixType : ValueTypeMatrix<T> 13 13 where T : struct 14 14 { 15 public override IItem FromData(ParameterData obj, Type targetType) { 16 /*T[,] arr = CastValue<T[,]>(obj.Default); 17 MatrixType matrix = item.Cast<MatrixType>(); 18 for (int x = 0; x < arr.GetLength(0); ++x){ 19 for (int y = 0; y < arr.GetLength(1); ++y) { 20 matrix[x, y] = arr[x, y]; 21 } 22 }*/ 23 return Instantiate<MatrixType>(CastValue<T[,]>(obj.Default)); 24 } 15 public override void InjectData(IItem item, ParameterData data) => 16 CopyMatrixData(item.Cast<MatrixType>(), CastValue<T[,]>(data.Default)); 25 17 26 public override void SetValue(IItem item, ParameterData data) { 27 T[,] arr = CastValue<T[,]>(data.Default); 28 MatrixType matrix = item.Cast<MatrixType>(); 29 for (int x = 0; x < arr.GetLength(0); ++x) { 30 for (int y = 0; y < arr.GetLength(1); ++y) { 31 matrix[x, y] = arr[x, y]; 18 public override ParameterData ExtractData(IItem value) => 19 new ParameterData() { 20 Default = value.Cast<MatrixType>().CloneAsMatrix() 21 }; 22 23 #region Helper 24 private void CopyMatrixData(MatrixType matrix, T[,] data) { 25 for (int x = 0; x < data.GetLength(0); ++x) { 26 for (int y = 0; y < data.GetLength(1); ++y) { 27 matrix[x, y] = data[x, y]; 32 28 } 33 29 } 34 30 } 35 36 public override ParameterData ToData(IItem value) { 37 ParameterData data = base.ToData(value); 38 data.Default = value.Cast<MatrixType>().CloneAsMatrix(); 39 return data; 40 } 31 #endregion 41 32 } 42 33 }
Note: See TracChangeset
for help on using the changeset viewer.