CPoint:Offset


The Offset method adds a numeric offset to the x and y members of the CPoint. For example, consider applying an offset of (4,6). Then x=1.3 becomes x=5.3, and x=-16.2 becomes x=-10.2.

Syntax

P = CPoint:Offset( dx )

P = CPoint:Offset( dx, dy )

P = CPoint:Offset( CPoint_old )

P = CPoint:Offset( CRect_old )

P = CPoint:Offset( tblOffset )

bullet.gif    dx is the offset to apply to both the x and y members of the CPoint.

bullet.gif    dx and dy are offset values to apply respectively to the x and y members of the CPoint.

bullet.gif    CPoint_old is another CPoint object. Its x and y members are used as offsets to the x and y members of the current CPoint.

bullet.gif    CRect_old is a CRect object. Its Width and Height are used respectively as offsets for the x and y members of the CPoint.

bullet.gif    tblOffset is a 1-dimensional array. Element 1 is used to offset the x member and element 2 is used to offset the y member of the CPoint.

bullet.gif    P returned is the original CPoint object. This allows the Offset method to be used as part of an operator expression, if desired.

bullet.gif    On failure, nil is returned.

Example

The following script creates a CPoint object and applies an Offset to its values.

P = new_point(4.4,-12.7)

-- create a CPoint object

Printf("x=%lg, y=%lg\n", P.x, P.y)

-- result: x=4.4, y=-12.7

P:Offset( -4, 6 )

-- offset the values

Printf("x=%lg, y=%lg\n", P.x, P.y)

-- result: x=0.4, y=-6.7

P:Offset( new_rect(1,2,5,8) )

-- create a rectable offset in the method call

Printf("x=%lg, y=%lg\n", P.x, P.y)

-- result: x=1.4, y=-3.7 (apply width and height)

Related Topics

CPoint class, CRect class, CPoint Math Operators


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.