home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / ams__l~1.zoo / include / shape.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-05  |  1.3 KB  |  49 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is part of the Atari Machine Specific Library,
  4. //  and is Copyright 1992 by Warwick W. Allison.
  5. //
  6. //  You are free to copy and modify these sources, provided you acknowledge
  7. //  the origin by retaining this notice, and adhere to the conditions
  8. //  described in the file COPYING.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. #ifndef _Shape_h
  12. #define _Shape_h
  13.  
  14. // 2D shapes
  15.  
  16. struct Point {
  17.     int x,y;
  18.     Point() : x(0), y(0) { }
  19.     Point(int X,int Y) : x(X), y(Y) { }
  20.     void MoveTo(int X,int Y) { x=X; y=Y; }
  21.     void MoveBy(int X,int Y) { x+=X; y+=Y; }
  22.     void Bound(const struct Rectangle& R);
  23. };
  24.  
  25. struct Line : Point {
  26.     Line() : end(1,0) { }
  27.     Line(int x1,int y1,int x2, int y2) : Point(x1,y1), end(x2,y2) { }
  28.     Point end;
  29. };
  30.  
  31. struct Rectangle : Point {
  32.     int w,h;
  33.     Rectangle() : w(1), h(1) { }
  34.     Rectangle(int X,int Y,int W, int H) : Point(X,Y), w(W), h(H) { }
  35.     void Area(int W,int H) { w=W; h=H; }
  36.     int Area() const { return w*h; }
  37.     Rectangle& operator*= (int m) { w*=m; h*=m; return *this; }
  38. };
  39.  
  40.  
  41. inline void Point::Bound(const Rectangle& R) {
  42.     if (x<R.x) x=R.x;
  43.     else if (x>=R.x+R.w) x=R.x+R.w-1;
  44.     if (y<R.y) y=R.y;
  45.     else if (y>=R.y+R.h) y=R.y+R.h-1;
  46. }
  47.  
  48. #endif
  49.