21 #define VECTORTLP tlp::Vector<TYPE, SIZE, OTYPE, DTYPE>
31 VECTORTLP & VECTORTLP::operator*=(
const TYPE scalaire) {
32 for (
unsigned int i=0; i<SIZE; ++i)
39 VECTORTLP & VECTORTLP::operator*=(
const VECTORTLP &vecto) {
40 for (
unsigned int i=0; i<SIZE; ++i)
47 VECTORTLP & VECTORTLP::operator/=(
const TYPE scalaire) {
48 assert(scalaire!=static_cast<TYPE>(0));
50 for (
unsigned int i=0; i<SIZE; ++i)
63 VECTORTLP & VECTORTLP::operator/=(
const VECTORTLP &vecto) {
64 for (
unsigned int i=0; i<SIZE; ++i) {
65 assert(vecto[i]!=static_cast<TYPE>(0));
73 VECTORTLP & VECTORTLP::operator+=(
const TYPE scalaire) {
74 for (
unsigned int i=0; i<SIZE; ++i)
87 VECTORTLP & VECTORTLP::operator+=(
const VECTORTLP &vecto) {
88 for (
unsigned int i=0; i<SIZE; ++i)
95 VECTORTLP & VECTORTLP::operator-=(
const TYPE scalaire) {
96 for (
unsigned int i=0; i<SIZE; ++i)
108 VECTORTLP & VECTORTLP::operator-=(
const VECTORTLP &vecto) {
109 for (
unsigned int i=0; i<SIZE; ++i)
110 (*
this)[i]-=vecto[i];
116 VECTORTLP & VECTORTLP::operator^=(
const VECTORTLP &v) {
117 (*this) = (*this) ^ v;
122 VECTORTLP tlp::operator+(
const VECTORTLP &u,
const VECTORTLP &v) {
123 return VECTORTLP(u)+=v;
127 VECTORTLP tlp::operator+(
const VECTORTLP &u,
const TYPE scalaire) {
128 return VECTORTLP(u)+=scalaire;
137 VECTORTLP tlp::operator-(
const VECTORTLP &u,
const VECTORTLP &v) {
138 return VECTORTLP(u) -= v;
142 VECTORTLP tlp::operator-(
const VECTORTLP &u,
const TYPE scalaire) {
143 return VECTORTLP(u) -= scalaire;
151 VECTORTLP tlp::operator*(
const VECTORTLP &u,
const VECTORTLP &v) {
152 return VECTORTLP(u)*=v;
156 VECTORTLP tlp::operator*(
const VECTORTLP &u,
const TYPE scalaire) {
157 return VECTORTLP(u)*=scalaire;
165 VECTORTLP tlp::operator*(
const TYPE scalaire,
const VECTORTLP &u ) {
166 return VECTORTLP(u)*=scalaire;
174 VECTORTLP tlp::operator/(
const VECTORTLP &u,
const VECTORTLP &v) {
175 return VECTORTLP(u)/=v;
179 VECTORTLP tlp::operator/(
const VECTORTLP &u,
const TYPE scalaire) {
180 return VECTORTLP(u)/=scalaire;
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;
222 VECTORTLP tlp::operator-(
const VECTORTLP &u) {
223 return VECTORTLP(u) *=
static_cast<TYPE
>(-1);
227 bool VECTORTLP::operator>(
const VECTORTLP &vecto)
const {
228 return vecto < (*this);
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;
251 bool VECTORTLP::operator!=(
const VECTORTLP &vecto)
const {
252 return (! ( (*
this) == vecto ));
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())) {
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);
284 VECTORTLP & VECTORTLP::fill(
const TYPE scalaire) {
285 for (
unsigned int i=0; i<SIZE; ++i)
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));
322 DTYPE VECTORTLP::dist(
const VECTOR &c)
const {
325 return static_cast<TYPE
>(fabs(x()-c.x()));
328 return tlpsqrt<DTYPE, OTYPE>(tlpsqr<DTYPE, OTYPE>(x()-c.x())
330 tlpsqr<DTYPE, OTYPE>(y()-c.y()));
333 return tlpsqrt<DTYPE, OTYPE>(tlpsqr<DTYPE, OTYPE>(x()-c.x())
335 tlpsqr<DTYPE, OTYPE>(y()-c.y())
337 tlpsqr<DTYPE, OTYPE>(z()-c.z())
341 OTYPE tmp = tlpsqr<DTYPE, OTYPE>((*this)[0] - c[0]);
343 for (
unsigned int i=1; i<SIZE; ++i)
344 tmp += tlpsqr<DTYPE, OTYPE>((*
this)[i]-c[i]);
346 return(tlpsqrt<DTYPE, OTYPE>(tmp));