home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / rehack / text / misc.txt < prev    next >
Encoding:
Text File  |  1993-06-29  |  4.7 KB  |  137 lines

  1. File:            MISC.TXT
  2. Path:            ...\REHACK\TEXT\MISC.TXT
  3. Version:        0.01
  4. Author:            Pat Reilly
  5. CIS Id:            71333,2764
  6. Created On:        6/23/93
  7. Modified On:    6/27/93
  8. Description:    Documentation on class in MISC.HPP.
  9. Tabs:            4
  10.  
  11. Class Point
  12. ===========
  13.  
  14. Point encapsulates the idea of a two-dimensional point, using ints for the
  15. x,y coordinates. Unlike mathematical points, Point is a "computer science"
  16. point <g> - this means you can add two points together. Adding and subtracting
  17. Points is like the same operations for a 2-tuple: x += arg.x and y += arg.y.
  18.         Point p1 = { 2, 3 };
  19.         Point p2 = { 5, 7 };
  20.         ...
  21.         Point p3 = p1 + p2;
  22.         // p3 = (2+5, 3+7) = (7,10)
  23. Though they could be, Points are not templated for support for the poor,
  24. misguided souls who are using MSC++ instead of BC++ <g>.
  25.  
  26. The int x,y members for Point have public scope, so can be accessed directly:
  27.         Point pt;
  28.         pt.x = 3;
  29.         pt.y = 4;
  30.  
  31. Because Point has no constructors and no functions (not counting operators),
  32. you can initialize a static point using braces and an int list:
  33.         Point point = { 3, 4 };
  34. The first value will be assigned to x, and the second value to y. Also, since
  35. there are no constructors, when first instantiated, a Point object has
  36. undefined values for x and y.
  37.  
  38. Also the default copy constructor and assignment operator for Point (built by
  39. the compiler) work fine - you can do things like:
  40.         Point point2 = point;    // uses copy constructor.
  41.         point2 = point;            // uses assignment operator.
  42.  
  43. Point overloads the binary operator += and -= so that Points can be added:
  44.         Point p1, p2;
  45.         p1 += p2;
  46.         p1 -= p2;
  47.  
  48. Point overloads the unary sign operators + and -
  49.         Point point = -point2;
  50.         point = +point2;
  51.  
  52. Global binary operators + and - are also provided for adding a Points:
  53.         Point point = p2 + p1;
  54.         point = p2 - p1;
  55.  
  56. ---------------------------------------------------------------------
  57.  
  58. Class Rect
  59. ==========
  60.  
  61. Rect encapsulates a two-dimensional rectangle, whose sides are parallel with
  62. the X and Y axes. Normally, a Rect is used for screen regions; because the
  63. screen is normally laid out so that the origin is at the top-left corner of
  64. the screen, and the +X axis extends right, and the +Y axis extends *down*,
  65. then the Point member topLeft should have the smallest X coordinate and the
  66. *smallest* Y coordinate; Point member bottomRight should have the largest
  67. X coordinate and the *largest* Y coordinate. IOW a Rect that defined the full
  68. screen for mode 13 (320x200) would be:
  69.         topLeft =     { 0, 0 };
  70.         bottomRight = { 320, 200 };
  71. Notice also that Rect fully encloses the region it covers. IOW if Rect is
  72. used to encapsulate a region of the screen and it has topLeft = (0,0) and
  73. bottomRight = (4,4), then any Point pt = (4,y) or any Point pt = (x,4) will
  74. NOT be considered to be contained within the Rect. For screen pixels, you
  75. can consider that the Points topLeft and bottomRight are the *junctions*
  76. between pixels, whereas when testing a Point for inclusion, the Point is
  77. considered to be in the *center* of the pixel:
  78.  
  79.      topLeft
  80.         o───┬─
  81.         │   │                    Rect(0,0, 1,1)
  82.         │ X │
  83.         │   │                 ONLY Point X = { 0,0 } is contained.
  84.         ├───o─ bottomRight
  85.         │   │
  86.  
  87.  
  88. Rect cannot be instantiated with braces and an int list:
  89.         Rect rect = { 0,0, 1,1 };  // <=== No! Compiler error.
  90.  
  91. Rect has various constructors defined:
  92.         Rect r;
  93.         Rect r(0,0,1,1);
  94.         Rect r(point1, point2);
  95.         Rect r(rect);
  96.  
  97. And various functions:
  98.     isEmpty
  99.         Returns true if its an empty rectangle. A Rect is considered empty
  100.         if the left side is >= the right side, or if the top is >= bottom.
  101.     contains
  102.         Returns true if the point is contained in the Rect, else false.
  103.     intersectWith
  104.         Sets the rect to the intersection of itself and the arg rect. That
  105.         is, the largest rect contained within both *this and the arg.
  106.     unionWith
  107.         Sets the rect to the union of itself and the arg rect. That is, the
  108.         smallest rect which contains both *this and the arg.
  109.     move
  110.         Moves the rectangle the given distance and direction by adding the
  111.         argument Point to the topLeft and bottomRight members.
  112.  
  113.     width
  114.         Returns the width of the rect. If the rect isEmpty(), returns 0.
  115.  
  116.     height
  117.         Returns the height of the rect. If the rect isEmpty(), returns 0.
  118.  
  119. And various operators:
  120.     ==
  121.         Returns true if the arg rect has the same coords as *this; else false.
  122.     !=
  123.         Returns true if the arg rect doesn't have the same coords as *this;
  124.         else false.
  125.     +=
  126.         Moves the rect in the direction/length of the Point.
  127.     -=
  128.         Moves the rect in the opposite direction/length of the Point.
  129.     |=
  130.         Calls unionWith.
  131.     &=
  132.         Calls intersectWith
  133.  
  134. Also, global binary operators +, -, &, and | are provided, which correspond
  135. to +=, -=, &= and |= respectively.
  136.  
  137.