vector2D.cpp
Go to the documentation of this file.00001
00015 #include <dlrNumeric/vector2D.h>
00016
00017 namespace dlr {
00018
00019 namespace numeric {
00020
00021 Vector2D operator+(const Vector2D& vector0, const Vector2D& vector1)
00022 {
00023 return Vector2D(vector0.x() + vector1.x(),
00024 vector0.y() + vector1.y());
00025 }
00026
00027 Vector2D operator-(const Vector2D& vector0, const Vector2D& vector1)
00028 {
00029 return Vector2D(vector0.x() - vector1.x(),
00030 vector0.y() - vector1.y());
00031 }
00032
00033 Vector2D operator*(const Vector2D& vector0, const Vector2D& vector1)
00034 {
00035 return Vector2D(vector0.x() * vector1.x(),
00036 vector0.y() * vector1.y());
00037 }
00038
00039 Vector2D operator/(const Vector2D& vector0, const Vector2D& vector1)
00040 {
00041 return Vector2D(vector0.x() / vector1.x(),
00042 vector0.y() / vector1.y());
00043 }
00044
00045 Vector2D operator+(const Vector2D& vector0, double scalar)
00046 {
00047 return Vector2D(vector0.x() + scalar,
00048 vector0.y() + scalar);
00049 }
00050
00051 Vector2D operator-(const Vector2D& vector0, double scalar)
00052 {
00053 return Vector2D(vector0.x() - scalar,
00054 vector0.y() - scalar);
00055 }
00056
00057 Vector2D operator*(const Vector2D& vector0, double scalar)
00058 {
00059 return Vector2D(vector0.x() * scalar,
00060 vector0.y() * scalar);
00061 }
00062 Vector2D operator/(const Vector2D& vector0, double scalar)
00063 {
00064 return Vector2D(vector0.x() / scalar,
00065 vector0.y() / scalar);
00066 }
00067
00068 bool
00069 operator==(const Vector2D& vector0, const Vector2D& vector1)
00070 {
00071 return((vector0.x() == vector1.x()) &&
00072 (vector0.y() == vector1.y()));
00073 }
00074
00075 bool
00076 operator!=(const Vector2D& vector0, const Vector2D& vector1)
00077 {
00078 return(!operator==(vector0, vector1));
00079 }
00080
00081 std::ostream&
00082 operator<<(std::ostream& stream, const Vector2D& vector0)
00083 {
00084 stream << "Vector2D(" << vector0.x() << ", " << vector0.y() << ")";
00085 return stream;
00086 }
00087
00088 std::istream&
00089 operator>>(std::istream& stream, Vector2D& vector0)
00090 {
00091 const char intro[] = "Vector2D(";
00092 const char intermission[] = ",";
00093 const char outro[] = ")";
00094 double x, y;
00095 char inChar;
00096 size_t index;
00097
00098 for(index = 0; index < strlen(intro); ++index) {
00099 inChar = 0;
00100 stream >> inChar;
00101 if(inChar != intro[index]) {
00102 stream.clear(std::ios_base::failbit);
00103 return stream;
00104 }
00105 }
00106 stream >> x;
00107 for(index = 0; index < strlen(intermission); ++index) {
00108 inChar = 0;
00109 stream >> inChar;
00110 if(inChar != intermission[index]) {
00111 stream.clear(std::ios_base::failbit);
00112 return stream;
00113 }
00114 }
00115 stream >> y;
00116 for(index = 0; index < strlen(outro); ++index) {
00117 inChar = 0;
00118 stream >> inChar;
00119 if(inChar != outro[index]) {
00120 stream.clear(std::ios_base::failbit);
00121 return stream;
00122 }
00123 }
00124 if(stream) {
00125 vector0.setValue(x, y);
00126 }
00127 return stream;
00128 }
00129
00130 }
00131
00132 }