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

__construct(int $width, int $height)

Constructs a new Rectangle object.

$this
rotate(float $angle)

Rotates the rectangle.

float
fixImprecision(float $input, float $imprecision)

Performs an imprecision check on the input value and fixes it if needed.

float
fraction(float $input)

Returns the fractional part of a float number, unsigned.

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.

Details

__construct(int $width, int $height)

Constructs a new Rectangle object.

Parameters

int $width

The width of the rectangle.

int $height

The height of the rectangle.

$this rotate(float $angle)

Rotates the rectangle.

Parameters

float $angle

Rotation angle.

Return Value

$this

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.

Parameters

float $input

The input value.

float $imprecision

The imprecision factor.

Return Value

float

A value, where imprecision is added to input if the delta part of the input is lower than the absolute imprecision.

protected float fraction(float $input)

Returns the fractional part of a float number, unsigned.

Parameters

float $input

The input value.

Return Value

float

The fractional part of the input number, unsigned.

protected float delta(float $input)

Returns the difference of a fraction from the closest between 0 and 1.

Parameters

float $input

The input value.

Return Value

float

the difference of a fraction from the closest between 0 and 1.

int getBoundingWidth()

Gets the bounding width of the rectangle.

Return Value

int

The bounding width of the rotated rectangle.

int getBoundingHeight()

Gets the bounding height of the rectangle.

Return Value

int

The bounding height of the rotated rectangle.