public NodeIndexQuadTree.VectorIndexPair ActualClosestTo(Vector2 pos)
        {
            NodeIndexQuadTree.VectorIndexPair opp =
                ObjectsWithinNode.OrderBy(a => Vector2.Distance(pos, a.Position)).FirstOrDefault();

            return(opp ?? null);
        }
        public Vector2 ActualClosestPointTo(Vector2 pos)
        {
            NodeIndexQuadTree.VectorIndexPair opp =
                ObjectsWithinNode.OrderBy(a => Vector2.Distance(pos, a.Position)).FirstOrDefault();

            return(opp == null ? Vector2.zero : opp.Position);
        }
        private NodeIndexQuadTree.VectorIndexPair ObjectClosestToRecursive(Vector2 pos)
        {
            if (ObjectsWithinNode.Length == 0 || ObjectsWithinNode.Any() == false)
            {
                return(null);
            }

            NodeIndexQuadTree.VectorIndexPair found = null;

            if (NodeBounds.Contains(pos))
            {
                foreach (NodeIndexQuadTreeNode child in ChildNodes)
                {
                    found = child.ObjectClosestToRecursive(pos);
                    if (found != null)
                    {
                        break;
                    }
                }

                if (found == null)
                {
                    foreach (var t in
                             ObjectsWithinNode.OrderBy(a => Vector2.Distance(a.Position, pos)))
                    {
                        if (ObstructionLayer == "" || Physics2D.Raycast(pos, ((Vector2)t.Position - pos).normalized, Vector2.Distance(pos, t.Position), 1 << LayerMask.NameToLayer(ObstructionLayer)) == false)
                        {
                            found = t;
                            break;
                        }
                    }
                }
            }

            return(found);
        }
 public Vector2 ClosestPointTo(Vector2 pos)
 {
     NodeIndexQuadTree.VectorIndexPair foundPos = ObjectClosestToRecursive(pos);
     return(foundPos != null ? foundPos.Position : pos);
 }