예제 #1
0
        public bool Insert(MarkGeometryLine line)
        {
            if (
                !(
                    GeometricArithmeticModule.IsWithin2D(line.StartPoint, Boundary.Extents) &&
                    GeometricArithmeticModule.IsWithin2D(line.EndPoint, Boundary.Extents)
                    )
                )
            {
                return(false);
            }

            // ensure quads exist
            if (!ChildrenExists)
            {
                var radius = 0.5 * SubSize;

                NorthWest = new ContourQuadTree(
                    Boundary.Extents.MinX + radius, // west
                    Boundary.Extents.MaxY - radius, // north
                    SubSize
                    );
                NorthEast = new ContourQuadTree(
                    Boundary.Extents.MaxX - radius, // east
                    Boundary.Extents.MaxY - radius, // north
                    SubSize
                    );
                SouthWest = new ContourQuadTree(
                    Boundary.Extents.MinX + radius, // west
                    Boundary.Extents.MinY + radius, // south
                    SubSize
                    );
                SouthEast = new ContourQuadTree(
                    Boundary.Extents.MaxX - radius, // east
                    Boundary.Extents.MinY + radius, // south
                    SubSize
                    );

                ChildrenExists = true;
            }

            if (
                (line.Length <= MinSize) ||
                !(
                    NorthWest.Insert(line) ||
                    NorthEast.Insert(line) ||
                    SouthWest.Insert(line) ||
                    SouthEast.Insert(line)
                    )
                )
            {
                Segments.Add(line);
            }

            return(true);
        }
예제 #2
0
        public void Insert(Point pt)
        {
            if (!_rectangle.Contains(pt))
            {
                return;
            }
            if (ptList.Count < CAPACITY)
            {
                ptList.Add(pt);
            }
            else
            {
                if (!divided)
                {
                    SubDivide();
                }

                NorthEast.Insert(pt);
                SouthEast.Insert(pt);
                SouthWest.Insert(pt);
                NorthWest.Insert(pt);
            }
        }
예제 #3
0
        /// <summary>
        /// Insert a point into the QuadTree.
        /// </summary>
        /// <param name="point">Position where to insert the point.</param>
        /// <param name="obj">The object that is attached to the point.</param>
        /// <returns>Returns true if the point was successfully inserted into this QuadTree, otherwise false.</returns>
        public bool Insert(Vector2 point, T obj)
        {
            if (!Boundary.Contains(point))
            {
                return(false);
            }

            if (points.Count < Capacity)
            {
                // Inserted a point successfully.
                points.Add(new Tuple <Vector2, T>(point, obj));
                return(true);
            }
            else if (!divided)
            {
                Subdivide();
            }

            if (NorthWest.Insert(point, obj))
            {
                return(true);
            }
            if (NorthEast.Insert(point, obj))
            {
                return(true);
            }
            if (SouthWest.Insert(point, obj))
            {
                return(true);
            }
            if (SouthEast.Insert(point, obj))
            {
                return(true);
            }

            return(false);
        }