1 //
2 // Copyright (c) 2010-2022 Antmicro
3 //
4 // This file is licensed under the MIT License.
5 // Full license text is available in 'licenses/MIT.txt'.
6 //
7 
8 using System.Collections.Generic;
9 using System.Globalization;
10 
11 namespace Antmicro.Renode.Peripherals.Sensors
12 {
13     public class Vector3DSample : SensorSample
14     {
Vector3DSample()15         public Vector3DSample()
16         {
17         }
18 
Vector3DSample(decimal x, decimal y, decimal z)19         public Vector3DSample(decimal x, decimal y, decimal z)
20         {
21             X = x;
22             Y = y;
23             Z = z;
24         }
25 
Load(IList<decimal> data)26         public override void Load(IList<decimal> data)
27         {
28             if(data.Count != Dimensions)
29             {
30                 throw new Exceptions.RecoverableException($"Tried to create a {Dimensions}-dimensional Vector3DSample using {data.Count} values");
31             }
32 
33             X = data[0];
34             Y = data[1];
35             Z = data[2];
36         }
37 
TryLoad(params string[] data)38         public override bool TryLoad(params string[] data)
39         {
40             var x = 0m;
41             var y = 0m;
42             var z = 0m;
43 
44             var result = data.Length == 3
45                     && decimal.TryParse(data[0], NumberStyles.Any, CultureInfo.InvariantCulture, out x)
46                     && decimal.TryParse(data[1], NumberStyles.Any, CultureInfo.InvariantCulture, out y)
47                     && decimal.TryParse(data[2], NumberStyles.Any, CultureInfo.InvariantCulture, out z);
48 
49             X = x;
50             Y = y;
51             Z = z;
52 
53             return result;
54         }
55 
ToString()56         public override string ToString()
57         {
58             return $"[X: {X}, Y: {Y}, Z: {Z}]";
59         }
60 
61         public decimal X { get; set; }
62         public decimal Y { get; set; }
63         public decimal Z { get; set; }
64 
65         public const int Dimensions = 3;
66     }
67 }
68