Example #1
0
        public void Test_IEquatable()
        {
            PointD first  = new PointD(50.0);
            PointD second = new PointD(50);

            Assert.IsTrue(first == second);
            Assert.IsTrue(first.Equals(second));
            Assert.IsTrue(first.Equals((object)second));
        }
Example #2
0
    public void Test_IEquatable()
    {
      PointD first = new PointD(50.0);
      PointD second = new PointD(50);

      Assert.IsTrue(first == second);
      Assert.IsTrue(first.Equals(second));
      Assert.IsTrue(first.Equals((object)second));
    }
Example #3
0
            public void ShouldReturnTrueWhenInstanceIsEqual()
            {
                var first  = new PointD(50.0);
                var second = new PointD(50);

                Assert.True(first.Equals(second));
            }
Example #4
0
            public void ShouldReturnTrueWhenObjectIsEqual()
            {
                var first  = new PointD(50.0);
                var second = new PointD(50);

                Assert.True(first.Equals((object)second));
            }
Example #5
0
            public void ShouldReturnFalseWhenInstanceIsNotEqual()
            {
                var first  = new PointD(50);
                var second = new PointD(42);

                Assert.False(first.Equals(second));
            }
Example #6
0
            public void ShouldReturnFalseWhenObjectIsNotEqual()
            {
                var first  = new PointD(50);
                var second = new PointD(42);

                Assert.False(first.Equals((object)second));
            }
        public void Epsilon()
        {
            LineD[] lines   = new LineD[] { new LineD(0, 2, 5, 2), new LineD(3, 2.1, 5, 4) };
            var     results = FindBoth(lines);

            Assert.AreEqual(0, results.Length);
            results = MultiLineIntersection.FindSimple(lines, 1.0);
            Assert.AreEqual(1, results.Length);

            var result = results[0];

            Assert.IsTrue(PointD.Equals(new PointD(3, 2), result.Shared, 1.0));
            Assert.AreEqual(2, result.Lines.Length);
            Assert.AreEqual(0, result.Lines[0]);
            Assert.AreEqual(LineLocation.Between, result.Locations[0]);
            Assert.AreEqual(1, result.Lines[1]);
            Assert.AreEqual(LineLocation.Start, result.Locations[1]);

            lines   = new LineD[] { new LineD(3, 1, 1, 1), new LineD(1, 1.1, 3, 3), new LineD(1, 0.9, 3, -2) };
            results = FindBoth(lines);
            Assert.AreEqual(0, results.Length);
            results = MultiLineIntersection.FindSimple(lines, 1.0);
            Assert.AreEqual(1, results.Length);

            result = results[0];
            Assert.IsTrue(PointD.Equals(new PointD(1, 1), result.Shared, 1.0));
            Assert.AreEqual(3, result.Lines.Length);
            Assert.AreEqual(0, result.Lines[0]);
            Assert.AreEqual(LineLocation.End, result.Locations[0]);
            Assert.AreEqual(1, result.Lines[1]);
            Assert.AreEqual(LineLocation.Start, result.Locations[1]);
            Assert.AreEqual(2, result.Lines[2]);
            Assert.AreEqual(LineLocation.Start, result.Locations[1]);
        }
