Overview

Namespaces

  • Quadtree
    • Geometry

Classes

  • Bounds
  • Point
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: namespace Quadtree\Geometry;
 4: 
 5: /**
 6:  * A point on a two-dimensional plane
 7:  */
 8: class Point implements \Quadtree\Insertable
 9: {
10:     /** @var float */
11:     private $left;
12:     
13:     /** @var float */
14:     private $top;
15:     
16:     /** @var Bounds */
17:     private $bounds;
18:     
19:     /**
20:      * @param float $left
21:      * @param float $top
22:      */
23:     function __construct($left, $top)
24:     {
25:         if (!is_numeric($left) || !is_numeric($top) ) {
26:             throw new \InvalidArgumentException('Input must be numeric');
27:         }
28:         $this->left = (float)$left;
29:         $this->top = (float)$top;
30:     }
31:     
32:     /**
33:      * @return float
34:      */
35:     function getLeft()
36:     {
37:         return $this->left;
38:     }
39: 
40:     /**
41:      * @return float
42:      */
43:     function getTop()
44:     {
45:         return $this->top;
46:     }
47:     
48:     /**
49:      * Comparison function
50:      * @param \Quadtree\Point $point
51:      * @return boolean
52:      */
53:     public function equals(Point $point)
54:     {
55:         return $this->left === $point->getLeft() && $this->top === $point->getTop();
56:     }
57:     
58:     /**
59:      * Get 2D envelope
60:      * @return Bounds
61:      */
62:     public function getBounds()
63:     {
64:         if ($this->bounds === NULL) {
65:             $this->bounds = new Bounds(0, 0, $this->left, $this->top);
66:         }
67:         return $this->bounds;
68:     }
69: 
70: }
API documentation generated by ApiGen