CPoint:Math Operators
The CPoint class allows several common arithmetic and comparison operations to be performed directly between objects without using class methods. This is an object oriented feature, similar to operator overloading in other modern computer languages.
Class operators make it possible for a script to contain expressions like the following between CPoint objects Pt1 and Pt2:
PtResult = (Pt1 + 0.08) / Pt2
PtResult = -Pt1 + Pt2:Offset(-3.4,12) + 1.2
Operators do not modify the original point object, and a new CPoint object is created for the result of the expression. For example, in the above examples, the object PtResult does not need to be created before its use.
NOTE: Since expressions are evaluated left to right, the order of objects is important. When a table or value is to be used by the CPoint object in an expression, the CPoint object must precede the table or value so that CPoint operator methods are called to apply the table or value. For example, P3=P2+{2,4} is valid, but P3={2,4}+P2 causes a script error because a raw table like {2,4} has no methods.
In the description of the operators below, the following definitions are used:
Pt1, Pt2, Pt3 |
CPoint objects which are combined using the arithmetic operation, member for member. For example, Pt2.x is applied to Pt1.x and Pt2.y is applied to Pt1.y. |
tbl |
A 2-element array with elements tbl[1] and tbl[2], in which tbl[1] is applied to the x member and tbl[2] is applied to the y member of the CPoint. |
number |
A numeric value, like 2 or -15.66, which is applied to both the x and y members of the CPoint. |
rect |
A CRect object. The rectangle width is applied to the x member of the CPoint and the rectangle height is applied to the y member of the CPoint. |
The operations described below work between the CPoint class and objects listed in the table above:
Pt1 + object |
Adds the second object to the CPoint object and creates a new CPoint for the result. Examples: Pt3 = Pt1 + Pt2 Pt2 = Pt1 + number Pt2 = Pt1 + tbl Pt2 = Pt1 + rect |
Pt1 - object |
Subtracts the second object from the CPoint object and creates a new CPoint for the result. Examples: Pt3 = Pt1 - Pt2 Pt2 = Pt1 - number Pt2 = Pt1 - tbl Pt2 = Pt1 - rect |
Pt1 * object |
Multiplies the second object by the CPoint object and creates a new CPoint for the result. Examples: Pt3 = Pt1 * Pt2 Pt2 = Pt1 * number Pt2 = Pt1 * tbl Pt2 = Pt1 * rect |
Pt1 / object |
Divides the second object into the CPoint object and creates a new CPoint for the result. Examples: Pt3 = Pt1 / Pt2 Pt2 = Pt1 / number Pt2 = Pt1 / tbl Pt2 = Pt1 / rect |
Pt1 ^ object |
Raises the CPoint to a power given by the second object and creates a new CPoint for the result. Examples: Pt3 = Pt1 ^ Pt2 Pt2 = Pt1 ^ number Pt2 = Pt1 ^ tbl Pt2 = Pt1 ^ rect |
-Pt1 |
Calculates the unary minus of both members, so that Pt1.x = -Pt1.x and Pt1.y = -Pt1.y. |
Pt1 == object |
Compares the second object with the CPoint object. It returns true if the two objects are equal. Examples: Pt1 == Pt2 returns true if the xand y members of both objects are equal. Pt1 == number returns true if the xand y members of the CPoint equal the number. Pt1 == tbl returns true if the xmember equals tbl[1]and the y member equals tbl[2]. Pt1 == rect returns true if the xmember equals the rectangle width and the ymember equals the rectangle height. |
Pt1 <= object |
Compares the second object with the CPoint object. It returns true if both CPoint members are numerically less than or equal to the object. Examples: Pt1 <= Pt2 returns true if Pt1.x <= Pt2.xand Pt1.y <= Pt2.y. Pt1 <= number returns true if Pt1.x<= num and Pt1.y <= num. Pt1 <= tbl returns true if Pt1.x <= tbl[1]and Pt1.y <= tbl[2]. Pt1 <= rect returns true if Pt1.x <= rect:Width()and Pt1.y <= rect:Height(). |
Pt1 < object |
Compares the second object with the CPoint object. It returns true if both CPoint members are numerically less than the object. Examples: Pt1 < Pt2 returns true if Pt1.x < Pt2.xand Pt1.y < Pt2.y. Pt1 < number returns true if Pt1.x< num and Pt1.y < num. Pt1 < tbl returns true if Pt1.x < tbl[1]and Pt1.y < tbl[2]. Pt1 < rect returns true if Pt1.x < rect:Width()and Pt1.y < rect:Height(). |
Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024
Mirametrics, Inc. All Rights Reserved.