# Points and Rectangles

SenseTalk understands the concepts of geometric points and rectangles. Any list of two numbers, or a text string consisting of two numbers separated by a comma, can be treated as a point. The first number represents the X coordinate of the point, and the second number the Y coordinate:

put (150,47) into pointA

put "250,98" into pointB

A rectangle can be represented by any list of two points, by a list of four numbers or by a text string consisting of four numbers separated by commas (representing two points). The two points indicate two opposite corners of the rectangle (either the top-left and bottom-right corners, or the bottom-left and top-right corners, listed in either order).

put (pointA,pointB) into myRect

put "15,28,19,72" into bounds

The is within operator can be used to test whether a point lies within a rectangle or one rectangle is completely within another (see the full description in Expressions):

if (18,35) is within bounds then scoreHit

### x, y, width, height, origin, and size functions

#### What it Does

These functions can be used to extract the various component values of a point or rectangle. The functions x() and y() can be used with points and rectangles to obtain the x and y coordinates of the point, or of the origin point of the rectangle. The origin() and size() functions can be used with rectangles to obtain the origin point (the minimum x and y values) and the size (a list of two numbers representing the width and height, respectively) of the rectangle. The width() and height() functions can be used with rectangles or sizes to obtain the width or height.

#### Examples

These functions are most commonly used with the dot (.), apostrophe-S (‘s) or “of” syntax, similar to accessing a property of an object, but keep in mind that these functions return read-only values only:

put pointA.x into horizontalLocation

put the y of pointA into verticalLocation

put myRect's origin into topLeftCorner

put the size of bounds into outerRect

put height of imageRect into verticalSpaceNeeded

Tech Talk

Syntax:

 {the} x of pointOrRectangle x(pointOrRectangle) {the} y of pointOrRectangle y(pointOrRectangle) {the} width of rectangle width(rectangle) {the} height of rectangle height(rectangle) {the} origin of rectangle origin(rectangle) {the} size of rectangle size(rectangle)

### top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight, center, topCenter, bottomCenter, leftCenter, and rightCenter functions

#### What it Does

These functions can be used to find the coordinates of various parts of a rectangle.

The top(), bottom(), left() and right() functions return a single number which is the y coordinate of the top or bottom edge, or the x coordinate of the left or right edge, respectively, of a rectangle.

The topLeft(), topRight(), bottomLeft() and bottomRight() functions return the coordinates of the point at the indicated corner of a rectangle.

The center() function returns the coordinates of the center of a rectangle, and the topCenter(), bottomCenter(), leftCenter() and rightCenter() functions return the coordinates of the point at the center of the indicated edge of a rectangle.

#### Examples

These functions are most commonly used with the dot (.), apostrophe-S (‘s) or “of” syntax, similar to accessing a property of an object, but keep in mind that these are not properties, but functions which return read-only values:

put boundingBox.top into highestEdge

put the bottomRight of doorFrame into anchorPoint

put myRect's center into centerPoint

put the leftCenter of bounds into alignmentPoint

Tech Talk

Syntax:

 {the} top of rectangle top(rectangle) {the} bottom of rectangle bottom(rectangle) {the} left of rectangle left(rectangle) {the} right of rectangle right(rectangle) {the} topLeft of rectangle topLeft(rectangle) {the} topRight of rectangle topRight(rectangle) {the} bottomLeft of rectangle bottomLeft(rectangle) {the} bottomRight of rectangle bottomRight(rectangle) {the} center of rectangle center(rectangle) {the} topCenter of rectangle topCenter(rectangle) {the} bottomCenter of rectangle bottomCenter(rectangle) {the} leftCenter of rectangle leftCenter(rectangle) {the} rightCenter of rectangle rightCenter(rectangle)

This topic was last updated on November 20, 2019, at 03:32:06 PM.