21 #define VECTORTLP tlp::Vector<TYPE,SIZE, OTYPE>
30 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
31 VECTORTLP & VECTORTLP::operator*=(
const TYPE scalaire) {
32 for (
unsigned int i=0; i<SIZE; ++i)
38 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
39 VECTORTLP & VECTORTLP::operator*=(
const VECTORTLP &vecto) {
40 for (
unsigned int i=0; i<SIZE; ++i)
46 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
47 VECTORTLP & VECTORTLP::operator/=(
const TYPE scalaire) {
48 assert(scalaire!=static_cast<TYPE>(0));
50 for (
unsigned int i=0; i<SIZE; ++i)
62 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
63 VECTORTLP & VECTORTLP::operator/=(
const VECTORTLP &vecto) {
64 for (
unsigned int i=0; i<SIZE; ++i) {
65 assert(vecto[i]!=static_cast<TYPE>(0));
72 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
73 VECTORTLP & VECTORTLP::operator+=(
const TYPE scalaire) {
74 for (
unsigned int i=0; i<SIZE; ++i)
86 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
87 VECTORTLP & VECTORTLP::operator+=(
const VECTORTLP &vecto) {
88 for (
unsigned int i=0; i<SIZE; ++i)
94 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
95 VECTORTLP & VECTORTLP::operator-=(
const TYPE scalaire) {
96 for (
unsigned int i=0; i<SIZE; ++i)
107 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
108 VECTORTLP & VECTORTLP::operator-=(
const VECTORTLP &vecto) {
109 for (
unsigned int i=0; i<SIZE; ++i)
110 (*
this)[i]-=vecto[i];
115 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
116 VECTORTLP & VECTORTLP::operator^=(
const VECTORTLP &v) {
117 (*this) = (*this) ^ v;
121 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
122 VECTORTLP tlp::operator+(
const VECTORTLP &u,
const VECTORTLP &v) {
123 return VECTORTLP(u)+=v;
126 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
127 VECTORTLP tlp::operator+(
const VECTORTLP &u,
const TYPE scalaire) {
128 return VECTORTLP(u)+=scalaire;
136 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
137 VECTORTLP tlp::operator-(
const VECTORTLP &u,
const VECTORTLP &v) {
138 return VECTORTLP(u) -= v;
141 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
142 VECTORTLP tlp::operator-(
const VECTORTLP &u,
const TYPE scalaire) {
143 return VECTORTLP(u) -= scalaire;
150 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
151 VECTORTLP tlp::operator*(
const VECTORTLP &u,
const VECTORTLP &v) {
152 return VECTORTLP(u)*=v;
155 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
156 VECTORTLP tlp::operator*(
const VECTORTLP &u,
const TYPE scalaire) {
157 return VECTORTLP(u)*=scalaire;
164 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
165 VECTORTLP tlp::operator*(
const TYPE scalaire,
const VECTORTLP &u ) {
166 return VECTORTLP(u)*=scalaire;
173 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
174 VECTORTLP tlp::operator/(
const VECTORTLP &u,
const VECTORTLP &v) {
175 return VECTORTLP(u)/=v;
178 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
179 VECTORTLP tlp::operator/(
const VECTORTLP &u,
const TYPE scalaire) {
180 return VECTORTLP(u)/=scalaire;
187 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
188 VECTORTLP tlp::operator^(
const VECTORTLP &u,
const VECTORTLP &v) {
194 static_cast<OTYPE>(u.y()) * static_cast<OTYPE>(v.z())
196 static_cast<OTYPE>(u.z()) * static_cast<OTYPE>(v.y())
200 static_cast<OTYPE
>(u.z()) * static_cast<OTYPE>(v.x())
202 static_cast<OTYPE>(u.x()) * static_cast<OTYPE>(v.z())
206 static_cast<OTYPE
>(u.x()) * static_cast<OTYPE>(v.y())
208 static_cast<OTYPE>(u.y()) * static_cast<OTYPE>(v.x())
214 tlp::warning() <<
"cross product not implemented for dimension :" << SIZE << std::endl;
221 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
222 VECTORTLP tlp::operator-(
const VECTORTLP &u) {
223 return VECTORTLP(u) *=
static_cast<TYPE
>(-1);
226 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
227 bool VECTORTLP::operator>(
const VECTORTLP &vecto)
const {
228 return vecto < (*this);
231 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
232 bool VECTORTLP::operator<(
const VECTORTLP &v)
const {
233 if (std::numeric_limits<TYPE>::is_integer) {
234 return memcmp(&((*this).array[0]), (
void*)&(v.array[0]), SIZE *
sizeof(TYPE)) < 0;
237 for (
unsigned int i=0; i<SIZE; ++i) {
238 OTYPE tmp =
static_cast<OTYPE
>((*this)[i]) - static_cast<OTYPE>(v[i]);
240 if (tmp > sqrt(std::numeric_limits<TYPE>::epsilon()) || tmp < -sqrt(std::numeric_limits<TYPE>::epsilon())) {
241 if (tmp > 0)
return false;
243 if (tmp < 0)
return true;
250 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
251 bool VECTORTLP::operator!=(
const VECTORTLP &vecto)
const {
252 return (! ( (*
this) == vecto ));
255 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
256 bool VECTORTLP::operator==(
const VECTORTLP &v)
const {
257 if (std::numeric_limits<TYPE>::is_integer) {
258 return memcmp((
void*)&((*this).array[0]), (
void*)&(v.array[0]), SIZE *
sizeof(TYPE)) == 0;
261 for (
unsigned int i=0; i<SIZE; ++i) {
262 OTYPE tmp =
static_cast<OTYPE
>((*this)[i]) - static_cast<OTYPE>(v[i]);
264 if (tmp > sqrt(std::numeric_limits<TYPE>::epsilon()) || tmp < -sqrt(std::numeric_limits<TYPE>::epsilon())) {
272 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
273 TYPE VECTORTLP::dotProduct(
const VECTORTLP &v)
const {
275 OTYPE tmpO =
static_cast<OTYPE
>(VECTORTLP::array[0]) * static_cast<OTYPE>(v[0]);
277 for (
unsigned int i=1; i<SIZE; ++i)
278 tmpO += static_cast<OTYPE>((*
this)[i]) * static_cast<OTYPE>(v[i]);
280 return static_cast<TYPE
>(tmpO);
283 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
284 VECTORTLP & VECTORTLP::fill(
const TYPE scalaire) {
285 for (
unsigned int i=0; i<SIZE; ++i)
291 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
292 TYPE VECTORTLP::norm()
const {
295 return VECTORTLP::array[0];
298 return tlpsqrt<TYPE, OTYPE>(tlpsqr<TYPE, OTYPE>(x())
300 tlpsqr<TYPE, OTYPE>(y())
304 return tlpsqrt<TYPE, OTYPE>(tlpsqr<TYPE, OTYPE>(x())
306 tlpsqr<TYPE, OTYPE>(y())
308 tlpsqr<TYPE, OTYPE>(z())
312 OTYPE tmp = tlpsqr<TYPE, OTYPE>((*this)[0]);
314 for (
unsigned int i=1; i<SIZE; ++i)
315 tmp += tlpsqr<TYPE, OTYPE>((*
this)[i]);
317 return(tlpsqrt<TYPE, OTYPE>(tmp));
321 template <
typename TYPE,
unsigned int SIZE,
typename OTYPE>
322 TYPE VECTORTLP::dist(
const VECTOR &c)
const {
325 return static_cast<TYPE
>(fabs(x()-c.x()));
328 return tlpsqrt<TYPE, OTYPE>(tlpsqr<TYPE, OTYPE>(x()-c.x())
330 tlpsqr<TYPE, OTYPE>(y()-c.y()));
333 return tlpsqrt<TYPE, OTYPE>(tlpsqr<TYPE, OTYPE>(x()-c.x())
335 tlpsqr<TYPE, OTYPE>(y()-c.y())
337 tlpsqr<TYPE, OTYPE>(z()-c.z())
341 OTYPE tmp = tlpsqr<TYPE, OTYPE>((*this)[0] - c[0]);
343 for (
unsigned int i=1; i<SIZE; ++i)
344 tmp += tlpsqr<TYPE, OTYPE>((*
this)[i]-c[i]);
346 return(tlpsqrt<TYPE, OTYPE>(tmp));