CRect:Inflate


The Inflate method expands a rectangle outward on all 4 sides. Using positive values for the inflation, xmin and ymin are reduced while xmax and ymax are increased. You can inflate using either positive or negative values.

Syntax

CRect:Inflate( CRect2 )

CRect:Inflate( x )

CRect:Inflate( x, y )

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

bullet.gif    CRect2 is another CRect object.

bullet.gif    x is a single offset applied to all 4 edges.

bullet.gif    x and y are offsets applied equally to parallel sides.

bullet.gif    x1, x2, y1, y2 are applied independently to all 4 sides.

Remarks

Using the 3 different argument lists gives great flexibility in changing the rectangle dimensions:

bullet.gif    Use the 1 argument version with a CRect to inflate one rectangle using the edge coordinates of another.

bullet.gif    Use the 1 argument version with a number argument to inflate all 4 edges equally.

bullet.gif    Use the 2 argument version to inflate opposite edges by the same amount.

bullet.gif    Use the 4 argument version to inflate all edges by different amounts. This version works like the CRect version except that the offsets are given as numbers rather than by using another CRect.

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 inflates 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 = new_rect()

-- 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:Inflate( 2, 10, 4, 20 )

-- inflate the rectangle R

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

-- result: 98:210, 296:620.

 

 

R:Inflate( 100, 200 )

-- inflate the rectangle R

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

-- result: -2:410, 196:820.

 

 

R:Inflate( -100, -200 )

-- deflate the rectangle R

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

-- result: 98:210, 296:620.

 

 

R:Inflate( 10 )

-- inflate the rectangle R

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

-- result: 88:220, 286:630.

 

 

Rnew = new_rect( 0, 60, 40, 80 )

-- create another CRect object

R:Inflate( Rnew )

-- inflate R using another rectangle

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

-- result: 88:280, 246:710.

Related Topics

CRect class, Union, Intersection, Offset


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