using UnityEngine;
using System.Collections;

public class BoundsHelper : MonoBehaviour {

    public static bool WrapAtBounds(Transform t, float buffer = 0)
    {
        bool wrapped = false;

        float LIMIT = 8.65f + buffer;
        Vector3 p = t.position;

        if (p.x < -LIMIT)
        {
            t.position = new Vector3(LIMIT, p.y, p.z);
            wrapped = true;
        }
        else if (p.x > LIMIT)
        {
            t.position = new Vector3(-LIMIT, p.y, p.z);
            wrapped = true;
        }

        if (p.y < -LIMIT)
        {
            t.position = new Vector3(p.x, LIMIT, p.z);
            wrapped = true;
        }
        else if (p.y > LIMIT)
        {
            t.position = new Vector3(p.x, -LIMIT, p.z);
            wrapped = true;
        }

        return wrapped;
    }

    public static bool BoundsOK(Transform t, float buffer = 0)
    {
        Vector3 p = t.position;
        if (p.x < -(8.6f + buffer) || p.x > 8.6f + buffer || p.y < -(8 + buffer) || p.y > 8 + buffer)
            return false;
        return true;
    }
}
