78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Thermo.Active.Model.DTOModels
|
|
{
|
|
public class DTOAxesModel
|
|
{
|
|
public Dictionary<string, double> interpolated;
|
|
public Dictionary<string, double> machine;
|
|
public Dictionary<string, double> programmePos;
|
|
public Dictionary<string, double> toGo;
|
|
public Dictionary<string, double> followingErr;
|
|
|
|
public DTOAxesModel()
|
|
{
|
|
interpolated = new Dictionary<string, double>();
|
|
machine = new Dictionary<string, double>();
|
|
programmePos = new Dictionary<string, double>();
|
|
toGo = new Dictionary<string, double>();
|
|
}
|
|
|
|
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<string, double> x, IDictionary<string, double> 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;
|
|
}
|
|
}
|
|
} |