Skip to main content
Version: 26.3

Points and Rectangles

SenseTalk understands the concepts of geometric points and rectangles.

Points and Rectangles in SenseTalk​

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:

if [18,35] is within bounds then scoreHit

X, Y, Width, Height, Origin, and Size Functions​

Behavior: 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.

Syntax:

{the} x of pointOrRectanglex( pointOrRectangle )
{the} y of pointOrRectangley( pointOrRectangle )
{the} width of rectanglewidth( rectangle )
{the} height of rectangleheight( rectangle )
{the} origin of rectangleorigin( rectangle )
{the} size of rectanglesize( 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 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

Top, Bottom, Left, Right, TopLeft, TopRight, BottomLeft, BottomRight, Center, TopCenter, BottomCenter, LeftCenter, and RightCenter Functions​

Behavior: 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 (and their synonyms leftTop, rightTop, leftBottom and rightBottom) 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 (and their synonyms centerTop, centerBottom, centerLeft, and centerRight) return the coordinates of the point at the center of the indicated edge of a rectangle.

Syntax:

{the} top of rectangletop( rectangle )
{the} bottom of rectanglebottom( rectangle )
{the} left of rectangleleft( rectangle )
{the} right of rectangleright( rectangle )
{the} topLeft of rectangletopLeft( rectangle )
{the} topRight of rectangletopRight( rectangle )
{the} bottomLeft of rectanglebottomLeft( rectangle )
{the} bottomRight of rectanglebottomRight( rectangle )
{the} center of rectanglecenter( rectangle )
{the} topCenter of rectangletopCenter( rectangle )
{the} bottomCenter of rectanglebottomCenter( rectangle )
{the} leftCenter of rectangleleftCenter( rectangle )
{the} rightCenter of rectanglerightCenter( 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

TopHalf, BottomHalf, LeftHalf, and RightHalf Functions​

Behavior: These functions can be used to obtain a sub-rectangle that is one half of an existing rectangle.

The topHalf, bottomHalf, leftHalf and rightHalf functions return the coordinates of the sub-rectangle for the indicated half of a rectangle.

Syntax:Alternate Syntax:
{the} topHalf of rectangletopHalf( rectangle )
{the} bottomHalf of rectanglebottomHalf( rectangle )
{the} leftHalf of rectangleleftHalf( rectangle )
{the} rightHalf of rectanglerightHalf( rectangle )

Examples:

put screenRectangle's topHalf into upperPortionRect
put the leftHalf of doorFrame into leftDoor

TopLeftQuadrant, TopRightQuadrant, BottomLeftQuadrant, and BottomRightQuadrant Functions​

Behavior: These functions can be used to obtain a sub-rectangle that is one quarter of an existing rectangle.

The topLeftQuadrant, topRightQuadrant, bottomLeftQuadrant and bottomRightQuadrant functions (and their synonyms leftTopQuadrant, rightTopQuadrant, leftBottomQuadrant, and rightBottomQuadrant) return the coordinates of the sub-rectangle that is one-fourth of the source rectangle in the indicated corner.

Syntax:Alternate Syntax:
{the} topLeftQuadrant of rectangle or {the} leftTopQuadrant of rectangletopLeftQuadrantop( rectangle ) or leftTopQuadrant( rectangle )
{the} topRightQuadrant of rectangle or {the} rightTopQuadrant of rectangletopRightQuadrant( rectangle ) or rightTopQuadrant( rectangle )
{the} bottomLeftQuadrant of rectangle or {the} leftBottomQuadrant of rectanglebottomLeftQuadrant( rectangle ) or leftBottomQuadrant( rectangle )
{the} bottomRightQuadrant of rectangle or {the} rightBottomQuadrant of rectanglebottomRightQuadrant( rectangle ) or rightBottomQuadrant( rectangle )

Examples:

put boundingBox.topRightQuadrant into topQuarter
put the bottomLeftQuadrant of bounds into lowerLeftPortion

Distance Function​

Behavior: The Distance function returns the distance between two points. Both 2-D and 3-D points are supported.

Syntax:
{the} distance between point1 and point2
{the} distance from point1 to point2
distance( point1 , point2 )

Examples:

put the distance from [100,100] to [130,140] --> 50

set myRect to [0,0,24,10]
put the distance between myRect.topLeft and myRect.center --> 13

put distance(startPoint, endPoint) into distanceTraveled

put distance from [12,14,50] to [48,17,22] --> 45.70558