メインコンテンツまでスキップ

ポイントと矩形

SenseTalkは幾何学的なポイントと矩形の概念を理解します。

SenseTalkのポイントと矩形

任意の2つの数値のリスト、またはコンマで区切られた2つの数値からなるテキスト文字列は、ポイントとして扱われます。最初の数値はポイントのX座標を表し、2つ目の数値はY座標を表します:

put [150,47] into pointA
put "250,98" into pointB

矩形は、任意の2つのポイントのリスト、4つの数値のリスト、またはコンマで区切られた4つの数値からなるテキスト文字列(2つのポイントを表す)によって表されます。2つのポイントは矩形の対角線上の2つの角を示します(上左と下右の角、または下左と上右の角、どちらの順番でも可)。

put [pointA,pointB] into myRect
put "15,28,19,72" into bounds

is withinオペレータは、ポイントが矩形内に存在するか、あるいは一つの矩形が他の矩形の完全に内部に存在するかをテストするために使用できます(詳細は Expressions を参照してください):

if [18,35] is within bounds then scoreHit

X, Y, Width, Height, Origin, そして Size 関数

振る舞い: これらの関数は、ポイントや矩形の各成分値を抽出するために使用できます。xyの関数は、ポイントや矩形に使用して、ポイントのx座標とy座標、または矩形の原点の座標を取得することができます。originsizeの関数は、矩形に使用して、原点(最小のx座標とy座標)とサイズ(幅と高さを表す2つの数値のリスト)を取得することができます。widthheightの関数は、矩形やサイズに使用して、幅または高さを取得することができます。

構文:

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

例:

これらの関数は、オブジェクトのプロパティにアクセスするのと同様の、ドット(.)、アポストロフィ-S(‘s)またはofの構文で最も一般的に使用されますが、これらはプロパティではなく、読み取り専用の値を返す関数であることを覚えておいてください:

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, そして RightCenter 関数

振る舞い: これらの関数は、矩形の各部分の座標を見つけるために使用することができます。

topbottomleft、そしてright関数は、矩形の上または下のエッジのy座標、または左または右のエッジのx座標を返す単一の数値を返します。

topLefttopRightbottomLeft、そしてbottomRight関数は、矩形の指定した角の点の座標を返します。

center関数は、矩形の中心の座標を返し、topCenterbottomCenterleftCenter、そしてrightCenter関数は、矩形の指定したエッジの中心の点の座標を返します。

文法:

{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 )

例:

これらの関数は、オブジェクトのプロパティにアクセスするのと同様の、ドット(.)、アポストロフィ-S(‘s)またはofの構文で最も一般的に使用されますが、これらはプロパティではなく、読み取り専用の値を返す関数であることを覚えておいてください:

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

Distance 関数

動作: Distance関数は、2つの点の距離を返します。2次元および3次元の両方の点がサポートされています。

md 構文:
{the} distance between point1 and point2
{the} distance from point1 to point2
distance( point1 , point2 )

テックトーク

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