home *** CD-ROM | disk | FTP | other *** search
- File: MISC.TXT
- Path: ...\REHACK\TEXT\MISC.TXT
- Version: 0.01
- Author: Pat Reilly
- CIS Id: 71333,2764
- Created On: 6/23/93
- Modified On: 6/27/93
- Description: Documentation on class in MISC.HPP.
- Tabs: 4
-
- Class Point
- ===========
-
- Point encapsulates the idea of a two-dimensional point, using ints for the
- x,y coordinates. Unlike mathematical points, Point is a "computer science"
- point <g> - this means you can add two points together. Adding and subtracting
- Points is like the same operations for a 2-tuple: x += arg.x and y += arg.y.
- Point p1 = { 2, 3 };
- Point p2 = { 5, 7 };
- ...
- Point p3 = p1 + p2;
- // p3 = (2+5, 3+7) = (7,10)
- Though they could be, Points are not templated for support for the poor,
- misguided souls who are using MSC++ instead of BC++ <g>.
-
- The int x,y members for Point have public scope, so can be accessed directly:
- Point pt;
- pt.x = 3;
- pt.y = 4;
-
- Because Point has no constructors and no functions (not counting operators),
- you can initialize a static point using braces and an int list:
- Point point = { 3, 4 };
- The first value will be assigned to x, and the second value to y. Also, since
- there are no constructors, when first instantiated, a Point object has
- undefined values for x and y.
-
- Also the default copy constructor and assignment operator for Point (built by
- the compiler) work fine - you can do things like:
- Point point2 = point; // uses copy constructor.
- point2 = point; // uses assignment operator.
-
- Point overloads the binary operator += and -= so that Points can be added:
- Point p1, p2;
- p1 += p2;
- p1 -= p2;
-
- Point overloads the unary sign operators + and -
- Point point = -point2;
- point = +point2;
-
- Global binary operators + and - are also provided for adding a Points:
- Point point = p2 + p1;
- point = p2 - p1;
-
- ---------------------------------------------------------------------
-
- Class Rect
- ==========
-
- Rect encapsulates a two-dimensional rectangle, whose sides are parallel with
- the X and Y axes. Normally, a Rect is used for screen regions; because the
- screen is normally laid out so that the origin is at the top-left corner of
- the screen, and the +X axis extends right, and the +Y axis extends *down*,
- then the Point member topLeft should have the smallest X coordinate and the
- *smallest* Y coordinate; Point member bottomRight should have the largest
- X coordinate and the *largest* Y coordinate. IOW a Rect that defined the full
- screen for mode 13 (320x200) would be:
- topLeft = { 0, 0 };
- bottomRight = { 320, 200 };
- Notice also that Rect fully encloses the region it covers. IOW if Rect is
- used to encapsulate a region of the screen and it has topLeft = (0,0) and
- bottomRight = (4,4), then any Point pt = (4,y) or any Point pt = (x,4) will
- NOT be considered to be contained within the Rect. For screen pixels, you
- can consider that the Points topLeft and bottomRight are the *junctions*
- between pixels, whereas when testing a Point for inclusion, the Point is
- considered to be in the *center* of the pixel:
-
- topLeft
- o───┬─
- │ │ Rect(0,0, 1,1)
- │ X │
- │ │ ONLY Point X = { 0,0 } is contained.
- ├───o─ bottomRight
- │ │
-
-
- Rect cannot be instantiated with braces and an int list:
- Rect rect = { 0,0, 1,1 }; // <=== No! Compiler error.
-
- Rect has various constructors defined:
- Rect r;
- Rect r(0,0,1,1);
- Rect r(point1, point2);
- Rect r(rect);
-
- And various functions:
- isEmpty
- Returns true if its an empty rectangle. A Rect is considered empty
- if the left side is >= the right side, or if the top is >= bottom.
- contains
- Returns true if the point is contained in the Rect, else false.
- intersectWith
- Sets the rect to the intersection of itself and the arg rect. That
- is, the largest rect contained within both *this and the arg.
- unionWith
- Sets the rect to the union of itself and the arg rect. That is, the
- smallest rect which contains both *this and the arg.
- move
- Moves the rectangle the given distance and direction by adding the
- argument Point to the topLeft and bottomRight members.
-
- width
- Returns the width of the rect. If the rect isEmpty(), returns 0.
-
- height
- Returns the height of the rect. If the rect isEmpty(), returns 0.
-
- And various operators:
- ==
- Returns true if the arg rect has the same coords as *this; else false.
- !=
- Returns true if the arg rect doesn't have the same coords as *this;
- else false.
- +=
- Moves the rect in the direction/length of the Point.
- -=
- Moves the rect in the opposite direction/length of the Point.
- |=
- Calls unionWith.
- &=
- Calls intersectWith
-
- Also, global binary operators +, -, &, and | are provided, which correspond
- to +=, -=, &= and |= respectively.
-
-