CRect Class


The CRect class encapsulates functionality for a rectangle object used in computing statistics, setting window boundaries, setting the image cursor for measurements, plots, etc. The rectangle properties include 4 numbers that define the coordinates of the rectangle edges. You also can use the CRect class to hold 4 arbitrary numbers which can be processed together using the class methods and operators.

Usage

Construction

Object = NewRect() (global function with several overloads)

Object = CRect:new() (class method with several overloads)

Destruction

Object:delete()

Class Properties

These properties specify the rectangle coordinate limits of the CRect object. You can set them directly or by using several methods.

Methods

Construction

NewRect

Global function that creates a new CRect object.

new

Creates a new CRect object. Same as NewRect.

delete

Deletes the instance of the CRect object.

Operators

The CRect class contains numerous math operators so you can use CRect objects in expressions, like R=(R1+R2)/2. These are described on the CRect Operators page.

Accessing Properties

In addition to using the properties by name, like R.xmin, the methods below allow you to set or get all the properties in one operation.

Get

Returns the 4 properties corresponding to the min and max x values and the min and max y values of the rectangle.

Set

Sets the 4 properties for the x and y limits of the rectangle.

Operations

Ceil

Rounds all rectangle values up to the next higher integer value.

Floor

Rounds all rectangle values down to the next lower integer value.

Height

Returns the height of the rectangle.

Inflate

Inflates a rectangle by pulling outward on all 4 sides.

Intersection

Returns a rectangle having the 4 inner dimensions of 2 overlapping rectangles.

Normalize

Normalizes the CRect so that the minimum is less than the maximum value in each direction.

Offset

Offsets a rectangle's sides to move and/or resize it.

PtInside

Returns true if the specified point x,y is inside the rectangle.

PtInsideInt

Returns true if the specified point x,y is inside the rectangle.

RectInside

Returns true if the specified rectangle is completely enclosed with the rectangle.

Round

Rounds the rectanble limits to the nearest integer value.

Size

Returns the width and height of the rectangle.

Union

Returns a rectangle having the 4 outer dimensions of 2 overlapping rectangles.

Width

Returns the width of the rectangle.

Related Topics

Image Coordinate System

Subpixel Coordinate Definition

Script Classes