/**
 * Geo octocube class
 *
 * An octocube is a cube divided in 8 parts (sliced in two in x, y and z)
 *
 * Its coordinate (0, 0, 0) is the octocube center.
 */
class GeoOctocube {
    /**
     * Gets the sector from the (x, y, z) specified coordinates
     *
     * Sector will be:
     * <code>
     * //             _____ _____ 
     * //           /  5  /  6  /|
     * //          /- - -/- - -/ |
     * //         /_____/____ /| |    
     * //        |     |     | |/|
     * //        |  7  |  8  | / | 2  
     * //        |_____|_____|/| |
     * //        |     |     | |/
     * //        |  3  |  4  | /
     * //        |_____|_____|/ 
     * </code>
     *
     * @param int $x the x coordinate
     * @param int $y the y coordinate
     * @param int $z the z coordinate
     * @return int the number of the sector (0 if x = y = z 0 ; otherwise, 1 to 8)
     */
    static function get_sector ($x, $y, $z) {
        //Cube center
        if ($x == 0 && $y == 0 && $z == 0) return 0;
        
        //One of the 8 cubes
        $sector = 1;
        if ($x >= 0) $sector++;      //we're at right
        if ($y < 0)  $sector += 2;  //we're in front
        if ($z >= 0) $sector += 4; //we're on the top layer
        
        return $sector;
    }
    
    /**
     * Gets the sector from the (x, y, z) specified coordinates
     * @see get_sector
     * 
     * @param GeoPoint3D $pt the x, y, z coordinates
     * @return int the number of the sector (0 if x = y = z 0 ; otherwise, 1 to 8)
     */
    static function get_sector_from_point3D ($pt) {
        return get_sector($pt->x, $pt->y, $pt->z);
    }
}