예제 #1
0
        public bool ContainsPoint(QVector2D point)
        {
            if (IsLeaf)
            {
                return(data.ContainsKey(point));
            }

            if (children[0].ContainsPoint(point))
            {
                return(true);
            }
            if (children[1].ContainsPoint(point))
            {
                return(true);
            }
            if (children[2].ContainsPoint(point))
            {
                return(true);
            }
            if (children[3].ContainsPoint(point))
            {
                return(true);
            }

            return(false);
        }
예제 #2
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ContainsPoint(QVector2D point)
        {
            if (IsLeaf)
            {
                return(data.ContainsKey(point));
            }

            if (children[0].ContainsPoint(point))
            {
                return(true);
            }
            if (children[1].ContainsPoint(point))
            {
                return(true);
            }
            if (children[2].ContainsPoint(point))
            {
                return(true);
            }
            if (children[3].ContainsPoint(point))
            {
                return(true);
            }

            return(false);
        }
예제 #3
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)] private QRegion CalculateChildRegion(QQuadrant quadrant)
        {
            QVector2D childHalfRegion = CalculateChildHalfSize(quadrant);

            return(new QRegion(
                       CalculateChildCenter(quadrant, childHalfRegion),
                       childHalfRegion
                       ));
        }
예제 #4
0
        private QRegion CalculateChildRegion(QQuadrant quadrant)
        {
            QVector2D childHalfRegion = .5f * region.halfRegionSize;

            return(new QRegion(
                       CalculateChildCenter(quadrant, childHalfRegion),
                       childHalfRegion
                       ));
        }
예제 #5
0
        private QVector2D CalculateChildCenter(QQuadrant quadrant, QVector2D childHalfRegion)
        {
            float xSign = (quadrant.XComponentIsPositive()) ? 1 : -1;
            float ySign = (quadrant.YComponentIsPositive()) ? 1 : -1;

            return(new QVector2D(
                       region.center.x + xSign * childHalfRegion.x,
                       region.center.y + ySign * childHalfRegion.y
                       ));
        }
예제 #6
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)] private QVector2D CalculateChildHalfSize(QQuadrant quadrant)
        {
            QVector2D quadrantsCorner = GetQuadrantsCorner(quadrant);

            float xComponent = .5f * (Math.Max(lastPointInserted.x, quadrantsCorner.x) -
                                      Math.Min(lastPointInserted.x, quadrantsCorner.x));
            float yComponent = .5f * (Math.Max(lastPointInserted.y, quadrantsCorner.y) -
                                      Math.Min(lastPointInserted.y, quadrantsCorner.y));

            return(new QVector2D(xComponent, yComponent));
        }
예제 #7
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (!GetType().Equals(obj.GetType()))
            {
                return(false);
            }

            QVector2D argPoint = (QVector2D)obj;

            return(x.Equals(argPoint.x) && y.Equals(argPoint.y));
        }
예제 #8
0
        public bool InsertPoint(QVector2D point, T pointData)
        {
            if (IsLeaf)
            {
                if (!region.ContainsPoint(point) || data.ContainsKey(point))
                {
                    return(false);
                }

                data.Add(point, pointData);
                if (data.Count == bucketSize && depth != maximumDepth)
                {
                    Subdivide();
                }
                return(true);
            }

            return(InsertInChild(point, pointData));
        }
예제 #9
0
        public bool InsertPoint(QVector2D point, T pointData)
        {
            if (IsLeaf)
            {
                if (!region.ContainsPoint(point) || data.ContainsKey(point))
                {
                    return(false);
                }

                data.Add(point, pointData);
                lastPointInserted = point;
                if (depth != maximumDepth && !subdividing)
                {
                    Subdivide();
                }
                return(true);
            }

            return(InsertInChild(point, pointData));
        }
예제 #10
0
        private bool InsertInChild(QVector2D point, T pointData)
        {
            if (children[0].region.ContainsPoint(point))
            {
                return(children[0].InsertPoint(point, pointData));
            }
            if (children[1].region.ContainsPoint(point))
            {
                return(children[1].InsertPoint(point, pointData));
            }
            if (children[2].region.ContainsPoint(point))
            {
                return(children[2].InsertPoint(point, pointData));
            }
            if (children[3].region.ContainsPoint(point))
            {
                return(children[3].InsertPoint(point, pointData));
            }

            return(false);
        }
예제 #11
0
        public bool InsertPoint(QVector2D point, T pointData)
        {
            if (IsLeaf)
            {
                if (!region.ContainsPoint(point) || points.Contains(point))
                {
                    return(false);
                }

                if (!data.Equals(pointData) && depth != maximumDepth)
                {
                    subdivisionPoint     = point;
                    subdivisionPointData = pointData;
                    Subdivide();
                }
                else
                {
                    points.Add(point);
                }
                return(true);
            }

            return(InsertInChild(point, pointData));
        }
예제 #12
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)] private QVector2D CalculateChildCenter(QQuadrant quadrant, QVector2D childHalfRegion)
        {
            float xSign = (quadrant.XComponentIsPositive()) ? 1 : -1;
            float ySign = (quadrant.YComponentIsPositive()) ? 1 : -1;

            return(new QVector2D(
                       lastPointInserted.x + xSign * childHalfRegion.x,
                       lastPointInserted.y + ySign * childHalfRegion.y
                       ));
        }