summaryrefslogtreecommitdiffstats
path: root/src/math/boundings.php
blob: b869a1f914cd918ecaa559831b4778b5f6c274ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
 * File containing the ezcGraphBoundings class
 *
 * @package Graph
 * @version //autogentag//
 * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
 * @license http://ez.no/licenses/new_bsd New BSD License
 * @access private
 */
/**
 * Provides a class representing boundings in a cartesian coordinate system.
 *
 * Currently only works with plane rectangular boundings, should be enhanced by
 * rotated rectangular boundings.
 *
 * This class is only used internally to represent space which is used by
 * certain obejcts on the drawing plane, or which free space is still
 * available.
 *
 * @version //autogentag//
 * @package Graph
 * @access private
 */
class ezcGraphBoundings
{
    /**
     * Top left x coordinate 
     * 
     * @var float
     */
    public $x0 = 0;

    /**
     * Top left y coordinate 
     * 
     * @var float
     */
    public $y0 = 0;
    
    /**
     * Bottom right x coordinate 
     * 
     * @var float
     */
    public $x1 = false;

    /**
     * Bottom right y coordinate 
     * 
     * @var float
     */
    public $y1 = false;
    
    /**
     * Constructor
     * 
     * @param float $x0 Top left x coordinate
     * @param float $y0 Top left y coordinate
     * @param float $x1 Bottom right x coordinate
     * @param float $y1 Bottom right y coordinate
     * @return ezcGraphBoundings
     */
    public function __construct( $x0 = 0., $y0 = 0., $x1 = null, $y1 = null )
    {
        $this->x0 = $x0;
        $this->y0 = $y0;
        $this->x1 = $x1;
        $this->y1 = $y1;

        // Switch values to ensure correct order
        if ( $this->x0 > $this->x1 )
        {
            $tmp = $this->x0;
            $this->x0 = $this->x1;
            $this->x1 = $tmp;
        }

        if ( $this->y0 > $this->y1 )
        {
            $tmp = $this->y0;
            $this->y0 = $this->y1;
            $this->y1 = $tmp;
        }
    }

    /**
     * Getter for calculated values depending on the boundings.
     *  - 'width': Width of bounding recangle
     *  - 'height': Height of bounding recangle
     * 
     * @param string $name Name of property to get
     * @return mixed Calculated value
     */
    public function __get( $name )
    {
        switch ( $name )
        {
            case 'width':
                return $this->x1 - $this->x0;
            case 'height':
                return $this->y1 - $this->y0;
            default:
                throw new ezcBasePropertyNotFoundException( $name );
        }
    }
}

?>
OpenPOWER on IntegriCloud