<?php

class Tile {
  /** Defines a Tile from a panorama
   */

    private $point;
    private $zoom;
    public $x;
    public $y;

    public function __construct($site_point, $zoom, $x, $y) {
        $this->point = $site_point;
        $this->zoom = $zoom;
        $this->x = $x;
        $this->y = $y;
    }

    public function path() {
        return sprintf('%s/%03d_%03d_%03d.jpg', $this->point->tiles_path(),
                       $this->zoom, $this->x, $this->y);
    }

    /** Returns tile size (x,y)
     */
    public function dimensions() {
        return getimagesize($this->path());
    }

    public static function from_file($file_path, $site_point) {
        preg_match('/([0-9]+)_([0-9]+)_([0-9]+)\.jpg$/', $file_path, $groups);
        $zoom = (int)($groups[1]);
		$x = (int)($groups[2]);
		$y = (int)($groups[3]);
        return new Tile($site_point, $zoom, $x, $y);
    }
  };
?>
