Rect Class

The Rect object is most often used to represent a rectangle on a coordinate system, specifically the coordinate system used by Windows where the upper left corner is considered (0,0). However, it is convenient to use the Rect object for other things, for instance the margin around a rectangle.

Requires:

The Rect class requires the class definition file oodPlain.cls:

::requires "oodPlain.cls"

Methods:

Instances of the Rect class implement the methods listed in the following table:

Table 10-3. Rect Instance Methods

Method......on page
new (Class Method)new
bottombottom
bottom=bottom=
leftleft
left=left=
rightright
right=right=
toptop
top=top=

new (Class Method)

               +-0----+     +-left-+     +-left--+     +-left---+
>>-aRect~new(--+------+--,--+------+--,--+-------+--,--+--------+--)------><
               +-left-+     +-top--+     +-right-+     +-bottom-+

Instantiates a new Rect object. All the arguments are whole numbers.

Arguments:

The arguments are:

left

The left postion. The default is 0.

top

The top position. The default is the value of left.

right

The right position. The default is the value of left.

bottom

The bottom position. The default is the value of left.

Return value:

The new Rect object is returned.

Example:

r = .Rect~new(3, 4, 13, 9)
say 'Upper corner ('r~left','r~top') lower corner 'r~right','r~bottom')'
say
margin = .Rect~new(5)
say 'Margins:'
say '  Left: ' margin~left
say '  Top   ' margin~top
say '  Right ' margin~right
say '  Bottom' margin~bottom
say

r~left = 55
r~top = 75
r~right = 110
r~bottom = 125
say 'New upper corner ('r~left','r~top') new lower corner 'r~right','r~bottom')'
say

/* Output would be:
Upper corner (3,4) lower corner 13,9)

Margins:
  Left:  5
  Top    5
  Right  5
  Bottom 5

New upper corner (55,75) new lower corner 110,125)

/*

left

>>-aRect~left----------------------------------------------><

Retrieves the left value of the rectangle.

Arguments:

This method takes no arguments

Return value:

The return value is the numeric value for the left of the rectangle.

Example:

See .Rect~new example.

left=

>>-aRect~left=value----------------------------------------><

Sets the left value of the rectangle.

Arguments:

This has one argument:

value

The left value for the rectangle.

Return value:

This method does not return a value.

Example:

See .Rect~new example.

top

>>-aRect~top-----------------------------------------------><

Retrieves the top value of the rectangle.

Arguments:

This method takes no arguments

Return value:

The return value is the numeric value for the top of the rectangle.

Example:

See .Rect~new example.

top=

>>-aRect~top=value-----------------------------------------><

Sets the top value of the rectangle.

Arguments:

This method takes one argument:

value

The top value for the rectangle.

Return value:

This method does not return any value.

Example:

See .Rect~new example.

right

>>-aRect~right---------------------------------------------><

Retrieves the right value of the rectangle.

Arguments:

This method takes no arguments

Return value:

The return value is the numeric value for the right of the rectangle.

Example:

See .Rect~new example.

right=

>>-aRect~right=value---------------------------------------><

Sets the right value of the rectangle.

Arguments:

This method has one argument:

value

The new right value for the rectangle.

Return value:

There is nor return value for this method.

Example:

See .Rect~new example.

bottom

>>-aRect~bottom--------------------------------------------><

Retrieves the bottom value of the rectangle.

Arguments:

This method takes no arguments

Return value:

The return value is the numeric value for the bottom of the rectangle.

Example:

See .Rect~new example.

bottom=

>>-aRect~bottom=value--------------------------------------><

Sets the bottom value of the rectangle.

Arguments:

This method has one argument:

value

The bottom value for the rectangle.

Return value:

The method does not return a value.

Example:

See .Rect~new example.