Example #8
0
        public void IntersectDivergent()
        {
            var result = new LineD(0, 0, 1, 1).Intersect(new LineD(1, 1, 2, 0));

            Assert.IsTrue(PointD.Equals(new PointD(1, 1), result.Shared.Value, 0.01));
            Assert.AreEqual(LineLocation.End, result.First);
            Assert.AreEqual(LineLocation.Start, result.Second);
            Assert.AreEqual(LineRelation.Divergent, result.Relation);

            result = new LineD(1, 1, 0, 0).Intersect(new LineD(2, 0, 1, 1));
            Assert.IsTrue(PointD.Equals(new PointD(1, 1), result.Shared.Value, 0.01));
            Assert.AreEqual(LineLocation.Start, result.First);
            Assert.AreEqual(LineLocation.End, result.Second);
            Assert.AreEqual(LineRelation.Divergent, result.Relation);

            result = new LineD(0, 0, 2, 2).Intersect(new LineD(1, 1, 2, 0));
            Assert.IsTrue(PointD.Equals(new PointD(1, 1), result.Shared.Value, 0.01));
            Assert.AreEqual(LineLocation.Between, result.First);
            Assert.AreEqual(LineLocation.Start, result.Second);
            Assert.AreEqual(LineRelation.Divergent, result.Relation);

            result = new LineD(0, 0, 1, 1).Intersect(new LineD(0, 2, 2, 0));
            Assert.IsTrue(PointD.Equals(new PointD(1, 1), result.Shared.Value, 0.01));
            Assert.AreEqual(LineLocation.End, result.First);
            Assert.AreEqual(LineLocation.Between, result.Second);
            Assert.AreEqual(LineRelation.Divergent, result.Relation);

            result = new LineD(0, 0, 2, 2).Intersect(new LineD(0, 2, 2, 0));
            Assert.IsTrue(PointD.Equals(new PointD(1, 1), result.Shared.Value, 0.01));
            Assert.AreEqual(LineLocation.Between, result.First);
            Assert.AreEqual(LineLocation.Between, result.Second);
            Assert.AreEqual(LineRelation.Divergent, result.Relation);
        }
Example #9
0
        public void Intersect()
        {
            var result = new LineD(0, 0, 0.9, 0.9).Intersect(new LineD(1, 1, 2, 2));

            Assert.AreEqual(null, result.Shared);
            Assert.AreEqual(LineLocation.None, result.First);
            Assert.AreEqual(LineLocation.None, result.Second);
            Assert.AreEqual(LineRelation.Collinear, result.Relation);

            result = new LineD(0, 1, 2, 3).Intersect(new LineD(1, 0, 3, 2));
            Assert.AreEqual(null, result.Shared);
            Assert.AreEqual(LineLocation.None, result.First);
            Assert.AreEqual(LineLocation.None, result.Second);
            Assert.AreEqual(LineRelation.Parallel, result.Relation);

            result = new LineD(0, 0, 0.9, 0.9).Intersect(new LineD(0, 2, 0.9, 1.1));
            Assert.IsTrue(PointD.Equals(new PointD(1, 1), result.Shared.Value, 0.01));
            Assert.AreEqual(LineLocation.After, result.First);
            Assert.AreEqual(LineLocation.After, result.Second);
            Assert.AreEqual(LineRelation.Divergent, result.Relation);

            result = new LineD(0.9, 0.9, 0, 0).Intersect(new LineD(1.1, 0.9, 2, 0));
            Assert.IsTrue(PointD.Equals(new PointD(1, 1), result.Shared.Value, 0.01));
            Assert.AreEqual(LineLocation.Before, result.First);
            Assert.AreEqual(LineLocation.Before, result.Second);
            Assert.AreEqual(LineRelation.Divergent, result.Relation);
        }
Example #10
0
        public void Normalize()
        {
            const float epsilon = 0.0001f;

            Assert.IsTrue(PointD.Equals(new PointD(-1, 0), new PointD(-1, 0).Normalize(), epsilon));
            Assert.IsTrue(PointD.Equals(new PointD(0, -1), new PointD(0, -0.5).Normalize(), epsilon));
            Assert.IsTrue(PointD.Equals(new PointD(0.447213, 0.894428), pointD.Normalize(), epsilon));

            Assert.IsTrue(PointF.Equals(new PointF(-1, 0), new PointF(-1, 0).Normalize(), epsilon));
            Assert.IsTrue(PointF.Equals(new PointF(0, -1), new PointF(0, -0.5f).Normalize(), epsilon));
            Assert.IsTrue(PointF.Equals(new PointF(0.447213f, 0.894428f), pointF.Normalize(), epsilon));
        }
