00001 /*************************************************************************************************** 00002 ***** Copyright (C) 2005 John Schneiderman <JohnMS@member.fsf.org> ***** 00003 ***** ***** 00004 ***** This program is free software; you can redistribute it and/or modify ***** 00005 ***** it under the terms of the GNU General Public License as published by ***** 00006 ***** the Free Software Foundation; either version 2 of the License, or ***** 00007 ***** (at your option) any later version. ***** 00008 ***** ***** 00009 ***** This program is distributed in the hope that it will be useful, ***** 00010 ***** but WITHOUT ANY WARRANTY; without even the implied warranty of ***** 00011 ***** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ***** 00012 ***** GNU General Public License for more details. ***** 00013 ***** ***** 00014 ***** You should have received a copy of the GNU General Public License ***** 00015 ***** along with this program; if not, write to the Free Software ***** 00016 ***** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ***** 00017 ***************************************************************************************************/ 00018 #include "coordinate.h" 00019 00020 Coordinate::Coordinate() 00021 { 00022 x=0.0; 00023 y=0.0; 00024 z=0.0; 00025 } 00026 00027 Coordinate::Coordinate(double value) 00028 { 00029 x=value; 00030 y=value; 00031 z=value; 00032 } 00033 00034 Coordinate::Coordinate(double setX, double setY, double setZ) 00035 { 00036 x = setX; 00037 y = setY; 00038 z = setZ; 00039 } 00040 00041 Coordinate::Coordinate(const Coordinate &point) 00042 { 00043 *this = point; 00044 } 00045 00046 Coordinate& Coordinate::operator=(const Coordinate &rhs) 00047 { 00048 if (this != &rhs) 00049 { 00050 x = rhs.x; 00051 y = rhs.y; 00052 z = rhs.z; 00053 } 00054 } 00055 00056 Coordinate Coordinate::operator+(const Coordinate &rhs) const 00057 { 00058 Coordinate result; 00059 00060 result.x = x + rhs.x; 00061 result.y = y + rhs.y; 00062 result.z = z + rhs.z; 00063 return result; 00064 } 00065 00066 Coordinate Coordinate::operator-(const Coordinate &rhs) const 00067 { 00068 Coordinate result; 00069 00070 result.x = x - rhs.x; 00071 result.y = y - rhs.y; 00072 result.z = z - rhs.z; 00073 return result; 00074 } 00075 00076 Coordinate Coordinate::operator*(const Coordinate &rhs) const 00077 { 00078 Coordinate result; 00079 00080 result.x = x * rhs.x; 00081 result.y = y * rhs.y; 00082 result.z = z * rhs.z; 00083 return result; 00084 } 00085 00086 Coordinate Coordinate::operator/(const Coordinate &rhs) const 00087 { 00088 Coordinate result; 00089 00090 result.x = x / rhs.x; 00091 result.y = y / rhs.y; 00092 result.z = z / rhs.z; 00093 return result; 00094 } 00095 00096 Coordinate& Coordinate::operator+=(const Coordinate &rhs) 00097 { 00098 x += rhs.x; 00099 y += rhs.y; 00100 z += rhs.z; 00101 return *this; 00102 } 00103 00104 Coordinate& Coordinate::operator-=(const Coordinate &rhs) 00105 { 00106 x -= rhs.x; 00107 y -= rhs.y; 00108 z -= rhs.z; 00109 return *this; 00110 } 00111 00112 Coordinate& Coordinate::operator*=(const Coordinate &rhs) 00113 { 00114 x *= rhs.x; 00115 y *= rhs.y; 00116 z *= rhs.z; 00117 return *this; 00118 } 00119 00120 Coordinate& Coordinate::operator/=(const Coordinate &rhs) 00121 { 00122 x /= rhs.x; 00123 y /= rhs.y; 00124 z /= rhs.z; 00125 return *this; 00126 } 00127 00128 bool Coordinate::operator==(const Coordinate &rhs) const 00129 { 00130 if ((x == rhs.x) && (y == rhs.y) && (z == rhs.z)) 00131 return true; 00132 else 00133 return false; 00134 } 00135 00136 bool Coordinate::operator!=(const Coordinate &rhs) const 00137 { 00138 if (*this == rhs) 00139 return false; 00140 else 00141 return true; 00142 } 00143 00144 istream& operator>>(istream &in, Coordinate &point) 00145 { 00146 in >> point.x >> point.y >> point.z; 00147 return in; 00148 } 00149 00150 ostream& operator<<(ostream &out, const Coordinate &point) 00151 { 00152 out << point.x << " " << point.y << " " << point.z; 00153 return out; 00154 }