22 #define VECTORTLP tlp::Vector<TYPE, SIZE, OTYPE, DTYPE> 26 VECTORTLP &VECTORTLP::operator*=(
const TYPE scalaire) {
27 for (
size_t i = 0; i < SIZE; ++i)
28 (*
this)[i] *= scalaire;
34 VECTORTLP &VECTORTLP::operator*=(
const VECTORTLP &vecto) {
35 for (
size_t i = 0; i < SIZE; ++i)
36 (*
this)[i] *= vecto[i];
42 VECTORTLP &VECTORTLP::operator/=(
const TYPE scalaire) {
43 assert(scalaire != static_cast<TYPE>(0));
45 for (
size_t i = 0; i < SIZE; ++i)
46 (*
this)[i] /= scalaire;
52 VECTORTLP &VECTORTLP::operator/=(
const VECTORTLP &vecto) {
53 for (
size_t i = 0; i < SIZE; ++i) {
54 assert(vecto[i] != static_cast<TYPE>(0));
55 (*this)[i] /= vecto[i];
62 VECTORTLP &VECTORTLP::operator+=(
const TYPE scalaire) {
63 for (
size_t i = 0; i < SIZE; ++i)
64 (*
this)[i] += scalaire;
70 VECTORTLP &VECTORTLP::operator+=(
const VECTORTLP &vecto) {
71 for (
size_t i = 0; i < SIZE; ++i)
72 (*
this)[i] += vecto[i];
78 VECTORTLP &VECTORTLP::operator-=(
const TYPE scalaire) {
79 for (
size_t i = 0; i < SIZE; ++i)
80 (*
this)[i] -= scalaire;
86 VECTORTLP &VECTORTLP::operator-=(
const VECTORTLP &vecto) {
87 for (
size_t i = 0; i < SIZE; ++i)
88 (*
this)[i] -= vecto[i];
94 VECTORTLP &VECTORTLP::operator^=(
const VECTORTLP &v) {
95 (*this) = (*this) ^ v;
100 VECTORTLP tlp::operator+(
const VECTORTLP &u,
const VECTORTLP &v) {
101 return VECTORTLP(u) += v;
105 VECTORTLP tlp::operator+(
const VECTORTLP &u,
const TYPE scalaire) {
106 return VECTORTLP(u) += scalaire;
110 VECTORTLP tlp::operator-(
const VECTORTLP &u,
const VECTORTLP &v) {
111 return VECTORTLP(u) -= v;
115 VECTORTLP tlp::operator-(
const VECTORTLP &u,
const TYPE scalaire) {
116 return VECTORTLP(u) -= scalaire;
120 VECTORTLP tlp::operator*(
const VECTORTLP &u,
const VECTORTLP &v) {
121 return VECTORTLP(u) *= v;
125 VECTORTLP tlp::operator*(
const VECTORTLP &u,
const TYPE scalaire) {
126 return VECTORTLP(u) *= scalaire;
130 VECTORTLP tlp::operator*(
const TYPE scalaire,
const VECTORTLP &u) {
131 return VECTORTLP(u) *= scalaire;
135 VECTORTLP tlp::operator/(
const VECTORTLP &u,
const VECTORTLP &v) {
136 return VECTORTLP(u) /= v;
140 VECTORTLP tlp::operator/(
const VECTORTLP &u,
const TYPE scalaire) {
141 return VECTORTLP(u) /= scalaire;
145 VECTORTLP tlp::operator^(
const VECTORTLP &u,
const VECTORTLP &v) {
149 return VECTORTLP(static_cast<TYPE>(static_cast<OTYPE>(u.y()) * static_cast<OTYPE>(v.z()) -
150 static_cast<OTYPE>(u.z()) * static_cast<OTYPE>(v.y())),
151 static_cast<TYPE
>(
static_cast<OTYPE
>(u.z()) * static_cast<OTYPE>(v.x()) -
152 static_cast<OTYPE>(u.x()) * static_cast<OTYPE>(v.z())),
153 static_cast<TYPE
>(
static_cast<OTYPE
>(u.x()) * static_cast<OTYPE>(v.y()) -
154 static_cast<OTYPE>(u.y()) * static_cast<OTYPE>(v.x())));
158 tlp::warning() <<
"cross product not implemented for dimension :" << SIZE << std::endl;
166 VECTORTLP tlp::operator-(
const VECTORTLP &u) {
167 return VECTORTLP(u) *=
static_cast<TYPE
>(-1);
171 bool VECTORTLP::operator>(
const VECTORTLP &vecto)
const {
172 return vecto < (*this);
176 bool VECTORTLP::operator<(
const VECTORTLP &v)
const {
177 if (std::numeric_limits<TYPE>::is_integer) {
178 return memcmp(this->data(), v.data(), SIZE *
sizeof(TYPE)) < 0;
181 for (
size_t i = 0; i < SIZE; ++i) {
182 OTYPE tmp =
static_cast<OTYPE
>((*this)[i]) - static_cast<OTYPE>(v[i]);
184 if (tmp > sqrt(std::numeric_limits<TYPE>::epsilon()) ||
185 tmp < -sqrt(std::numeric_limits<TYPE>::epsilon())) {
198 bool VECTORTLP::operator!=(
const VECTORTLP &vecto)
const {
199 return (!((*
this) == vecto));
203 bool VECTORTLP::operator==(
const VECTORTLP &v)
const {
204 if (std::numeric_limits<TYPE>::is_integer) {
205 return memcmp(this->data(), v.data(), SIZE *
sizeof(TYPE)) == 0;
208 for (
size_t i = 0; i < SIZE; ++i) {
209 OTYPE tmp =
static_cast<OTYPE
>((*this)[i]) - static_cast<OTYPE>(v[i]);
211 if (tmp > sqrt(std::numeric_limits<TYPE>::epsilon()) ||
212 tmp < -sqrt(std::numeric_limits<TYPE>::epsilon())) {
221 TYPE VECTORTLP::dotProduct(
const VECTORTLP &v)
const {
223 OTYPE tmpO =
static_cast<OTYPE
>((*this)[0]) * static_cast<OTYPE>(v[0]);
225 for (
size_t i = 1; i < SIZE; ++i)
226 tmpO += static_cast<OTYPE>((*
this)[i]) * static_cast<OTYPE>(v[i]);
228 return static_cast<TYPE
>(tmpO);
232 VECTORTLP &VECTORTLP::fill(
const TYPE scalaire) {
233 for (
size_t i = 0; i < SIZE; ++i)
234 (*
this)[i] = scalaire;
240 TYPE VECTORTLP::norm()
const {
246 return tlpsqrt<TYPE, OTYPE>(tlpsqr<TYPE, OTYPE>(x()) + tlpsqr<TYPE, OTYPE>(y()));
249 return tlpsqrt<TYPE, OTYPE>(tlpsqr<TYPE, OTYPE>(x()) + tlpsqr<TYPE, OTYPE>(y()) +
250 tlpsqr<TYPE, OTYPE>(z()));
253 OTYPE tmp = tlpsqr<TYPE, OTYPE>((*this)[0]);
255 for (
size_t i = 1; i < SIZE; ++i)
256 tmp += tlpsqr<TYPE, OTYPE>((*
this)[i]);
258 return (tlpsqrt<TYPE, OTYPE>(tmp));
263 DTYPE VECTORTLP::dist(
const VECTOR &c)
const {
266 return static_cast<TYPE
>(fabs(x() - c.x()));
269 return tlpsqrt<DTYPE, OTYPE>(tlpsqr<DTYPE, OTYPE>(x() - c.x()) +
270 tlpsqr<DTYPE, OTYPE>(y() - c.y()));
273 return tlpsqrt<DTYPE, OTYPE>(tlpsqr<DTYPE, OTYPE>(x() - c.x()) +
274 tlpsqr<DTYPE, OTYPE>(y() - c.y()) +
275 tlpsqr<DTYPE, OTYPE>(z() - c.z()));
278 OTYPE tmp = tlpsqr<DTYPE, OTYPE>((*this)[0] - c[0]);
280 for (
size_t i = 1; i < SIZE; ++i)
281 tmp += tlpsqr<DTYPE, OTYPE>((*
this)[i] - c[i]);
283 return (tlpsqrt<DTYPE, OTYPE>(tmp));