using System; using System.Collections.Generic; using System.Linq; namespace Step.Model.DTOModels { public class DTOAxesModel { public Dictionary interpolated; public Dictionary machine; public Dictionary programmePos; public Dictionary toGo; public Dictionary followingErr; public DTOAxesModel() { interpolated = new Dictionary(); machine = new Dictionary(); programmePos = new Dictionary(); toGo = new Dictionary(); } public struct AxisModel { public string name; public double value; } public override bool Equals(object obj) { if (!(obj is DTOAxesModel item)) return false; if (!CheckAxesDictionaries(interpolated, item.interpolated)) return false; if (!CheckAxesDictionaries(machine, item.machine)) return false; if (!CheckAxesDictionaries(programmePos , item.programmePos)) return false; if (!CheckAxesDictionaries(toGo, item.toGo)) return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } private bool CheckAxesDictionaries(IDictionary x, IDictionary y) { // early-exit checks if (y == null) return x == null; if (x == null) return false; if (x.Count != y.Count) return false; // Check keys are the same foreach (string k in x.Keys) if (!y.ContainsKey(k)) return false; // Check values are differen foreach (string k in x.Keys) { double a = Math.Abs(y[k] - x[k]); if (Math.Round(a, 3) >= Constants.EPSILON) return false; } return true; } } }