1 | /**********************************************************************
|
---|
2 | *<
|
---|
3 | FILE: ipoint3.h
|
---|
4 |
|
---|
5 | DESCRIPTION: Class definitions for IPoint3
|
---|
6 |
|
---|
7 | CREATED BY: Dan Silva
|
---|
8 |
|
---|
9 | HISTORY:
|
---|
10 |
|
---|
11 | *> Copyright (c) 1994, All Rights Reserved.
|
---|
12 | **********************************************************************/
|
---|
13 |
|
---|
14 | #ifndef __IPOINT3__
|
---|
15 |
|
---|
16 | #define __IPOINT3__
|
---|
17 |
|
---|
18 | class ostream;
|
---|
19 |
|
---|
20 | class IPoint3 {
|
---|
21 | public:
|
---|
22 | int x,y,z;
|
---|
23 |
|
---|
24 | // Constructors
|
---|
25 | IPoint3(){}
|
---|
26 | IPoint3(int X, int Y, int Z) { x = X; y = Y; z = Z; }
|
---|
27 | IPoint3(const IPoint3& a) { x = a.x; y = a.y; z = a.z; }
|
---|
28 | IPoint3(int ai[3]) { x = ai[0]; y = ai[1]; z = ai[2]; }
|
---|
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 | IPoint3 operator-() const { return(IPoint3(-x,-y,-z)); }
|
---|
39 | IPoint3 operator+() const { return *this; }
|
---|
40 |
|
---|
41 | // Assignment operators
|
---|
42 | DllExport IPoint3& operator-=(const IPoint3&);
|
---|
43 | DllExport IPoint3& operator+=(const IPoint3&);
|
---|
44 |
|
---|
45 | // Binary operators
|
---|
46 | DllExport IPoint3 operator-(const IPoint3&) const;
|
---|
47 | DllExport IPoint3 operator+(const IPoint3&) const;
|
---|
48 | DllExport int operator*(const IPoint3&) const; // DOT PRODUCT
|
---|
49 | DllExport int DotProd(const IPoint3&) const; // DOT PRODUCT
|
---|
50 | DllExport IPoint3 operator^(const IPoint3&) const; // CROSS PRODUCT
|
---|
51 | DllExport IPoint3 CrossProd(const IPoint3&) const; // CROSS PRODUCT
|
---|
52 |
|
---|
53 | // Relational operators
|
---|
54 | int operator==(const IPoint3& p) const { return (x == p.x && y == p.y && z == p.z); }
|
---|
55 | };
|
---|
56 |
|
---|
57 | // friends, so you can write Length(A) instead of A.Length(), etc.
|
---|
58 | int DllExport MaxComponent(const IPoint3&); // the component with the maximum abs value
|
---|
59 | int DllExport MinComponent(const IPoint3&); // the component with the minimum abs value
|
---|
60 |
|
---|
61 | ostream DllExport &operator<<(ostream&, const IPoint3&);
|
---|
62 |
|
---|
63 | // Inlines:
|
---|
64 |
|
---|
65 | inline float Length(const IPoint3& v) {
|
---|
66 | return (float)sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
|
---|
67 | }
|
---|
68 |
|
---|
69 | inline IPoint3& IPoint3::operator-=(const IPoint3& a) {
|
---|
70 | x -= a.x; y -= a.y; z -= a.z;
|
---|
71 | return *this;
|
---|
72 | }
|
---|
73 |
|
---|
74 | inline IPoint3& IPoint3::operator+=(const IPoint3& a) {
|
---|
75 | x += a.x; y += a.y; z += a.z;
|
---|
76 | return *this;
|
---|
77 | }
|
---|
78 |
|
---|
79 | inline IPoint3 IPoint3::operator-(const IPoint3& b) const {
|
---|
80 | return(IPoint3(x-b.x,y-b.y,z-b.z));
|
---|
81 | }
|
---|
82 |
|
---|
83 | inline IPoint3 IPoint3::operator+(const IPoint3& b) const {
|
---|
84 | return(IPoint3(x+b.x,y+b.y,z+b.z));
|
---|
85 | }
|
---|
86 |
|
---|
87 | inline int IPoint3::operator*(const IPoint3& b) const {
|
---|
88 | return(x*b.x+y*b.y+z*b.z);
|
---|
89 | }
|
---|
90 |
|
---|
91 | inline int IPoint3::DotProd(const IPoint3& b) const {
|
---|
92 | return(x*b.x+y*b.y+z*b.z);
|
---|
93 | }
|
---|
94 |
|
---|
95 | #endif
|
---|
96 |
|
---|