Exemplo n.º 1
0
        NNInfoInternal GetNearestInternal(Vector3 position, NNConstraint constraint, bool fastCheck)
        {
            if (nodes == null)
            {
                return(new NNInfoInternal());
            }
            var iposition = (Int3)position;

            if (optimizeForSparseGraph)
            {
                if (nearestNodeDistanceMode == NodeDistanceMode.Node)
                {
                    return(new NNInfoInternal(lookupTree.GetNearest(iposition, fastCheck ? null : constraint)));
                }
                else
                {
                    var closestNode = lookupTree.GetNearestConnection(iposition, fastCheck ? null : constraint, maximumConnectionLength);
                    if (closestNode == null)
                    {
                        return(new NNInfoInternal());
                    }

                    return(FindClosestConnectionPoint(closestNode as PointNode, position));
                }
            }

            float maxDistSqr = constraint == null || constraint.constrainDistance ? AstarPath.active.maxNearestNodeDistanceSqr : float.PositiveInfinity;

            maxDistSqr *= Int3.FloatPrecision * Int3.FloatPrecision;

            var  nnInfo       = new NNInfoInternal(null);
            long minDist      = long.MaxValue;
            long minConstDist = long.MaxValue;

            for (int i = 0; i < nodeCount; i++)
            {
                PointNode node = nodes[i];
                long      dist = (iposition - node.position).sqrMagnitudeLong;

                if (dist < minDist)
                {
                    minDist     = dist;
                    nnInfo.node = node;
                }

                if (dist < minConstDist && (float)dist < maxDistSqr && (constraint == null || constraint.Suitable(node)))
                {
                    minConstDist           = dist;
                    nnInfo.constrainedNode = node;
                }
            }

            if (!fastCheck)
            {
                nnInfo.node = nnInfo.constrainedNode;
            }

            nnInfo.UpdateInfo();
            return(nnInfo);
        }
Exemplo n.º 2
0
        public override NNInfoInternal GetNearestForce(Vector3 position, NNConstraint constraint)
        {
            if (nodes == null)
            {
                return(new NNInfoInternal());
            }


            float maxDistSqr = constraint == null || constraint.constrainDistance ? AstarPath.active.maxNearestNodeDistanceSqr : float.PositiveInfinity;

            var   nnInfo       = new NNInfoInternal(null);
            float minDist      = float.PositiveInfinity;
            float minConstDist = float.PositiveInfinity;

            for (int i = 0; i < nodeCount; i++)
            {
                PointNode node = nodes[i];
                float     dist = (position - (Vector3)node.position).sqrMagnitude;

                if (dist < minDist)
                {
                    minDist     = dist;
                    nnInfo.node = node;
                }

                if (dist < minConstDist && dist < maxDistSqr && (constraint == null || constraint.Suitable(node)))
                {
                    minConstDist           = dist;
                    nnInfo.constrainedNode = node;
                }
            }

            nnInfo.UpdateInfo();
            return(nnInfo);
        }
Exemplo n.º 3
0
        public override NNInfoInternal GetNearestForce(Vector3 position, NNConstraint constraint)
        {
            if (this.nodes == null)
            {
                return(default(NNInfoInternal));
            }
            if (this.optimizeForSparseGraph)
            {
                return(new NNInfoInternal(this.lookupTree.GetNearest((Int3)position, constraint)));
            }
            float          num    = (constraint != null && !constraint.constrainDistance) ? float.PositiveInfinity : AstarPath.active.maxNearestNodeDistanceSqr;
            NNInfoInternal result = new NNInfoInternal(null);
            float          num2   = float.PositiveInfinity;
            float          num3   = float.PositiveInfinity;

            for (int i = 0; i < this.nodeCount; i++)
            {
                PointNode pointNode    = this.nodes[i];
                float     sqrMagnitude = (position - (Vector3)pointNode.position).sqrMagnitude;
                if (sqrMagnitude < num2)
                {
                    num2        = sqrMagnitude;
                    result.node = pointNode;
                }
                if (sqrMagnitude < num3 && sqrMagnitude < num && (constraint == null || constraint.Suitable(pointNode)))
                {
                    num3 = sqrMagnitude;
                    result.constrainedNode = pointNode;
                }
            }
            result.UpdateInfo();
            return(result);
        }
Exemplo n.º 4
0
        public NNInfoInternal QueryCircle(Vector3 p, float radius, NNConstraint constraint)
        {
            if (this.count == 0)
            {
                return(new NNInfoInternal(null));
            }
            NNInfoInternal result = new NNInfoInternal(null);

            this.SearchBoxCircle(0, p, radius, constraint, ref result);
            result.UpdateInfo();
            return(result);
        }
Exemplo n.º 5
0
        public NNInfoInternal Query(Vector3 p, NNConstraint constraint)
        {
            if (this.count == 0)
            {
                return(new NNInfoInternal(null));
            }
            NNInfoInternal result = default(NNInfoInternal);

            this.SearchBox(0, p, constraint, ref result);
            result.UpdateInfo();
            return(result);
        }
