source: golgotha/src/maxtool/sdk_inc/ipoint2.h @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1/**********************************************************************
2 *<
3        FILE: ipoint2.h
4
5        DESCRIPTION: Class definintion for IPoint2: Integer 2D point.
6
7        CREATED BY: Dan Silva
8
9        HISTORY:
10
11 *>     Copyright (c) 1994, All Rights Reserved.
12 **********************************************************************/
13
14#ifndef __IPOINT2__
15
16#define __IPOINT2__
17
18class ostream;
19
20class IPoint2 {
21public:
22        int x,y;
23
24        // Constructors
25        IPoint2(){}
26        IPoint2(int X, int Y)  { x = X; y = Y;  }
27        IPoint2(const IPoint2& a) { x = a.x; y = a.y; }
28        IPoint2(int af[2]) { x = af[0]; y = af[1]; }
29
30        // Access operators
31        int& operator[](int i) { return (&x)[i]; }     
32        const int& operator[](int i) const { return (&x)[i]; } 
33
34        // Conversion function
35        operator int*() { return(&x); }
36         
37        // Unary operators
38        IPoint2 operator-() const { return(IPoint2(-x,-y)); }
39        IPoint2 operator+() const { return *this; }
40
41        // Assignment operators
42        IPoint2& operator-=(const IPoint2&);
43        IPoint2& operator+=(const IPoint2&);
44        DllExport IPoint2& operator*=(int);
45        DllExport IPoint2& operator/=(int);
46
47        // Binary operators
48        DllExport IPoint2 IPoint2::operator-(const IPoint2&) const;
49        DllExport IPoint2 IPoint2::operator+(const IPoint2&) const;
50        DllExport int DotProd(const IPoint2&) const;    // DOT PRODUCT
51        DllExport int operator*(const IPoint2&) const;    // DOT PRODUCT
52
53        // Relational operators
54        int operator==(const IPoint2& p) const { return (x == p.x && y == p.y); }
55        };
56
57int DllExport Length(const IPoint2&);
58IPoint2 DllExport Normalize(const IPoint2&); // Return a unit vector.
59IPoint2 DllExport operator*(int, const IPoint2&);       // multiply by scalar
60IPoint2 DllExport operator*(const IPoint2&, int);       // multiply by scalar
61IPoint2 DllExport operator/(const IPoint2&, int);       // divide by scalar
62
63ostream DllExport &operator<<(ostream&, const IPoint2&);
64
65// Inlines:
66
67inline int MaxComponent(const IPoint2& p) { return(p.x>p.y?0:1); }
68inline int MinComponent(const IPoint2& p) { return(p.x<p.y?0:1); }
69
70inline int Length(const IPoint2& v) {   
71        return (int)sqrt(v.x*v.x+v.y*v.y);
72        }
73
74inline IPoint2& IPoint2::operator-=(const IPoint2& a) {
75        x -= a.x;       y -= a.y; 
76        return *this;
77        }
78
79inline IPoint2& IPoint2::operator+=(const IPoint2& a) {
80        x += a.x;       y += a.y; 
81        return *this;
82        }
83
84inline IPoint2& IPoint2::operator*=(int f) {
85        x *= f;   y *= f;       
86        return *this;
87        }
88
89inline IPoint2& IPoint2::operator/=(int f) {
90        x /= f; y /= f;         
91        return *this;
92        }
93
94inline IPoint2 IPoint2::operator-(const IPoint2& b) const{
95        return(IPoint2(x-b.x,y-b.y));
96        }
97
98inline IPoint2 IPoint2::operator+(const IPoint2& b) const {
99        return(IPoint2(x+b.x,y+b.y));
100        }
101
102inline int IPoint2::DotProd(const IPoint2& b) const{
103        return(x*b.x+y*b.y);
104        }
105
106inline int IPoint2::operator*(const IPoint2& b)const {
107        return(x*b.x+y*b.y);
108        }
109
110inline IPoint2 operator*(int f, const IPoint2& a) {
111        return(IPoint2(a.x*f, a.y*f));
112        }
113
114inline IPoint2 operator*(const IPoint2& a, int f) {
115        return(IPoint2(a.x*f, a.y*f));
116        }
117
118inline IPoint2 operator/(const IPoint2& a, int f) {
119        return(IPoint2(a.x/f, a.y/f));
120        }
121
122#endif
123
Note: See TracBrowser for help on using the repository browser.