From ebfd5a8af07bc5fdf5b463714d8030e49eac53ba Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 1 Apr 2021 22:08:01 -0700 Subject: Add differing table types --- grapher/Models/Serialized/LookupTable.cs | 57 +++++++++++--------------------- 1 file changed, 20 insertions(+), 37 deletions(-) (limited to 'grapher/Models/Serialized/LookupTable.cs') diff --git a/grapher/Models/Serialized/LookupTable.cs b/grapher/Models/Serialized/LookupTable.cs index 578c5bf..d373461 100644 --- a/grapher/Models/Serialized/LookupTable.cs +++ b/grapher/Models/Serialized/LookupTable.cs @@ -10,32 +10,9 @@ using System.Threading.Tasks; namespace grapher.Models.Serialized { [Serializable] - public class LookupTable + public static class LookupTable { - [Serializable] - public class Point - { - public Point(double x, double y) - { - X = x; - Y = y; - } - - double X { get; set; } - - double Y { get; set; } - } - - public LookupTable(Point[] points) - { - Points = points; - } - - public Point[] Points { get; } - - public bool InSensGraph { get; } - - public static LookupTable Deserialize(string lutFile) + public static void Deserialize(string lutFile, ref DriverSettings settings) { if (!File.Exists(lutFile)) { @@ -44,23 +21,29 @@ namespace grapher.Models.Serialized JObject lutJObject = JObject.Parse(File.ReadAllText(lutFile)); - var lut = lutJObject.ToObject(JsonSerializer.Create(RawAccelSettings.SerializerSettings)); + var spacedLut = lutJObject.ToObject(JsonSerializer.Create(RawAccelSettings.SerializerSettings)); - if (lut is null || lut.Points is null) + if (spacedLut is null) { - throw new Exception($"{lutFile} does not contain valid lookuptable json."); - } + var arbitraryLut = lutJObject.ToObject(JsonSerializer.Create(RawAccelSettings.SerializerSettings)); - lut.Verify(); + if (arbitraryLut is null || arbitraryLut.points is null) + { + throw new Exception($"{lutFile} does not contain valid lookuptable json."); + } - return lut; - } - - private void Verify() - { - if (Points.Length >= short.MaxValue) + settings.ArbitraryTable = arbitraryLut; + settings.args.x.lutArgs.type = TableType.arbitrary; + } + else { - throw new Exception($"LUT file with {Points.Length} points is too long. Max points: {short.MaxValue}"); + if (spacedLut.points is null) + { + throw new Exception($"{lutFile} does not contain valid lookuptable json."); + } + + settings.SpacedTable = spacedLut; + settings.args.x.lutArgs = spacedLut.args; } } } -- cgit v1.2.3