CRect:Normalize CRect:PtInside

CRect:Offset


The Offset method moves a rectangle to new coordinates. The offset can be specified in several different ways so that this method can work as a move, resize, or addition of the corresponding edge coordinates. The offsets can be positive or negative.

Syntax

CRect:Offset( CRect2 )

CRect:Offset( x )

CRect:Offset( x, y )

CRect:Offset( x1, x2, y1, y2 )

  • CRect2 is another CRect object.
  • x is a single offset applied to all edges.
  • x and y are offsets applied equally to parallel sides.
  • x1, x2, y1, y2 are applied independently to all 4 sides.

Remarks

The specified offset values are added to the edge coordinates of the rectangle. Using the 3 different argument lists gives great flexibility in changing the rectangle dimensions:

The difference between Offset and Inflate is that Offset adds positive offsets to all 4 edges, whereas Inflate subtracts positive offsets from the minimum edges while adding positive offsets to the maximum edges.

Example

The following script moves and resizes the CRect R using various argument lists. Note that CRect:Get returns 4 arguments, which can be automatically filled into the 4 fields of the Printf function as shown.

R = CRect:new()

-- create a CRect object R

R:Set(100, 200, 300, 600)

 

Printf("%lg:%lg, %lg:%lg\n", R:Get())

-- result: 100:200, 300:600.

 

 

R:Offset( 2, 10, 4, 20 )

-- move and resize the rectangle R

Printf("%lg:%lg, %lg:%lg\n", R:Get())

-- result: 102:210, 304:620.

 

 

R:Offset( 0, 30, 0, 40 )

-- resize the rectangle R

Printf("%lg:%lg, %lg:%lg\n", R:Get())

-- result: 102:240, 310:660.

 

 

R:Offset( 100, -200 )

-- move the rectangle R

Printf("%lg:%lg, %lg:%lg\n", R:Get())

-- result: 202:340, 110:460.

 

 

R:Offset( 10 )

-- move the rectangle R

Printf("%lg:%lg, %lg:%lg\n", R:Get())

-- result: 212:350, 120:470.

 

 

Rnew = CRect:new( 0, 60, 0, 80 )

-- create another CRect object

R:Offset( Rnew )

-- resize R using another rectangle

Printf("%lg:%lg, %lg:%lg\n", R:Get())

-- result: 212:410, 120:550.

Related Topics

CRect, Union, Intersection, Inflate