From 89a1a9c5f3e2fb51471a6c78d71632f69d3629f7 Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Wed, 22 Apr 2020 14:05:11 +0200 Subject: [PATCH] Adding comparers for Contraints4DOF and 6DOF --- .../Constraint4DOFComparer.cs | 77 ++++++++++++++++++ .../Constraint6DOFComparer.cs | 80 +++++++++++++++++++ Structure_Engine/Structure_Engine.csproj | 2 + 3 files changed, 159 insertions(+) create mode 100644 Structure_Engine/Objects/EqualityComparers/Constraint4DOFComparer.cs create mode 100644 Structure_Engine/Objects/EqualityComparers/Constraint6DOFComparer.cs diff --git a/Structure_Engine/Objects/EqualityComparers/Constraint4DOFComparer.cs b/Structure_Engine/Objects/EqualityComparers/Constraint4DOFComparer.cs new file mode 100644 index 000000000..7b76cb4ef --- /dev/null +++ b/Structure_Engine/Objects/EqualityComparers/Constraint4DOFComparer.cs @@ -0,0 +1,77 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + + +using BH.oM.Structure.Constraints; +using System.Collections.Generic; +using System; + +namespace BH.Engine.Structure +{ + public class Constraint4DOFComparer : IEqualityComparer + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + public bool Equals(Constraint4DOF linearRelease1, Constraint4DOF linearRelease2) + { + //Check whether the compared objects reference the same data. + if (Object.ReferenceEquals(linearRelease1, linearRelease2)) + return true; + + //Check whether any of the compared objects is null. + if (Object.ReferenceEquals(linearRelease1, null) || Object.ReferenceEquals(linearRelease2, null)) + return false; + + //Check if the GUIDs are the same + if (linearRelease1.BHoM_Guid == linearRelease2.BHoM_Guid) + return true; + + if (linearRelease1.Name == linearRelease2.Name && + linearRelease1.TranslationX == linearRelease2.TranslationX && + linearRelease1.TranslationY == linearRelease2.TranslationY && + linearRelease1.TranslationZ == linearRelease2.TranslationZ && + linearRelease1.RotationX == linearRelease2.RotationX && + linearRelease1.TranslationalStiffnessX == linearRelease2.TranslationalStiffnessX && + linearRelease1.TranslationalStiffnessY == linearRelease2.TranslationalStiffnessY && + linearRelease1.TranslationalStiffnessZ == linearRelease2.TranslationalStiffnessZ && + linearRelease1.RotationalStiffnessX == linearRelease2.RotationalStiffnessX) + return true; + + return false; + } + + /***************************************************/ + + public int GetHashCode(Constraint4DOF obj) + { + //Check whether the object is null + if (Object.ReferenceEquals(obj, null)) return 0; + + return obj.Name == null ? 0 : obj.Name.GetHashCode(); + } + + /***************************************************/ + } +} + diff --git a/Structure_Engine/Objects/EqualityComparers/Constraint6DOFComparer.cs b/Structure_Engine/Objects/EqualityComparers/Constraint6DOFComparer.cs new file mode 100644 index 000000000..6f5aeca61 --- /dev/null +++ b/Structure_Engine/Objects/EqualityComparers/Constraint6DOFComparer.cs @@ -0,0 +1,80 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + + +using BH.oM.Structure.Constraints; +using System.Collections.Generic; +using System; + +namespace BH.Engine.Structure +{ + public class Constraint6DOFComparer : IEqualityComparer + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + public bool Equals(Constraint6DOF support1, Constraint6DOF support2) + { + //Check whether the compared objects reference the same data. + if (Object.ReferenceEquals(support1, support2)) + return true; + + //Check whether any of the compared objects is null. + if (Object.ReferenceEquals(support1, null) || Object.ReferenceEquals(support2, null)) + return false; + + //Check if the GUIDs are the same + if (support1.BHoM_Guid == support2.BHoM_Guid) + return true; + + if (support1.Name == support2.Name && + support1.TranslationX == support2.TranslationX && + support1.TranslationY == support2.TranslationY && + support1.TranslationZ == support2.TranslationZ && + support1.RotationX == support2.RotationX && + support1.RotationY == support2.RotationY && + support1.RotationZ == support2.RotationZ && + support1.TranslationalStiffnessX == support2.TranslationalStiffnessX && + support1.TranslationalStiffnessY == support2.TranslationalStiffnessY && + support1.TranslationalStiffnessZ == support2.TranslationalStiffnessZ && + support1.RotationalStiffnessX == support2.RotationalStiffnessX && + support1.RotationalStiffnessY == support2.RotationalStiffnessY && + support1.RotationalStiffnessZ == support2.RotationalStiffnessZ) + return true; + return false; + } + + /***************************************************/ + + public int GetHashCode(Constraint6DOF obj) + { + //Check whether the object is null + if (Object.ReferenceEquals(obj, null)) return 0; + + return obj.Name == null ? 0 : obj.Name.GetHashCode(); + } + + /***************************************************/ + } +} + diff --git a/Structure_Engine/Structure_Engine.csproj b/Structure_Engine/Structure_Engine.csproj index 8e7954d20..06f33c892 100644 --- a/Structure_Engine/Structure_Engine.csproj +++ b/Structure_Engine/Structure_Engine.csproj @@ -121,6 +121,8 @@ + +