CRect:PtInside


The PtInside method tests whether a point is interior to the CRect. The tests are made using <= or >= so that a point exactly on a CRect boundary is considered to be inside. The related PtInsideInt method tests the CRect using fuzzy integral boundaries.

Syntax

bSuccess = CRect:PtInside( CPoint )

bSuccess = CRect:PtInside( x, y )

where

    x, y are the point coordinates.

    CPoint is a CPoint object.

    bSuccess is returned true if the point is inside the rectangle, otherwise false.

Examples

The following script tests whether the point (225,300) is inside the CRect:

R = NewRect(200,250,250,500)

-- create a CRect object

x = 225 ; y = 300

 

test = R:PtInside(x,y)

-- returns test = true or false

Printf( "Inside= %d\n", test)

-- result: Inside = 1

The script below tests whether an object intended for photometry is entirely inside the image when the size of the outer background aperture is considered. Assume a CApphot object A and a CImage object I already exist. This script uses the radius of the outer aperture to define a zone to be avoided around the margin of the image. The value is increased by 1 pixel to handle fractional pixels that might otherwise push the edge of the aperture outside the image.

nBorder = A.nRadius3 + 1

-- get the radius of the outer aperture, add 1 pixel

R = NewRect()

-- create a CRect object

R:SetToImage( I )

-- give the rectangle the dimension of the image

R:Inflate( -nBorder, -nBorder )

-- shrink the CRect by (aperture radius + 1)

x = 225 ; y = 300

-- get some coordinates for the object

test = R:PtInside(x,y)

-- returns test = true or false

Printf( "Inside= %d\n", test)

 

Related Topics

PtInsideInt

RectInside

CRect class

CImage:PtInside