Rect Type

In bot scripts rectangles can be represented using Botfather’s inbuild Rect object. A Rect is described by it’s top left corner and size. The Rect type provides methods to work with rectangles conveniently (rects short).

Table of contents

Creating Rect objects

A non empty Rect object can be created by providing the Rects top left corner and size or it’s top left and bottom right corners. The corner position must be represented using the Point type and sizes using the Size type. Providing no parameters results in an empty rectangle being created.

Rect methods

Rect.isEmpty();

Returns true if the rectangle is empty, otherwise returns false.

Rect.getTop();

Returns the y-coordinate of the rectangle’s top edge.

Rect.getLeft();

Returns x-the coordinate of the rectangle’s left edge.

Rect.getRight();

Returns the x-coordinate of the rectangle’s right edge.

Rect.getBottom();

Returns the coordinate of the rectangle’s bottom edge.

Rect.getCenter();

Returns the center Point of the rectangle.

Rect.getTopLeft();

Returns the position of the rectangle’s top-left corner as a Point.

Rect.getTopRight();

Returns the position of the rectangle’s top-right corner as a Point.

Rect.getBottomLeft();

Returns the position of the rectangle’s bottom-left corner as a Point.

Rect.getBottomRight();

Returns the position of the rectangle’s bottom-right corner as a Point.

Rect.getWidth();

Returns the width of the rectangle.

Rect.setWidth(width);

Sets the width of the rectangle to the given width. The right edge is changed, but not the left one.

Rect.getHeight();

Returns the height of the rectangle.

Rect.setHeight(height);

Sets the height of the rectangle to the given height. The bottom edge is changed, but not the top one.

Rect.getSize();

Returns the Size of the rectangle.

Rect.moveTop(top);

Moves the rectangle vertically, leaving the rectangle’s top edge at the given top coordinate. The rectangle’s size is unchanged.

Rect.moveLeft(left);

Moves the rectangle horizontally, leaving the rectangle’s left edge at the given left coordinate. The rectangle’s size is unchanged.

Rect.moveRight(right);

Moves the rectangle horizontally, leaving the rectangle’s right edge at the given right coordinate. The rectangle’s size is unchanged.

Rect.moveBottom(bottom);

Moves the rectangle vertically, leaving the rectangle’s bottom edge at the given bottom coordinate. The rectangle’s size is unchanged.

Rect.marginsAdded(margins)

Returns a rectangle grown by the margins.

Rect.marginsSubtracted(margins)

Removes the margins from the rectangle, shrinking it.

Rect.contains(point, proper);

Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false. If proper is true, this function only returns true if the given point is inside the rectangle (i.e., not on the edge).

Rect.contains(other_rect, proper);

Returns true if the given rectangle is inside this rectangle. If proper is true, this function only returns true if the given other_rect is inside the rectangle (i.e., not on the edge).

Rect.intersects(other_rect);

Returns true if this rectangle intersects with the given rectangle, otherwise returns false.

Rect.united(other_rect);

Returns the bounding rectangle of this rectangle and the given other_rect rectangle as a new Rect.

Rect.randomPoint();

Generates and returns a random point within the rectangle.