/* **************** DoorIsOnCell() ****************
     * Determines whether a Door is "on" a Cell--that is to say that the Door's
     * location Vector3 falls somewhere on a vertical surface of the Cell. Be-
     * cause the Door's adjusted location Vector3 is used if the Door is on the
     * Cell, this calculated value is an out parameter.
     *
     * Parameters:
     *   door (Door): Door to evaluate
     *   doorRoomLoc (Vector3): Local position Vector3 of the Room that the
     *     Door is in
     *   doorRoomRot (float): Local y rotation of the Room that the Door is in
     *   cell (Cell): Cell to evaluate
     *   cellRoomLoc (Vector3): Local position Vector3 of the Room that the
     *     Cell is in
     *   cellRoomRot (float): Local y rotation of the Room that the Cell is in
     *
     * Out Parameters:
     *   doorLoc (Vector3): Local position Vector3 of the Door relative to the
     *     it's Room's parent Transform
     *
     * Returns:
     *   bool: true iff Door is on one of the vertical planes of the Cell
     */
    private static bool DoorIsOnCell(Door door, Vector3 doorRoomLoc, float doorRoomRot, Cell cell, Vector3 cellRoomLoc, float cellRoomRot, out Vector3 doorLoc)
    {
        doorLoc = doorRoomLoc + Quaternion.AngleAxis(doorRoomRot, Vector3.up) * door.location;
        doorLoc = RPGUtil.RoundVec3(doorLoc, 1);
        Vector3 minCorner, maxCorner;

        GetMinAndMaxCorners(cell, cellRoomLoc, cellRoomRot, out minCorner, out maxCorner);

        /*
         * Hopefully the spacing of this return statements help clarify what it does, but in case it doesn't:
         * First and foremost, the door must fall in the cell's y range, since all doors are perpendicular to the XZ plane
         * There are two cases for the next check:
         *      Case 1: The door is parallel to the YZ plane
         *          The door must then be on the x boundary of the cell (either the min or max),
         *          and the door must fall in the cell's z range
         *      Case 2: The door is parallel to the XY plane
         *          The door must then be on the z boundary of the cell (either the min or max)
         *          and the door must fall in the cell's x range
         */

        return
            (minCorner.y < doorLoc.y
             &&
             doorLoc.y < maxCorner.y
             &&
             (
                 (
                     (
                         doorLoc.x == minCorner.x
                         ||
                         doorLoc.x == maxCorner.x
                     )
                     &&
                     minCorner.z < doorLoc.z
                     &&
                     doorLoc.z < maxCorner.z
                 )
                 ||
                 (
                     (
                         doorLoc.z == minCorner.z
                         ||
                         doorLoc.z == maxCorner.z
                     )
                     &&
                     minCorner.x < doorLoc.x
                     &&
                     doorLoc.x < maxCorner.x
                 )
             ));
    }
    /* **************** GetMinAndMaxCorners() ****************
     * Void method that calculates the min and max corners of a Cell, taking
     * into account the Cell's Room's location and rotation.
     *
     * Parameters:
     *   cell (Cell): Cell to evaluate
     *   loc (Vector3): Local position Vector3 of the Room that the Cell is in
     *   rot (float): Local y rotation of the Room that the Cell is in
     *
     * Out Parameters:
     *   minCorner (Vector3Int): Vector3Int with the minimum x, y, and z values
     *     out of the corner Vector3s of the Cell, adjusted for location and
     *     rotation
     *   maxCorner (Vector3Int): Vector3Int with the maximum x, y, and z values
     *     out of the corner Vector3s of the Cell, adjusted for location and
     *     rotation
     */
    private static void GetMinAndMaxCorners(Cell cell, Vector3 loc, float rot, out Vector3 minCorner, out Vector3 maxCorner)
    {
        Vector3 corner1 = RPGUtil.RoundVec3(
            loc + Quaternion.AngleAxis(rot, Vector3.up) * cell.corner1);
        Vector3 corner2 = RPGUtil.RoundVec3(
            loc + Quaternion.AngleAxis(rot, Vector3.up) * cell.corner2);

        minCorner = RPGUtil.RoundVec3(new Vector3(
                                          Mathf.Min(corner1.x, corner2.x),
                                          Mathf.Min(corner1.y, corner2.y),
                                          Mathf.Min(corner1.z, corner2.z)));
        maxCorner = RPGUtil.RoundVec3(new Vector3(
                                          Mathf.Max(corner1.x, corner2.x),
                                          Mathf.Max(corner1.y, corner2.y),
                                          Mathf.Max(corner1.z, corner2.z)));
    }