Source for file Rectangle.php
Documentation is available at Rectangle.php
* Description: Class to create the Rectangle object
* @copyright (c) 1995-2010 by Steema Software SL. All Rights Reserved. <info@steema.com>
* @link http://www.steema.com
function __get( $property ) {
$method = "get{$property}";
function __set ( $property,$value ) {
$method = "set{$property}";
return $this->$method($value);
function Rectangle($x = 0, $y = 0, $width = 0.0, $height = 0.0)
return $this->x + $this->width / 2.0;
return $this->y + $this->height / 2.0;
static public function fromLTRB($x, $y, $right, $bottom)
return new Rectangle($x, $y, $right - $x + 1, $bottom - $y + 1);
* Gets rectangle Right coordinate.
return $this->x + $this->width;
* Gets rectangle Bottom coordinate.
* Gets rectangle Left coordinate.
* Sets rectangle Left coordinate.
$this->width += $this->x - $value;
* Sets rectangle Right coordinate.
$this->width = $value - $this->x;
* Gets rectangle Top coordinate.
* Sets rectangle Top coordinate.
public function setTop($value)
$this->height += $this->y - $value;
* Sets rectangle Bottom coordinate.
self::__intersect($this, $value, $this);
public static function __intersect($src1, $src2, $dest)
$x1 = max($src1->getX(), $src2->getX());
$y1 = max($src1->getY(), $src2->getY());
$x2 = min($src1->getX() + $src1->getWidth(), $src2->getX() + $src2->getWidth());
$y2 = min($src1->getY() + $src1->getHeight(), $src2->getY() + $src2->getHeight());
$dest->setFrame($x1, $y1, $x2 - $x1, $y2 - $y1);
* Determines whether or not this <code>Rectangle</code> and the specified
* <code>Rectangle</code> intersect. Two rectangles intersect if
* their intersection is nonempty.
* @param r the specified <code>Rectangle</code>
* @return <code>true</code> if the specified <code>Rectangle</code>
* and this <code>Rectangle</code> intersect;
* <code>false</code> otherwise.
if($rw <= 0 || $rh <= 0 || $tw <= 0 || $th <= 0)
return(($rw < $rx || $rw > $tx) &&
($rh < $ry || $rh > $ty) &&
($tw < $tx || $tw > $rx) &&
($th < $ty || $th > $ry));
public function setFrame($x, $y, $w, $h)
* Returns the location of this <code>Rectangle</code>.
* This method is included for completeness, to parallel the
* <code>getLocation</code> method of <code>Component</code>.
* @return the <code>Point</code> that is the top-left corner of
* this <code>Rectangle</code>.
* Moves this <code>Rectangle</code> to the specified location.
* This method is included for completeness, to parallel the
* <code>setLocation</code> method of <code>Component</code>.
* @param p the <code>Point</code> specifying the new location
* for this <code>Rectangle</code>
* Determines whether or not this <code>Rectangle</code> is empty. A
* <code>Rectangle</code> is empty if its width or its height is less
* @return <code>true</code> if this <code>Rectangle</code> is empty;
* <code>false</code> otherwise.
public function inflate($horizontal, $vertical)
$this->width += $horizontal;
public function offset($w, $h)
* Resizes the <code>Rectangle</code> both horizontally and vertically.
* This method modifies the <code>Rectangle</code> so that it is
* <code>h</code> units larger on both the left and right side,
* and <code>v</code> units larger at both the top and bottom.
* The new <code>Rectangle</code> has (<code>x - h</code>,
* <code>y - v</code>) as its top-left corner, a
* <code>width</code> <code>+</code> <code>2h</code>,
* <code>height</code> <code>+</code> <code>2v</code>.
* If negative values are supplied for <code>h</code> and
* <code>v</code>, the size of the <code>Rectangle</code>
* The <code>grow</code> method does not check whether the resulting
* values of <code>width</code> and <code>height</code> are
* @param h the horizontal expansion
* @param v the vertical expansion
public function grow($h, $v)
|