当前位置: 首页>>代码示例>>C#>>正文


C# QuadTree.Add方法代码示例

本文整理汇总了C#中QuadTree.Add方法的典型用法代码示例。如果您正苦于以下问题:C# QuadTree.Add方法的具体用法?C# QuadTree.Add怎么用?C# QuadTree.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QuadTree的用法示例。


在下文中一共展示了QuadTree.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MergeObjects

        /// <summary>
        /// Merges objects from the given scene for the given zoom level.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="source"></param>
        /// <param name="idx"></param>
        private void MergeObjects(Scene2D target, Scene2D source, int idx)
        {
            var lines = new Dictionary<Scene2D.ScenePoints, Scene2DStylesSet>();
            var linesIndex = new QuadTree<PointF2D, Scene2D.ScenePoints>();

            var polygons = new Dictionary<Scene2D.ScenePoints, Scene2DStylesSet>();
            //var polygonsIndex = new QuadTree<PointF2D, Scene2D.ScenePoints>();

            Dictionary<uint, SceneObject> sceneObjects = source.GetSceneObjectsAt(idx);
            float zoomFactor = source.GetMaximumZoomFactorAt(idx);
            float epsilon = source.CalculateSimplificationEpsilon(zoomFactor);
            foreach (var sceneObject in sceneObjects)
            {
                if (sceneObject.Value.Enum == SceneObjectType.LineObject)
                { // the scene object is a line object.
                    var sceneLineObject = sceneObject.Value as SceneLineObject;
                    Scene2D.ScenePoints scenePoints = source.GetPoints(sceneLineObject.GeoId);
                    Scene2DStylesSet stylesSet = null;
                    if (!lines.TryGetValue(scenePoints, out stylesSet))
                    { // create styles set.
                        stylesSet = new Scene2DStylesSet();
                        lines.Add(scenePoints, stylesSet);

                        // add scenePoints to the index.
                        linesIndex.Add(new PointF2D(scenePoints.X[0], scenePoints.Y[0]), scenePoints);
                        linesIndex.Add(new PointF2D(scenePoints.X[scenePoints.X.Length - 1], scenePoints.Y[scenePoints.Y.Length - 1]), scenePoints);
                    }
                    stylesSet.AddStyleLine(sceneLineObject.StyleId);
                }
                else if (sceneObject.Value.Enum == SceneObjectType.LineTextObject)
                {
                    var sceneLineTextObject = sceneObject.Value as SceneLineTextObject;
                    Scene2D.ScenePoints scenePoints = source.GetPoints(sceneLineTextObject.GeoId);
                    Scene2DStylesSet stylesSet = null;
                    if (!lines.TryGetValue(scenePoints, out stylesSet))
                    { // create styles set.
                        stylesSet = new Scene2DStylesSet();
                        lines.Add(scenePoints, stylesSet);

                        // add scenePoints to the index.
                        linesIndex.Add(new PointF2D(scenePoints.X[0], scenePoints.Y[0]), scenePoints);
                        linesIndex.Add(new PointF2D(scenePoints.X[scenePoints.X.Length - 1], scenePoints.Y[scenePoints.Y.Length - 1]), scenePoints);
                    }
                    stylesSet.AddStyleLineText(sceneLineTextObject.StyleId, sceneLineTextObject.TextId);
                }
                else if (sceneObject.Value.Enum == SceneObjectType.IconObject)
                {
                    throw new NotSupportedException("Icons not yet supported!");
                    //var sceneIconObject = (sceneObject.Value as SceneIconObject);
                    //Scene2D.ScenePoint scenePoint = source.GetPoint(sceneIconObject.GeoId);
                    //source.GetStyleIcon(
                    //target.AddIcon(target.AddPoint(scenePoint.X, scenePoint.Y);
                }
                else if (sceneObject.Value.Enum == SceneObjectType.PointObject)
                {
                    var scenePointObject = (sceneObject.Value as ScenePointObject);
                    Scene2D.ScenePoint scenePoint = source.GetPoint(scenePointObject.GeoId);
                    StylePoint stylePoint = source.GetStylePoint(scenePointObject.StyleId);

                    target.AddStylePoint(target.AddPoint(scenePoint.X, scenePoint.Y), stylePoint.Layer, stylePoint.MinZoom, stylePoint.MaxZoom,
                        stylePoint.Color, stylePoint.Size);
                }
                else if (sceneObject.Value.Enum == SceneObjectType.PolygonObject)
                { // the scene object is a polygon.
                    var scenePolygonObject = (sceneObject.Value as ScenePolygonObject);
                    Scene2D.ScenePoints scenePoints = source.GetPoints(sceneObject.Value.GeoId);
                    Scene2DStylesSet stylesSet = null;
                    if (!polygons.TryGetValue(scenePoints, out stylesSet))
                    { // create styles set.
                        stylesSet = new Scene2DStylesSet();
                        polygons.Add(scenePoints, stylesSet);

                        //// add scenePoints to the index.
                        //polygonsIndex.Add(new PointF2D(scenePoints.X[0], scenePoints.Y[0]), scenePoints);
                        //polygonsIndex.Add(new PointF2D(scenePoints.X[scenePoints.X.Length - 1], scenePoints.Y[scenePoints.Y.Length - 1]), scenePoints);
                    }
                    stylesSet.AddStylePolygon(scenePolygonObject.StyleId);

                    //var scenePolygonObject = (sceneObject.Value as ScenePolygonObject);
                    //Scene2D.ScenePoints scenePoints = source.GetPoints(sceneObject.Value.GeoId);
                    //StylePolygon stylePolygon = source.GetStylePolygon(sceneObject.Value.StyleId);

                    //uint? pointsId = target.AddPoints(scenePoints.X, scenePoints.Y);
                    //if (pointsId.HasValue)
                    //{
                    //    target.AddStylePolygon(pointsId.Value, stylePolygon.Layer, stylePolygon.MinZoom, stylePolygon.MaxZoom,
                    //        stylePolygon.Color, stylePolygon.Width, stylePolygon.Fill);
                    //}
                }
                else if (sceneObject.Value.Enum == SceneObjectType.TextObject)
                {
                    var sceneTextObject = (sceneObject.Value as SceneTextObject);
                    Scene2D.ScenePoint scenePoint = source.GetPoint(sceneObject.Value.GeoId);
                    StyleText styleText = source.GetStyleText(sceneTextObject.StyleId);
//.........这里部分代码省略.........
开发者ID:JoeCooper,项目名称:ui,代码行数:101,代码来源:Scene2DObjectMerger.cs

示例2: QuadTreeTestTwo

        public void QuadTreeTestTwo()
        {
            int numPoints = 1000;
            double BoundarySize = 1000;
            int seed = 0;
            Random RandGen = new Random(seed);

            QuadTree<int> Tree = new QuadTree<int>(new GridRectangle(-BoundarySize, BoundarySize, -BoundarySize, BoundarySize));

            GridVector2[] points = new GridVector2[numPoints];

            //Create the QuadTree
            for (int i = 0; i < numPoints; i++)
            {
                points[i] = new GridVector2(RandGen.NextDouble() * BoundarySize, RandGen.NextDouble() * BoundarySize);
                Tree.Add(points[i], i);
            }

            double distance;

            //Check to see we can find every item in the quad tree
            for (int i = 0; i < numPoints; i++)
            {

                int iFound = Tree.FindNearest(points[i], out distance);
                Debug.Assert(iFound == i, "Could not find previously inserted point");
            }

            //Remove half the points
            for (int i = 0; i < numPoints / 2; i++)
            {
                Tree.Remove(i);

                //Make sure if we look for the removed point we get an index higher than the ones we've already removed
                int iFound = Tree.FindNearest(points[i], out distance);
                Debug.Assert(iFound > i, "Found previously deleted point");
            }

            //Look for the remaining points
            for (int i = numPoints / 2; i < numPoints; i++)
            {
                //Make sure if we look for the removed point we get an index higher than the ones we've already removed
                int iFound = Tree.FindNearest(points[i], out distance);
                Debug.Assert(iFound == i, "Could not find previously inserted point after deletes");
            }

            //Re-insert the removed points
            for (int i = 0; i < numPoints / 2; i++)
            {
                Tree.Add(points[i], i);

                //Make sure if we look for the removed point we get an index higher than the ones we've already removed
                int iFound = Tree.FindNearest(points[i], out distance);
                Debug.Assert(iFound == i, "Could not find newly inserted point after deletes");
            }

            //Look for the remaining points
            for (int i = numPoints / 2; i < numPoints; i++)
            {
                //Make sure if we look for the removed point we get an index higher than the ones we've already removed
                int iFound = Tree.FindNearest(points[i], out distance);
                Debug.Assert(iFound == i, "Could not find previously inserted point after delete and insert");
            }

            //Delete all the points
            for (int i = 0; i < numPoints; i++)
            {
                Tree.Remove(i);

                //Make sure if we look for the removed point we get an index higher than the ones we've already removed
                if (i < numPoints - 1)
                {
                    int iFound = Tree.FindNearest(points[i], out distance);
                    Debug.Assert(iFound > i, "Found previously deleted point");
                }
            }

            //Insert some points into the empty tree to make sure we still can
            for (int i = 0; i < numPoints; i++)
            {
                points[i] = new GridVector2(RandGen.NextDouble() * BoundarySize, RandGen.NextDouble() * BoundarySize);
                Tree.Add(points[i], i);
            }

            //Check to see we can find every item in the quad tree
            for (int i = 0; i < numPoints; i++)
            {

                int iFound = Tree.FindNearest(points[i], out distance);
                Debug.Assert(iFound == i, "Could not find previously inserted point");
            }

            //The end
        }
开发者ID:abordt,项目名称:Viking,代码行数:94,代码来源:QuadTreeTest.cs


注:本文中的QuadTree.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。