Example #11
0
        /// <summary>
        /// 获取线段L与圆C的交点集合
        /// </summary>
        /// <param name="L">线段L</param>
        /// <param name="C">圆C</param>
        /// <returns>返回交点集合.</returns>
        public static PointD[] Intersection(LineI L, CircleI C)
        {
            List <PointD> result = new List <PointD>();
            Int32?        has    = HasIntersection(L, C);

            if (has == 0 || has == null)
            {
                return(result.ToArray());
            }

            //Points P (x,y) on a line defined by two points P1 (x1,y1,z1) and P2 (x2,y2,z2) is described by
            //P = P1 + u (P2 - P1)

            //or in each coordinate
            //x = x1 + u (x2 - x1)
            //y = y1 + u (y2 - y1)
            //z = z1 + u (z2 - z1)

            //A sphere centered at P3 (x3,y3,z3) with radius r is described by
            //(x - x3)2 + (y - y3)2 + (z - z3)2 = r2

            //Substituting the equation of the line into the sphere gives a quadratic equation of the form
            //a u2 + b u + c = 0

            //where:
            //a = (x2 - x1)2 + (y2 - y1)2 + (z2 - z1)2

            //b = 2[ (x2 - x1) (x1 - x3) + (y2 - y1) (y1 - y3) + (z2 - z1) (z1 - z3) ]

            //c = x32 + y32 + z32 + x12 + y12 + z12 - 2[x3 x1 + y3 y1 + z3 z1] - r2


            //The solutions to this quadratic are described by
            PointD PD = PointAlgorithm.Substract(L.Starting, L.End);
            Double a  = PD.X * PD.X + PD.Y * PD.Y;
            Double b  = 2 * ((L.End.X - L.Starting.X) * (L.Starting.X - C.Center.X) + (L.End.Y - L.Starting.Y) * (L.Starting.Y - C.Center.Y));
            Double c  = C.Center.X * C.Center.X + C.Center.Y * C.Center.Y + L.Starting.X * L.Starting.X + L.Starting.Y * L.Starting.Y - 2 * (C.Center.X * L.Starting.X + C.Center.Y * L.Starting.Y) - C.Radius * C.Radius;
            Double u1 = ((-1) * b + System.Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
            Double u2 = ((-1) * b - System.Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
            //交点
            PointD P1 = new PointD(L.Starting.X + u1 * (L.End.X - L.Starting.X), L.Starting.Y + u1 * (L.End.Y - L.Starting.Y));
            PointD P2 = new PointD(L.Starting.X + u2 * (L.End.X - L.Starting.X), L.Starting.Y + u2 * (L.End.Y - L.Starting.Y));

            if (LineAlgorithm.OnLine(L, P1) == true)
            {
                result.Add(P1);
            }
            if (LineAlgorithm.OnLine(L, P2) == true && P1.Equals(P2) == false)
            {
                result.Add(P2);
            }
            return(result.ToArray());
        }
 /// <summary>
 /// Updates the layout in the cache.
 /// </summary>
 public void UpdateCache(RectD layout)
 {
     if (layout.Equals(cachedLayout) && upVector.Equals(cachedOrientedRect.GetUp()))
     {
         return;
     }
     cachedLayout = layout;
     cachedOrientedRect.SetUpVector(upVector.X, upVector.Y);
     cachedOrientedRect.Width  = Width;
     cachedOrientedRect.Height = Height;
     cachedOrientedRect.SetCenter(cachedLayout.Center);
 }
        private void CompareResultPoints(MultiLinePoint brute, MultiLinePoint sweep)
        {
            Assert.IsTrue(PointD.Equals(brute.Shared, sweep.Shared, 1e-6));

            Int32[]        bruteLines     = brute.Lines, sweepLines = sweep.Lines;
            LineLocation[] bruteLocations = brute.Locations, sweepLocations = sweep.Locations;
            Assert.AreEqual(bruteLines.Length, bruteLocations.Length);
            Assert.AreEqual(sweepLines.Length, sweepLocations.Length);

            Array.Sort(bruteLines, bruteLocations); Array.Sort(sweepLines, sweepLocations);
            CollectionAssert.AreEqual(bruteLines, sweepLines);
            CollectionAssert.AreEqual(bruteLocations, sweepLocations);
        }
Example #14
0
        public void FromPolar()
        {
            const float epsilon = 0.0001f;

            Assert.IsTrue(PointD.Equals(pointD, PointD.FromPolar(pointD.Length, pointD.Angle), epsilon));
            Assert.IsTrue(PointF.Equals(pointF, PointF.FromPolar(pointF.Length, pointF.Angle), epsilon));
            Assert.AreEqual(pointI, PointI.FromPolar(pointI.Length, pointI.Angle));

            Assert.IsTrue(PointD.Equals(new PointD(-1, -2),
                                        PointD.FromPolar(-pointD.Length, pointD.Angle), epsilon));
            Assert.IsTrue(PointF.Equals(new PointF(-1, -2),
                                        PointF.FromPolar(-pointF.Length, pointF.Angle), epsilon));
            Assert.AreEqual(new PointI(-1, -2), PointI.FromPolar(-pointI.Length, pointI.Angle));
        }
Example #15
0
 //Draws the dots on the screen, end is a moot parameter
 public void DrawDot(Cairo.Context ctx, PointD start, PointD end)
 {
     if (!start.Equals(prevDot))
     {
         ctx.SetSourceRGBA(R, G, B, A);
         ctx.Arc(start.X, start.Y, 1, 0, 2 * Math.PI);
         ctx.StrokePreserve();
         ctx.Fill();
         if (startRecordPoints)
         {
             currentDrawnPoints.Add(start);
         }
         prevDot = start;
     }
 }
Example #16
0
        PointD PossiblyCombinePoint(PointD point, Double distance)
        {
            PointD ret = point;

            foreach (KeyValuePair <String, TreePathVertice> kvp in _vertices)
            {
                TreePathVertice vertice = kvp.Value;
                if (point.Equals(vertice.Position) == false && FlatGeo.Distance(point, vertice.Position) < distance)
                {
                    ret = vertice.Position;
                    DebugLogText(LogLevel.DEBUG, "Combining {0} into {1}", point, ret);
                    break;
                }
            }
            return(ret);
        }
Example #17
0
        /// <summary>
        /// 判断多条线段是否有首尾点重复
        /// </summary>
        public static List <LineRepetition> CheckLinesPepeat(List <PointD> points)
        {
            bool[] repetition = new bool[points.Count];
            List <LineRepetition> lineRepetition = new List <LineRepetition>();

            for (int i = 0; i < points.Count; i++)
            {
                //规定第一条线段的首点不是重复点
                if (i == 0)
                {
                    repetition[i] = false;
                }
                //选择一个数作为比较数
                PointD comparePoint = points[i];

                //同所有点进行循环比较
                for (int j = i + 1; j < points.Count; j++)
                {
                    //规定第一条线段的尾点不是重复点
                    if (j == 1)
                    {
                        repetition[j] = false;
                    }
                    //如果有相同的点,则认为是重复点
                    else if (comparePoint.Equals(points[j]))
                    {
                        repetition[j] = true;
                    }
                    else
                    {
                        //如果在之前已经被标记为了重复点,则不能标记为false
                        if (repetition[j] != true)
                        {
                            repetition[j] = false;
                        }
                    }
                }
            }

            //添加结果
            for (int i = 0; i < repetition.Length / 2; i++)
            {
                lineRepetition.Add(new LineRepetition(repetition[i * 2], repetition[i * 2 + 1]));
            }

            return(lineRepetition);
        }
Example #18
0
        public void IntersectEpsilon()
        {
            var result = new LineD(0, 0, 0.9, 0.9).Intersect(new LineD(1, 1, 2, 2), 0.01);

            Assert.AreEqual(null, result.Shared);
            Assert.AreEqual(LineLocation.None, result.First);
            Assert.AreEqual(LineLocation.None, result.Second);
            Assert.AreEqual(LineRelation.Collinear, result.Relation);

            result = new LineD(0, 0, 0.9, 0.9).Intersect(new LineD(1, 1, 2, 2), 0.5);
            Assert.IsTrue(PointD.Equals(new PointD(1, 1), result.Shared.Value, 0.01));
            Assert.AreEqual(LineLocation.End, result.First);
            Assert.AreEqual(LineLocation.Start, result.Second);
            Assert.AreEqual(LineRelation.Collinear, result.Relation);

            result = new LineD(0.9, 0.9, 0.1, 0.1).Intersect(new LineD(1.1, 1.1, 0, 0), 0.5);
            Assert.IsTrue(PointD.Equals(new PointD(0, 0), result.Shared.Value, 0.01));
            Assert.AreEqual(LineLocation.End, result.First);
            Assert.AreEqual(LineLocation.End, result.Second);
            Assert.AreEqual(LineRelation.Collinear, result.Relation);

            result = new LineD(0, 0, 0.9, 0.9).Intersect(new LineD(1, 1, 2, 0), 0.01);
            Assert.IsTrue(PointD.Equals(new PointD(1, 1), result.Shared.Value, 0.01));
            Assert.AreEqual(LineLocation.After, result.First);
            Assert.AreEqual(LineLocation.Start, result.Second);
            Assert.AreEqual(LineRelation.Divergent, result.Relation);

            result = new LineD(0, 0, 0.9, 0.9).Intersect(new LineD(1, 1, 2, 0), 0.5);
            Assert.IsTrue(PointD.Equals(new PointD(0.9, 0.9), result.Shared.Value, 0.01));
            Assert.AreEqual(LineLocation.End, result.First);
            Assert.AreEqual(LineLocation.Start, result.Second);
            Assert.AreEqual(LineRelation.Divergent, result.Relation);

            result = new LineD(0, 0, 2, 2).Intersect(new LineD(0.9, 1.1, 2, 0), 0.01);
            Assert.IsTrue(PointD.Equals(new PointD(1, 1), result.Shared.Value, 0.01));
            Assert.AreEqual(LineLocation.Between, result.First);
            Assert.AreEqual(LineLocation.Between, result.Second);
            Assert.AreEqual(LineRelation.Divergent, result.Relation);

            result = new LineD(0, 0, 2, 2).Intersect(new LineD(0.9, 1.1, 2, 0), 0.5);
            Assert.IsTrue(PointD.Equals(new PointD(0.9, 1.1), result.Shared.Value, 0.01));
            Assert.AreEqual(LineLocation.Between, result.First);
            Assert.AreEqual(LineLocation.Start, result.Second);
            Assert.AreEqual(LineRelation.Divergent, result.Relation);
        }
Example #19
0
 public void EqualsEpsilon()
 {
     Assert.IsTrue(PointD.Equals(pointD, new PointD(1.1, 1.9), 0.2));
     Assert.IsTrue(PointF.Equals(pointF, new PointF(1.1f, 1.9f), 0.2f));
 }
Example #20
0
            public void ShouldReturnFalseWhenInstanceIsNull()
            {
                var point = new PointD(50.0);

                Assert.False(point.Equals(null));
            }
 public bool Equals(Rectangle other)
 {
     return(PointA.Equals(other.PointA) && PointB.Equals(other.PointB) && PointC.Equals(other.PointC) && PointD.Equals(other.PointD));
 }
Example #22
0
        public override async Task RunAsync(string[] args)
        {
            await using Communicator communicator = Initialize(ref args);
            Console.Error.Write("testing proxy & endpoint hash algorithm collisions... ");
            Console.Error.Flush();
            var seenProxy          = new Dictionary <int, IObjectPrx>();
            var seenEndpoint       = new Dictionary <int, Endpoint>();
            int proxyCollisions    = 0;
            int endpointCollisions = 0;
            int i             = 0;
            int maxCollisions = 10;
            int maxIterations = 10000;

            {
                var rand = new Random();
                for (i = 0; proxyCollisions < maxCollisions &&
                     endpointCollisions < maxCollisions &&
                     i < maxIterations; ++i)
                {
                    string proxyString = $"ice+tcp://host-{rand.Next(100)}:{rand.Next(65536)}/{i}";

                    var obj       = IObjectPrx.Parse(proxyString, communicator);
                    var endpoints = new List <Endpoint>(obj.Endpoints);

                    if (seenProxy.ContainsKey(obj.GetHashCode()))
                    {
                        if (obj.Equals(seenProxy[obj.GetHashCode()]))
                        {
                            continue;
                        }
                        ++proxyCollisions;
                    }
                    else
                    {
                        seenProxy[obj.GetHashCode()] = obj;
                    }

                    foreach (Endpoint endpoint in endpoints)
                    {
                        if (seenEndpoint.ContainsKey(endpoint.GetHashCode()))
                        {
                            if (endpoint.Equals(seenEndpoint[endpoint.GetHashCode()]))
                            {
                                continue;
                            }
                            ++endpointCollisions;
                        }
                        else
                        {
                            seenEndpoint[endpoint.GetHashCode()] = endpoint;
                        }
                        // Check the same endpoint produce always the same hash
                        Assert(endpoint.GetHashCode() == endpoint.GetHashCode());
                    }
                    // Check the same proxy produce always the same hash
                    Assert(obj.GetHashCode() == obj.GetHashCode());
                }
                Assert(proxyCollisions < maxCollisions);
                Assert(endpointCollisions < maxCollisions);
                {
                    proxyCollisions = 0;
                    seenProxy       = new Dictionary <int, IObjectPrx>();
                    for (i = 0; proxyCollisions < maxCollisions && i < maxIterations; ++i)
                    {
                        string proxyString = $"ice+tcp://{rand.Next(100)}:{rand.Next(65536)}/{i}";

                        var obj = IObjectPrx.Parse(proxyString, communicator);

                        if (seenProxy.ContainsKey(ProxyComparer.Identity.GetHashCode(obj)))
                        {
                            ++proxyCollisions;
                        }
                        else
                        {
                            seenProxy[ProxyComparer.Identity.GetHashCode(obj)] = obj;
                        }
                        // Check the same proxy produce always the same hash
                        Assert(ProxyComparer.Identity.GetHashCode(obj) == ProxyComparer.Identity.GetHashCode(obj));
                    }
                    Assert(proxyCollisions < maxCollisions);
                }
            }

            {
                var rand = new Random();
                proxyCollisions = 0;
                seenProxy       = new Dictionary <int, IObjectPrx>();
                for (i = 0; proxyCollisions < maxCollisions && i < maxIterations; ++i)
                {
                    string proxyString = $"ice+tcp://{rand.Next(100)}:{rand.Next(65536)}/{i}#facet";

                    var obj = IObjectPrx.Parse(proxyString, communicator);

                    if (seenProxy.ContainsKey(ProxyComparer.IdentityAndFacet.GetHashCode(obj)))
                    {
                        ++proxyCollisions;
                    }
                    else
                    {
                        seenProxy[ProxyComparer.IdentityAndFacet.GetHashCode(obj)] = obj;
                    }
                    // Check the same proxy produce always the same hash
                    Assert(ProxyComparer.IdentityAndFacet.GetHashCode(obj) ==
                           ProxyComparer.IdentityAndFacet.GetHashCode(obj));
                }
                Assert(proxyCollisions < maxCollisions);
            }

            var prx1 = IObjectPrx.Parse("Glacier2/router:tcp -h localhost -p 10010", communicator);
            var prx2 = IObjectPrx.Parse("Glacier2/router:udp -h localhost -p 10012", communicator);
            var prx3 = IObjectPrx.Parse("Glacier2/router:tcp -h zeroc.com -p 10010", communicator);
            var prx4 = IObjectPrx.Parse("Glacier2/router:udp -h zeroc.com -p 10012", communicator);
            var prx5 = IObjectPrx.Parse("Glacier2/router:tcp -h localhost -p 10010 -t 10000", communicator);
            var prx6 = IObjectPrx.Parse("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000", communicator);

            var proxyMap = new Dictionary <string, int>
            {
                ["prx1"] = prx1.GetHashCode(),
                ["prx2"] = prx2.GetHashCode(),
                ["prx3"] = prx3.GetHashCode(),
                ["prx4"] = prx4.GetHashCode(),
                ["prx5"] = prx5.GetHashCode(),
                ["prx6"] = prx6.GetHashCode()
            };

            Assert(IObjectPrx.Parse("Glacier2/router:tcp -h localhost -p 10010", communicator).GetHashCode() == proxyMap["prx1"]);
            Assert(IObjectPrx.Parse("Glacier2/router:udp -h localhost -p 10012", communicator).GetHashCode() == proxyMap["prx2"]);
            Assert(IObjectPrx.Parse("Glacier2/router:tcp -h zeroc.com -p 10010", communicator).GetHashCode() ==
                   proxyMap["prx3"]);
            Assert(IObjectPrx.Parse("Glacier2/router:udp -h zeroc.com -p 10012", communicator).GetHashCode() ==
                   proxyMap["prx4"]);
            Assert(IObjectPrx.Parse("Glacier2/router:tcp -h localhost -p 10010 -t 10000", communicator).GetHashCode() ==
                   proxyMap["prx5"]);
            Assert(
                IObjectPrx.Parse("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000", communicator).GetHashCode() ==
                proxyMap["prx6"]);

            Assert(ProxyComparer.Identity.GetHashCode(prx1) == ProxyComparer.Identity.GetHashCode(prx1));
            Assert(ProxyComparer.IdentityAndFacet.GetHashCode(prx1) ==
                   ProxyComparer.IdentityAndFacet.GetHashCode(prx1));

            Assert(ProxyComparer.Identity.GetHashCode(prx2) == ProxyComparer.Identity.GetHashCode(prx2));
            Assert(ProxyComparer.IdentityAndFacet.GetHashCode(prx2) ==
                   ProxyComparer.IdentityAndFacet.GetHashCode(prx2));

            Assert(ProxyComparer.Identity.GetHashCode(prx3) == ProxyComparer.Identity.GetHashCode(prx3));
            Assert(ProxyComparer.IdentityAndFacet.GetHashCode(prx3) ==
                   ProxyComparer.IdentityAndFacet.GetHashCode(prx3));

            Assert(ProxyComparer.Identity.GetHashCode(prx4) == ProxyComparer.Identity.GetHashCode(prx4));
            Assert(ProxyComparer.IdentityAndFacet.GetHashCode(prx4) ==
                   ProxyComparer.IdentityAndFacet.GetHashCode(prx4));

            Assert(ProxyComparer.Identity.GetHashCode(prx5) == ProxyComparer.Identity.GetHashCode(prx5));
            Assert(ProxyComparer.IdentityAndFacet.GetHashCode(prx5) ==
                   ProxyComparer.IdentityAndFacet.GetHashCode(prx5));

            Assert(ProxyComparer.Identity.GetHashCode(prx6) == ProxyComparer.Identity.GetHashCode(prx6));
            Assert(ProxyComparer.IdentityAndFacet.GetHashCode(prx6) ==
                   ProxyComparer.IdentityAndFacet.GetHashCode(prx6));

            Console.Error.WriteLine("ok");

            Console.Error.Write("testing exceptions hash algorithm collisions... ");

            {
                var seenException = new Dictionary <int, OtherException>();
                var rand          = new Random();

                int exceptionCollisions = 0;
                for (i = 0; i < maxIterations && exceptionCollisions < maxCollisions; ++i)
                {
                    var ex = new OtherException(rand.Next(100), rand.Next(100), 0, false);
                    if (seenException.ContainsKey(ex.GetHashCode()))
                    {
                        if (ex.Equals(seenException[ex.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        exceptionCollisions++;
                    }
                    else
                    {
                        seenException[ex.GetHashCode()] = ex;
                    }
                    // Check the same exception produce always the same hash
                    Assert(ex.GetHashCode() == ex.GetHashCode());
                }
                Assert(exceptionCollisions < maxCollisions);
            }

            // Same as above but with numbers in high ranges
            {
                var seenException = new Dictionary <int, OtherException>();
                var rand          = new Random();

                int exceptionCollisions = 0;
                for (i = 0; i < maxIterations && exceptionCollisions < maxCollisions; ++i)
                {
                    var ex = new OtherException((rand.Next(100) * 2) ^ 30,
                                                (rand.Next(100) * 2) ^ 30,
                                                (rand.Next(100) * 2) ^ 30,
                                                false);

                    if (seenException.ContainsKey(ex.GetHashCode()))
                    {
                        if (ex.Equals(seenException[ex.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        exceptionCollisions++;
                    }
                    else
                    {
                        seenException[ex.GetHashCode()] = ex;
                    }
                    // Check the same exception produce always the same hash
                    Assert(ex.GetHashCode() == ex.GetHashCode());
                }
                Assert(exceptionCollisions < maxCollisions);
            }

            {
                var seenException = new Dictionary <int, BaseException>();
                var rand          = new Random();

                int exceptionCollisions = 0;
                for (i = 0; i < maxIterations && exceptionCollisions < maxCollisions; ++i)
                {
                    int           v  = rand.Next(1000);
                    BaseException ex = new InvalidPointException(v);
                    if (seenException.ContainsKey(ex.GetHashCode()))
                    {
                        if (ex.Equals(seenException[ex.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        exceptionCollisions++;
                    }
                    else
                    {
                        seenException[ex.GetHashCode()] = ex;
                    }

                    // Check the same exception produce always the same hash
                    Assert(ex.GetHashCode() == ex.GetHashCode());

                    ex = new InvalidLengthException(v);
                    if (seenException.ContainsKey(ex.GetHashCode()))
                    {
                        if (ex.Equals(seenException[ex.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        exceptionCollisions++;
                    }
                    else
                    {
                        seenException[ex.GetHashCode()] = ex;
                    }

                    // Check the same exception produce always the same hash
                    Assert(ex.GetHashCode() == ex.GetHashCode());
                }
                Assert(exceptionCollisions < maxCollisions);
            }
            Console.Error.WriteLine("ok");

            Console.Error.Write("testing struct hash algorithm collisions... ");
            {
                var seenPointF       = new Dictionary <int, PointF>();
                var rand             = new Random();
                int structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    var pf = new PointF((float)rand.NextDouble(),
                                        (float)rand.NextDouble(),
                                        (float)rand.NextDouble());
                    if (seenPointF.ContainsKey(pf.GetHashCode()))
                    {
                        if (pf.Equals(seenPointF[pf.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenPointF[pf.GetHashCode()] = pf;
                    }
                    // Check the same struct produce always the same hash
                    Assert(pf.GetHashCode() == pf.GetHashCode());
                }
                Assert(structCollisions < maxCollisions);

                var seenPointD = new Dictionary <int, PointD>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    var pd = new PointD(rand.NextDouble(), rand.NextDouble(), rand.NextDouble());
                    if (seenPointD.ContainsKey(pd.GetHashCode()))
                    {
                        if (pd.Equals(seenPointD[pd.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenPointD[pd.GetHashCode()] = pd;
                    }
                    // Check the same struct produce always the same hash
                    Assert(pd.GetHashCode() == pd.GetHashCode());
                }
                Assert(structCollisions < maxCollisions);

                var seenPolyline = new Dictionary <int, Polyline>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    var polyline = new Polyline();
                    var vertices = new List <Point>();
                    for (int j = 0; j < 100; ++j)
                    {
                        vertices.Add(new Point(rand.Next(100), rand.Next(100)));
                    }
                    polyline.Vertices = vertices.ToArray();

                    if (seenPolyline.ContainsKey(polyline.GetHashCode()))
                    {
                        if (polyline.Equals(seenPolyline[polyline.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenPolyline[polyline.GetHashCode()] = polyline;
                    }
                    // Check the same struct produce always the same hash
                    Assert(polyline.GetHashCode() == polyline.GetHashCode());
                }
                Assert(structCollisions < maxCollisions);

                var seenColorPalette = new Dictionary <int, ColorPalette>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    var colorPalette = new ColorPalette();
                    colorPalette.Colors = new Dictionary <int, Color>();
                    for (int j = 0; j < 100; ++j)
                    {
                        colorPalette.Colors[j] = new Color(
                            rand.Next(255),
                            rand.Next(255),
                            rand.Next(255),
                            rand.Next(255));
                    }

                    if (seenColorPalette.ContainsKey(colorPalette.GetHashCode()))
                    {
                        if (colorPalette.Equals(seenColorPalette[colorPalette.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenColorPalette[colorPalette.GetHashCode()] = colorPalette;
                    }

                    // Check the same struct produce always the same hash
                    Assert(colorPalette.GetHashCode() == colorPalette.GetHashCode());
                }
                Assert(structCollisions < maxCollisions);

                var seenColor = new Dictionary <int, Color>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    var c = new Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255));
                    if (seenColor.ContainsKey(c.GetHashCode()))
                    {
                        if (c.Equals(seenColor[c.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenColor[c.GetHashCode()] = c;
                    }
                    // Check the same struct produce always the same hash
                    Assert(c.GetHashCode() == c.GetHashCode());
                }
                Assert(structCollisions < maxCollisions);

                var seenDraw = new Dictionary <int, Draw>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    var draw = new Draw(
                        new Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255)),
                        new Pen(rand.Next(10),
                                new Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255))),
                        false);

                    if (seenDraw.ContainsKey(draw.GetHashCode()))
                    {
                        if (draw.Equals(seenDraw[draw.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenDraw[draw.GetHashCode()] = draw;
                    }
                    // Check the same struct produce always the same hash
                    Assert(draw.GetHashCode() == draw.GetHashCode());
                }
                Assert(structCollisions < maxCollisions);
            }
            Console.Error.WriteLine("ok");
        }