public void EqualsComparerTest()
 {
     Coordinate[] reverse = CoordinateArrays.CopyDeep(array);
     CoordinateArrays.Reverse(reverse);
     Assert.IsFalse(CoordinateArrays.Equals(array, reverse));
     Assert.IsFalse(CoordinateArrays.Equals(array, reverse, new CoordinateArrays.ForwardComparator()));
     Assert.IsTrue(CoordinateArrays.Equals(array, reverse, new CoordinateArrays.BidirectionalComparator()));
 }
        public static CoordinateList Unique(Coordinate[] coords)
        {
            var coordsCopy = CoordinateArrays.CopyDeep(coords);

            Array.Sort(coordsCopy);
            var coordList = new CoordinateList(coordsCopy, false);

            return(coordList);
        }
Ejemplo n.º 3
0
        public void TestEqualsInHashBasedCollection()
        {
            var p0 = new Coordinate(0, 0);
            var p1 = new Coordinate(0, 1);
            var p2 = new Coordinate(1, 0);

            Coordinate[] exactEqualRing1 = { p0, p1, p2, p0 };
            var          exactEqualRing2 = CoordinateArrays.CopyDeep(exactEqualRing1);

            Coordinate[] rotatedRing1 = { p1, p2, p0, p1 };
            Coordinate[] rotatedRing2 = { p2, p0, p1, p2 };

            var exactEqualRing1Poly = geometryFactory.CreatePolygon(exactEqualRing1);
            var exactEqualRing2Poly = geometryFactory.CreatePolygon(exactEqualRing2);
            var rotatedRing1Poly    = geometryFactory.CreatePolygon(rotatedRing1);
            var rotatedRing2Poly    = geometryFactory.CreatePolygon(rotatedRing2);

            // IGeometry equality in hash-based collections should be based on
            // EqualsExact semantics, as it is in JTS.
            var hashSet1 = new HashSet <IGeometry>
            {
                exactEqualRing1Poly,
                exactEqualRing2Poly,
                rotatedRing1Poly,
                rotatedRing2Poly,
            };

            Assert.AreEqual(3, hashSet1.Count);

            // same as IPolygon equality.
            var hashSet2 = new HashSet <IPolygon>
            {
                exactEqualRing1Poly,
                exactEqualRing2Poly,
                rotatedRing1Poly,
                rotatedRing2Poly,
            };

            Assert.AreEqual(3, hashSet2.Count);
        }
Ejemplo n.º 4
0
        private void ComputeCirclePoints()
        {
            Coordinate[] pts;
            // handle degenerate or trivial cases
            if (_input.IsEmpty)
            {
                _extremalPts = new Coordinate[0];
                return;
            }
            if (_input.NumPoints == 1)
            {
                pts          = _input.Coordinates;
                _extremalPts = new[] { new Coordinate(pts[0]) };
                return;
            }

            /**
             * The problem is simplified by reducing to the convex hull.
             * Computing the convex hull also has the useful effect of eliminating duplicate points
             */
            var convexHull = _input.ConvexHull();

            // check for degenerate or trivial cases
            var hullPts = convexHull.Coordinates;

            // strip duplicate final point, if any
            pts = hullPts;
            if (hullPts[0].Equals2D(hullPts[hullPts.Length - 1]))
            {
                pts = new Coordinate[hullPts.Length - 1];
                CoordinateArrays.CopyDeep(hullPts, 0, pts, 0, hullPts.Length - 1);
            }

            /**
             * Optimization for the trivial case where the CH has fewer than 3 points
             */
            if (pts.Length <= 2)
            {
                _extremalPts = CoordinateArrays.CopyDeep(pts);
                return;
            }

            // find a point P with minimum Y ordinate
            var P = LowestPoint(pts);

            // find a point Q such that the angle that PQ makes with the x-axis is minimal
            var Q = PointWitMinAngleWithX(pts, P);

            /**
             * Iterate over the remaining points to find
             * a pair or triplet of points which determine the minimal circle.
             * By the design of the algorithm,
             * at most <tt>pts.length</tt> iterations are required to terminate
             * with a correct result.
             */
            for (int i = 0; i < pts.Length; i++)
            {
                var R = PointWithMinAngleWithSegment(pts, P, Q);

                // if PRQ is obtuse, then MBC is determined by P and Q
                if (AngleUtility.IsObtuse(P, R, Q))
                {
                    _extremalPts = new Coordinate[] { new Coordinate(P), new Coordinate(Q) };
                    return;
                }
                // if RPQ is obtuse, update baseline and iterate
                if (AngleUtility.IsObtuse(R, P, Q))
                {
                    P = R;
                    continue;
                }
                // if RQP is obtuse, update baseline and iterate
                if (AngleUtility.IsObtuse(R, Q, P))
                {
                    Q = R;
                    continue;
                }
                // otherwise all angles are acute, and the MBC is determined by the triangle PQR
                _extremalPts = new Coordinate[] { new Coordinate(P), new Coordinate(Q), new Coordinate(R) };
                return;
            }
            Assert.ShouldNeverReachHere("Logic failure in Minimum Bounding Circle algorithm!");
        }