Exemplo n.º 6
0
        public NNInfoInternal Query(Vector3 p, NNConstraint constraint)
        {
            if (this.count == 0)
            {
                return(new NNInfoInternal(null));
            }
            NNInfoInternal nnInfo = new NNInfoInternal();

            this.SearchBox(0, p, constraint, ref nnInfo);
            nnInfo.UpdateInfo();
            return(nnInfo);
        }
Exemplo n.º 7
0
        /** Queries the tree for the best node, searching within a circle around \a p with the specified radius.
         * Will fill in both the constrained node and the not constrained node in the NNInfo.
         *
         * \see QueryClosest
         */
        public NNInfoInternal QueryCircle(Vector3 p, float radius, NNConstraint constraint)
        {
            if (count == 0)
            {
                return(new NNInfoInternal(null));
            }

            var nnInfo = new NNInfoInternal(null);

            SearchBoxCircle(0, p, radius, constraint, ref nnInfo);

            nnInfo.UpdateInfo();

            return(nnInfo);
        }
Exemplo n.º 8
0
        private NNInfoInternal GetNearestInternal(Vector3 position, NNConstraint constraint, bool fastCheck)
        {
            if (nodes == null)
            {
                return(new NNInfoInternal());
            }
            var iposition = (Int3)position;


            var maxDistSqr = constraint == null || constraint.constrainDistance
                ? AstarPath.active.maxNearestNodeDistanceSqr
                : float.PositiveInfinity;

            maxDistSqr *= Int3.FloatPrecision * Int3.FloatPrecision;

            var nnInfo       = new NNInfoInternal(null);
            var minDist      = long.MaxValue;
            var minConstDist = long.MaxValue;

            for (var i = 0; i < nodeCount; i++)
            {
                var node = nodes[i];
                var dist = (iposition - node.position).sqrMagnitudeLong;

                if (dist < minDist)
                {
                    minDist     = dist;
                    nnInfo.node = node;
                }

                if (dist < minConstDist && (float)dist < maxDistSqr &&
                    (constraint == null || constraint.Suitable(node)))
                {
                    minConstDist           = dist;
                    nnInfo.constrainedNode = node;
                }
            }

            if (!fastCheck)
            {
                nnInfo.node = nnInfo.constrainedNode;
            }

            nnInfo.UpdateInfo();
            return(nnInfo);
        }
Exemplo n.º 9
0
        NNInfoInternal GetNearestInternal(Vector3 position, NNConstraint constraint, bool fastCheck)
        {
            if (nodes == null)
            {
                return(new NNInfoInternal());
            }

            if (optimizeForSparseGraph)
            {
                return(new NNInfoInternal(lookupTree.GetNearest((VInt3)position, fastCheck ? null : constraint)));
            }

            float maxDistSqr = constraint == null || constraint.constrainDistance ? AstarPath.active.maxNearestNodeDistanceSqr : float.PositiveInfinity;

            var   nnInfo       = new NNInfoInternal(null);
            float minDist      = float.PositiveInfinity;
            float minConstDist = float.PositiveInfinity;

            for (int i = 0; i < nodeCount; i++)
            {
                PointNode node = nodes[i];
                float     dist = (position - (Vector3)node.position).sqrMagnitude;

                if (dist < minDist)
                {
                    minDist     = dist;
                    nnInfo.node = node;
                }

                if (dist < minConstDist && dist < maxDistSqr && (constraint == null || constraint.Suitable(node)))
                {
                    minConstDist           = dist;
                    nnInfo.constrainedNode = node;
                }
            }

            if (!fastCheck)
            {
                nnInfo.node = nnInfo.constrainedNode;
            }

            nnInfo.UpdateInfo();
            return(nnInfo);
        }
        // Token: 0x060025B4 RID: 9652 RVA: 0x001A1470 File Offset: 0x0019F670
        private NNInfoInternal GetNearestInternal(Vector3 position, NNConstraint constraint, bool fastCheck)
        {
            if (this.nodes == null)
            {
                return(default(NNInfoInternal));
            }
            if (this.optimizeForSparseGraph)
            {
                return(new NNInfoInternal(this.lookupTree.GetNearest((Int3)position, fastCheck ? null : constraint)));
            }
            float          num            = (constraint == null || constraint.constrainDistance) ? AstarPath.active.maxNearestNodeDistanceSqr : float.PositiveInfinity;
            NNInfoInternal nninfoInternal = new NNInfoInternal(null);
            float          num2           = float.PositiveInfinity;
            float          num3           = float.PositiveInfinity;

            for (int i = 0; i < this.nodeCount; i++)
            {
                PointNode pointNode    = this.nodes[i];
                float     sqrMagnitude = (position - (Vector3)pointNode.position).sqrMagnitude;
                if (sqrMagnitude < num2)
                {
                    num2 = sqrMagnitude;
                    nninfoInternal.node = pointNode;
                }
                if (sqrMagnitude < num3 && sqrMagnitude < num && (constraint == null || constraint.Suitable(pointNode)))
                {
                    num3 = sqrMagnitude;
                    nninfoInternal.constrainedNode = pointNode;
                }
            }
            if (!fastCheck)
            {
                nninfoInternal.node = nninfoInternal.constrainedNode;
            }
            nninfoInternal.UpdateInfo();
            return(nninfoInternal);
        }