コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="g"></param>
        /// <returns></returns>
        private Coordinate[] ExtractTargetCoordinates(IGeometry g)
        {
            // TODO: should do this more efficiently.  Use CoordSeq filter to get points, KDTree for uniqueness & queries
            OrderedSet <Coordinate> ptSet = new OrderedSet <Coordinate>(g.Coordinates);

            Coordinate[] result = new Coordinate[ptSet.Count];
            ptSet.CopyTo(result, 0);
            return(result);
        }
コード例 #2
0
        /// Returns all entities which are currently in the context.
        public TEntity[] GetEntities()
        {
            if (_entitiesCache == null)
            {
                _entitiesCache = new TEntity[_entities.Count];
                _entities.CopyTo(_entitiesCache);
            }

            return(_entitiesCache);
        }
コード例 #3
0
        public void OrderedSet_CopiesTo_ByInsertionOrder()
        {
            IEnumerable <string> expectedItems = Enumerable.Range(0, 10).Reverse().Select(v => v.ToString());

            var set = new OrderedSet <string>();

            foreach (var item in expectedItems)
            {
                set.Add(item);
            }

            var copiedArray = new string[10];

            set.CopyTo(copiedArray, 0);

            Assert.Equal(expectedItems, copiedArray);
        }
コード例 #4
0
        public void OrderedSet_CopiesTo_ByInsertionOrder_AndRespectsArrayIndex()
        {
            IEnumerable <string> expectedItems = Enumerable.Range(0, 10).Reverse().Select(v => v.ToString());

            var set = new OrderedSet <string>();

            foreach (var item in expectedItems)
            {
                set.Add(item);
            }

            var copiedArray = new string[15];

            set.CopyTo(copiedArray, 5);

            Assert.Equal(new string[5], copiedArray.Take(5));
            Assert.Equal(expectedItems, copiedArray.Skip(5));
        }
コード例 #5
0
        public void CopyWholeSetToArray()
        {
            var set = new OrderedSet <int> {
                3, 1, 2
            };
            var array = new int[3];

            set.CopyTo(array, 0);
            Assert.Equal(array.Length, 3);
            Assert.Equal(array[0], 3);
            Assert.Equal(array[1], 1);
            Assert.Equal(array[2], 2);
            //Change set, ensure array does not change
            Assert.True(set.Add(4));
            Assert.Equal(array.Length, 3);
            Assert.Equal(array[0], 3);
            Assert.Equal(array[1], 1);
            Assert.Equal(array[2], 2);
        }
コード例 #6
0
        public void AssertThat_CopyTo_IsOrderedByInsertionOrder()
        {
            var r = new LinearFeedbackShiftRegister32(1);

            for (var i = 0; i < 100; i++)
            {
                _set.Add((int)r.NextRandom());
            }

            var items = new int[100];

            _set.CopyTo(items, 0);

            var r2 = new LinearFeedbackShiftRegister32(1);

            foreach (var item in items)
            {
                Assert.AreEqual((int)r2.NextRandom(), item);
            }
        }
コード例 #7
0
ファイル: ConvexHull.cs プロジェクト: Sony-NS/SharpMap
        /// <summary>
        /// Uses a heuristic to reduce the number of points scanned to compute the hull.
        /// The heuristic is to find a polygon guaranteed to
        /// be in (or on) the hull, and eliminate all points inside it.
        /// A quadrilateral defined by the extremal points
        /// in the four orthogonal directions
        /// can be used, but even more inclusive is
        /// to use an octilateral defined by the points in the 8 cardinal directions.
        /// Note that even if the method used to determine the polygon vertices
        /// is not 100% robust, this does not affect the robustness of the convex hull.
        /// </summary>
        /// <param name="pts"></param>
        /// <returns></returns>
        private ICoordinate[] Reduce(ICoordinate[] pts)
        {
            ICoordinate[] polyPts = ComputeOctRing(inputPts);

            // unable to compute interior polygon for some reason
            if (polyPts == null)
            {
                return(inputPts);
            }

            // add points defining polygon
            OrderedSet <ICoordinate> reducedSet = new OrderedSet <ICoordinate>();

            for (int i = 0; i < polyPts.Length; i++)
            {
                reducedSet.Add(polyPts[i]);
            }

            /*
             * Add all unique points not in the interior poly.
             * CGAlgorithms.IsPointInRing is not defined for points actually on the ring,
             * but this doesn't matter since the points of the interior polygon
             * are forced to be in the reduced set.
             */
            for (int i = 0; i < inputPts.Length; i++)
            {
                if (!CGAlgorithms.IsPointInRing(inputPts[i], polyPts))
                {
                    reducedSet.Add(inputPts[i]);
                }
            }

            ICoordinate[] arr = new ICoordinate[reducedSet.Count];
            reducedSet.CopyTo(arr, 0);
            return(arr);
        }
コード例 #8
0
 void ICollection <IKProtocolEndpoint <TNodeId> > .CopyTo(IKProtocolEndpoint <TNodeId>[] array, int arrayIndex)
 {
     using (sync.BeginReadLock())
         set.CopyTo(array, arrayIndex);
 }
コード例 #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="g"></param>
 /// <returns></returns>
 private Coordinate[] ExtractTargetCoordinates(IGeometry g)
 {
     // TODO: should do this more efficiently.  Use CoordSeq filter to get points, KDTree for uniqueness & queries
     OrderedSet<Coordinate> ptSet = new OrderedSet<Coordinate>(g.Coordinates);
     Coordinate[] result = new Coordinate[ptSet.Count];
     ptSet.CopyTo(result, 0);
     return result;
 }