Rectangle
class Rectangle (View source)
Rectangle rotation algebra class.
This class is used by the image system to abstract, from toolkit implementations, the calculation of the expected dimensions resulting from an image rotate operation.
Different versions of PHP for the GD toolkit, and alternative toolkits, use different algorithms to perform the rotation of an image and result in different dimensions of the output image. This prevents predictability of the final image size for instance by the image rotate effect, or by image toolkit rotate operations.
This class implements a calculation algorithm that returns, given input width, height and rotation angle, dimensions of the expected image after rotation that are consistent with those produced by the GD rotate image toolkit operation using PHP 5.5 and above.
Properties
| protected int | $width | The width of the rectangle. |
|
| protected int | $height | The height of the rectangle. |
|
| protected int | $boundingWidth | The width of the rotated rectangle. |
|
| protected int | $boundingHeight | The height of the rotated rectangle. |
Methods
Constructs a new Rectangle object.
Rotates the rectangle.
Performs an imprecision check on the input value and fixes it if needed.
Returns the fractional part of a float number, unsigned.
Returns the difference of a fraction from the closest between 0 and 1.
Gets the bounding width of the rectangle.
Gets the bounding height of the rectangle.
Details
__construct(int $width, int $height)
Constructs a new Rectangle object.
$this
rotate(float $angle)
Rotates the rectangle.
protected float
fixImprecision(float $input, float $imprecision)
Performs an imprecision check on the input value and fixes it if needed.
GD that uses C floats internally, whereas we at PHP level use C doubles. In some cases, we need to compensate imprecision.
protected float
fraction(float $input)
Returns the fractional part of a float number, unsigned.
protected float
delta(float $input)
Returns the difference of a fraction from the closest between 0 and 1.
int
getBoundingWidth()
Gets the bounding width of the rectangle.
int
getBoundingHeight()
Gets the bounding height of the rectangle.