using System;
using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace McGuffinsOfflineNetworkWorkshop {
    // This class is for storing axis-aligned boxes.
    public class MAlignedBox3 {
        private bool is_empty = true;

        // diagonally opposite corners
        private MVector3 p0 = new MVector3(0, 0, 0);
        private MVector3 p1 = new MVector3(0, 0, 0);

        public MAlignedBox3() {
        }
        public MAlignedBox3(MVector3 min, MVector3 max) {
            MLogger.Assert(min.x <= max.x, "qcm7kjt20a");
            MLogger.Assert(min.y <= max.y, "gyfdcs8lp8");
            MLogger.Assert(min.z <= max.z, "z9l908qfpo");

            p0.copy(min);
            p1.copy(max);
            is_empty = false;
        }

        public bool isEmpty() { return is_empty; }
        public void clear() { is_empty = true; }

        public MVector3 getMin() { return p0; }
        public MVector3 getMax() { return p1; }
        public MVector3 getDiagonal() { return p1-p0; }
        public MVector3 getCenter() {
            return MVector3.average(p0, p1);
        }

        // Enlarge the box as necessary to contain the given point
        public void bound(MVector3 p) {
            if (is_empty) {
                p0.copy(p);
                p1.copy(p);
                is_empty = false;
            }
            else {
                if (p.x < p0.x)
                    p0.x = p.x;
                else if (p.x > p1.x)
                    p1.x = p.x;

                if (p.y < p0.y)
                    p0.y = p.y;
                else if (p.y > p1.y)
                    p1.y = p.y;

                if (p.z < p0.z)
                    p0.z = p.z;
                else if (p.z > p1.z)
                    p1.z = p.z;
            }
        }

        // Enlarge the box as necessary to contain the given box
        public void bound(MAlignedBox3 box) {
            bound(box.p0);
            bound(box.p1);
        }

    }
//}

