Exemplo n.º 1
0
        public static bool LogicalEquality(Point3D _p1, Point3D _p2, double _tolerance = 0.0001)
        {
            if (_p1 == null && _p2 != null)
            {
                return(false);
            }
            if (_p1 != null && _p2 == null)
            {
                return(false);
            }
            if (_p1 == null && _p2 == null)
            {
                return(true);
            }

            if (!GeometricTransformations.LogicalEquality(_p1.X, _p2.X, _tolerance))
            {
                return(false);
            }
            if (!GeometricTransformations.LogicalEquality(_p1.Y, _p2.Y, _tolerance))
            {
                return(false);
            }
            if (!GeometricTransformations.LogicalEquality(_p1.Z, _p2.Z, _tolerance))
            {
                return(false);
            }

            return(true);
        }
        private static bool LogicalEquality(Dictionary <string, double> _d1, Dictionary <string, double> _d2)
        {
            if (_d1 == null && _d2 != null)
            {
                return(false);
            }
            if (_d1 != null && _d2 == null)
            {
                return(false);
            }
            if (_d1 == null && _d2 == null)
            {
                return(true);
            }

            int nrD1 = _d1.Count;

            if (nrD1 != _d2.Count)
            {
                return(false);
            }

            List <string> d1_keys   = _d1.OrderBy(x => x.Key).Select(x => x.Key).ToList();
            List <string> d2_keys   = _d2.OrderBy(x => x.Key).Select(x => x.Key).ToList();
            bool          same_keys = d1_keys.SequenceEqual(d2_keys);

            if (!same_keys)
            {
                return(false);
            }

            List <double> d1_values   = _d1.OrderBy(x => x.Key).Select(x => x.Value).ToList();
            List <double> d2_values   = _d2.OrderBy(x => x.Key).Select(x => x.Value).ToList();
            bool          same_values = d1_values.Zip(d2_values, (x, y) => GeometricTransformations.LogicalEquality(x, y)).Aggregate(true, (a, x) => a && x);

            if (!same_values)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        public static bool LogicalEquality(Matrix3D _m1, Matrix3D _m2, double _tolerance = 0.0001)
        {
            if (_m1 == null && _m2 == null)
            {
                return(true);
            }
            if (_m1 != null && _m2 == null)
            {
                return(false);
            }
            if (_m1 == null && _m2 != null)
            {
                return(false);
            }

            if (!(GeometricTransformations.LogicalEquality(_m1.M11, _m2.M11, _tolerance)))
            {
                return(false);
            }
            if (!(GeometricTransformations.LogicalEquality(_m1.M12, _m2.M12, _tolerance)))
            {
                return(false);
            }
            if (!(GeometricTransformations.LogicalEquality(_m1.M13, _m2.M13, _tolerance)))
            {
                return(false);
            }
            if (!(GeometricTransformations.LogicalEquality(_m1.M14, _m2.M14, _tolerance)))
            {
                return(false);
            }

            if (!(GeometricTransformations.LogicalEquality(_m1.M21, _m2.M21, _tolerance)))
            {
                return(false);
            }
            if (!(GeometricTransformations.LogicalEquality(_m1.M22, _m2.M22, _tolerance)))
            {
                return(false);
            }
            if (!(GeometricTransformations.LogicalEquality(_m1.M23, _m2.M23, _tolerance)))
            {
                return(false);
            }
            if (!(GeometricTransformations.LogicalEquality(_m1.M24, _m2.M24, _tolerance)))
            {
                return(false);
            }

            if (!(GeometricTransformations.LogicalEquality(_m1.M31, _m2.M31, _tolerance)))
            {
                return(false);
            }
            if (!(GeometricTransformations.LogicalEquality(_m1.M32, _m2.M32, _tolerance)))
            {
                return(false);
            }
            if (!(GeometricTransformations.LogicalEquality(_m1.M33, _m2.M33, _tolerance)))
            {
                return(false);
            }
            if (!(GeometricTransformations.LogicalEquality(_m1.M34, _m2.M34, _tolerance)))
            {
                return(false);
            }


            if (!(GeometricTransformations.LogicalEquality(_m1.OffsetX, _m2.OffsetX, _tolerance)))
            {
                return(false);
            }
            if (!(GeometricTransformations.LogicalEquality(_m1.OffsetY, _m2.OffsetY, _tolerance)))
            {
                return(false);
            }
            if (!(GeometricTransformations.LogicalEquality(_m1.OffsetZ, _m2.OffsetZ, _tolerance)))
            {
                return(false);
            }
            if (!(GeometricTransformations.LogicalEquality(_m1.M44, _m2.M44, _tolerance)))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
 public void MoveAlongUCSz(double _amount)
 {
     // this.gr_ucs.OffsetZ += _amount; // wrong
     GeometricTransformations.TranslateMatrixAlongZ(ref this.gr_ucs, _amount);
 }
Exemplo n.º 5
0
        /// <summary>
        /// <para>This method compares two geometric relationships according to content, NOT id or name.</para>
        /// <para>The transformation matrices are not being compared for now...</para>
        /// </summary>
        /// <param name="_gr1"></param>
        /// <param name="_gr2"></param>
        /// <returns></returns>
        public static bool HaveSameContent(GeometricRelationship _gr1, GeometricRelationship _gr2)
        {
            if (_gr1 == null && _gr2 == null)
            {
                return(true);
            }
            if (_gr1 == null && _gr2 != null)
            {
                return(false);
            }
            if (_gr1 != null && _gr2 == null)
            {
                return(false);
            }

            if (_gr1.gr_state.Type != _gr2.gr_state.Type)
            {
                return(false);
            }
            if (_gr1.gr_state.IsRealized != _gr2.gr_state.IsRealized)
            {
                return(false);
            }

            if (_gr1.gr_ids.X != _gr2.gr_ids.X || _gr1.gr_ids.Y != _gr2.gr_ids.Y || _gr1.gr_ids.Z != _gr2.gr_ids.Z)
            {
                return(false);
            }

            // if (_gr1.gr_ucs != _gr2.gr_ucs) return false; // checks for EXACT equality -> NaN and rounding errors can lead to false negatives
            if (!GeometricTransformations.LogicalEquality(_gr1.gr_ucs, _gr2.gr_ucs))
            {
                return(false);
            }

            // skipping transformation matrices for now...

            if (_gr1.inst_size == null && _gr2.inst_size != null)
            {
                return(false);
            }
            if (_gr1.inst_size != null && _gr2.inst_size == null)
            {
                return(false);
            }
            if (_gr1.inst_size != null && _gr2.inst_size != null)
            {
                int nrSize = _gr1.inst_size.Count;
                if (nrSize != _gr2.inst_size.Count)
                {
                    return(false);
                }

                if (nrSize > 0)
                {
                    bool same_size = _gr1.inst_size.SequenceEqual(_gr2.inst_size);
                    if (!same_size)
                    {
                        return(false);
                    }
                }
            }

            if (_gr1.inst_nwe_id != _gr2.inst_nwe_id)
            {
                return(false);
            }
            if (_gr1.inst_nwe_name != _gr2.inst_nwe_name)
            {
                return(false);
            }

            if (_gr1.inst_path == null && _gr2.inst_path != null)
            {
                return(false);
            }
            if (_gr1.inst_path != null && _gr2.inst_path == null)
            {
                return(false);
            }
            if (_gr1.inst_path != null && _gr2.inst_path != null)
            {
                int nrPathP = _gr1.inst_path.Count;
                if (nrPathP != _gr2.inst_path.Count)
                {
                    return(false);
                }

                if (nrPathP > 0)
                {
                    bool same_path = _gr1.inst_path.Zip(_gr2.inst_path, (x, y) => GeometricTransformations.LogicalEquality(x, y)).Aggregate(true, (a, x) => a && x);
                    if (!same_path)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }