00001
00002
00003 #if !defined(__geom_Segment_h__)
00004 #define __geom_Segment_h__
00005
00006
00007 #if defined(DEBUG_geom) && !defined(DEBUG_Segment)
00008 #define DEBUG_Segment
00009 #endif
00010
00011 #ifdef DEBUG_Segment
00012 #ifndef DEBUG_Point
00013 #define DEBUG_Point
00014 #endif
00015 #endif
00016
00017 #include "Point.h"
00018
00019 BEGIN_NAMESPACE_GEOM
00020
00022
00028 template<int N, typename T = double>
00029 class Segment {
00030
00031
00032
00033
00034 public:
00035
00037 typedef T Number;
00039 typedef ads::FixedArray<N,T> Point;
00040
00041
00042
00043
00044
00045 private:
00046
00047 Point _source, _target;
00048
00049 public:
00050
00051
00053
00054
00056 Segment() :
00057 _source(),
00058 _target()
00059 {}
00060
00062 Segment(const Point& source, const Point& target) :
00063 _source(source),
00064 _target(target)
00065 {}
00066
00068 Segment(const Segment& other) :
00069 _source(other._source),
00070 _target(other._target)
00071 {}
00072
00074 Segment&
00075 operator=(const Segment& other);
00076
00078 ~Segment()
00079 {}
00080
00082 void
00083 make(const Point& source, const Point& target) {
00084 _source = source;
00085 _target = target;
00086 }
00087
00088
00089
00091
00092
00094 const Point&
00095 getSource() const {
00096 return _source;
00097 }
00098
00100 const Point&
00101 getTarget() const {
00102 return _target;
00103 }
00104
00105
00106
00108
00109
00110
00111 #if 0
00112
00113 void
00114 setSource(const Point& source) {
00115 _source = source;
00116 }
00117
00119 void
00120 setTarget(const Point& target) {
00121 _target = target;
00122 }
00123 #endif
00124
00125
00126
00128
00129
00131 Segment&
00132 operator+=(const Point& p);
00133
00135 Segment&
00136 operator-=(const Point& p);
00137
00138
00139 };
00140
00141
00142
00143
00144
00145
00146
00148
00149 template<int N, typename T>
00150 inline
00151 bool
00152 operator==(const Segment<N,T>& x, const Segment<N,T>& y) {
00153 return (x.getSource() == y.getSource() && x.getTarget() == y.getTarget());
00154 }
00155
00156
00158
00159 template<int N, typename T>
00160 inline
00161 bool
00162 operator!=(const Segment<N,T>& x, const Segment<N,T>& y) {
00163 return !(x == y);
00164 }
00165
00166
00167
00168
00169
00170
00171
00173
00174 template<int N, typename T>
00175 inline
00176 const Segment<N,T>&
00177 operator+(const Segment<N,T>& x) {
00178 return x;
00179 }
00180
00181
00183
00184 template<int N, typename T>
00185 inline
00186 Segment<N,T>
00187 operator-(const Segment<N,T>& x) {
00188 return Segment<N,T>(x.getTarget(), x.getSource());
00189 }
00190
00191
00192
00193
00194
00195
00196
00198
00199 template<int N, typename T>
00200 inline
00201 Segment<N,T>
00202 operator+(const Segment<N,T>& s, const typename Segment<N,T>::Point& p) {
00203 return Segment<N,T>(s.getSource() + p, s.getTarget() + p);
00204 }
00205
00206
00208
00209 template<int N, typename T>
00210 inline
00211 Segment<N,T>
00212 operator-(const Segment<N,T>& s, const typename Segment<N,T>::Point& p) {
00213 return Segment<N,T>(s.getSource() - p, s.getTarget() - p);
00214 }
00215
00216
00217
00218
00219
00220
00221
00223
00224 template<int N, typename T>
00225 inline
00226 std::istream&
00227 operator>>(std::istream& in, Segment<N,T>& x) {
00228 typename Segment<N,T>::Point source, target;
00229 in >> source >> target;
00230 x.make(source, target);
00231 return in;
00232 }
00233
00234
00236
00237 template<int N, typename T>
00238 inline
00239 std::ostream&
00240 operator<<(std::ostream& out, const Segment<N,T>& x)
00241 {
00242 return out << x.getSource() << " " << x.getTarget();
00243 }
00244
00245
00246 END_NAMESPACE_GEOM
00247
00248 #define __geom_Segment_ipp__
00249 #include "Segment.ipp"
00250 #undef __geom_Segment_ipp__
00251
00252 #endif