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.
The Rect class requires the class definition file oodPlain.cls:
::requires "oodPlain.cls"
Instances of the Rect class implement the methods listed in the following table:
+-0----+ +-left-+ +-left--+ +-left---+
>>-aRect~new(--+------+--,--+------+--,--+-------+--,--+--------+--)------><
+-left-+ +-top--+ +-right-+ +-bottom-+
Instantiates a new Rect object. All the arguments are whole numbers.
The arguments are:
The left postion. The default is 0.
The top position. The default is the value of left.
The right position. The default is the value of left.
The bottom position. The default is the value of left.
The new Rect object is returned.
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)
/*
>>-aRect~left----------------------------------------------><
Retrieves the left value of the rectangle.
This method takes no arguments
The return value is the numeric value for the left of the rectangle.
See .Rect~new example.
>>-aRect~left=value----------------------------------------><
Sets the left value of the rectangle.
This has one argument:
The left value for the rectangle.
This method does not return a value.
See .Rect~new example.
>>-aRect~top-----------------------------------------------><
Retrieves the top value of the rectangle.
This method takes no arguments
The return value is the numeric value for the top of the rectangle.
See .Rect~new example.
>>-aRect~top=value-----------------------------------------><
Sets the top value of the rectangle.
This method takes one argument:
The top value for the rectangle.
This method does not return any value.
See .Rect~new example.
>>-aRect~right---------------------------------------------><
Retrieves the right value of the rectangle.
This method takes no arguments
The return value is the numeric value for the right of the rectangle.
See .Rect~new example.
>>-aRect~right=value---------------------------------------><
Sets the right value of the rectangle.
This method has one argument:
The new right value for the rectangle.
There is nor return value for this method.
See .Rect~new example.