VM2D 1.14
Vortex methods for 2D flows simulation
Loading...
Searching...
No Matches
numvector.h
Go to the documentation of this file.
1/*--------------------------------*- VM2D -*-----------------*---------------*\
2| ## ## ## ## #### ##### | | Version 1.14 |
3| ## ## ### ### ## ## ## ## | VM2D: Vortex Method | 2026/03/06 |
4| ## ## ## # ## ## ## ## | for 2D Flow Simulation *----------------*
5| #### ## ## ## ## ## | Open Source Code |
6| ## ## ## ###### ##### | https://www.github.com/vortexmethods/VM2D |
7| |
8| Copyright (C) 2017-2026 I. Marchevsky, K. Sokol, E. Ryatina, A. Kolganova |
9*-----------------------------------------------------------------------------*
10| File name: numvector.h |
11| Info: Source code of VM2D |
12| |
13| This file is part of VM2D. |
14| VM2D is free software: you can redistribute it and/or modify it |
15| under the terms of the GNU General Public License as published by |
16| the Free Software Foundation, either version 3 of the License, or |
17| (at your option) any later version. |
18| |
19| VM2D is distributed in the hope that it will be useful, but WITHOUT |
20| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
21| FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
22| for more details. |
23| |
24| You should have received a copy of the GNU General Public License |
25| along with VM2D. If not, see <http://www.gnu.org/licenses/>. |
26\*---------------------------------------------------------------------------*/
27
28
40#ifndef NUMVECTOR_H_
41#define NUMVECTOR_H_
42
43/*
44#define STRINGIZE_HELPER(x) #x
45#define STRINGIZE(x) STRINGIZE_HELPER(x)
46#define WARNING(desc) message(__FILE__ "(" STRINGIZE(__LINE__) ") : warning: " #desc)
47*/
48
49/*
50#if defined(__GNUC__) || defined(__clang__)
51#define DEPRECATED __attribute__((deprecated))
52#elif defined(_MSC_VER)
53#define DEPRECATED __declspec(deprecated)
54#else
55#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
56#define DEPRECATED
57#endif
58*/
59
60#if defined(__CUDACC__)
61 #define HD __host__ __device__
62#else
63 #define HD
64#endif
65
66#define DEPRECATED
67
68#include <array>
69#include <cmath>
70#include <cstring>
71#include <initializer_list>
72#include <ostream>
73#include <set>
74#include <vector>
75
76namespace VMlib
77{
78
79 class Point2D;
80 class Point;
81
96 template<typename T, size_t n>
97 //class numvector : public std::array<T, n>
99 {
100 protected:
101 T data[n];
102
103 public:
104 HD T& operator[](size_t i)
105 {
106 return this->data[i];
107 }
108
109 HD const T& operator[](size_t i) const
110 {
111 return this->data[i];
112 }
113
114 HD size_t size() const
115 {
116 return n;
117 }
118
125 template <typename P>
126 HD auto operator& (const numvector<P, n>& y) const -> typename std::remove_const<decltype(this->data[0] * y[0])>::type
127 {
128 typename std::remove_const<decltype(this->data[0] * y[0])>::type res = 0;
129 for (size_t j = 0; j < n; ++j)
130 res += this->data[j] * y[j];
131 return res;
132 }//operator&(...)
133
134
142 template <typename P>
143 HD auto operator^(const numvector<P, 3>& y) const -> numvector<typename std::remove_const<decltype(this->data[1] * y[2])>::type, 3>
144 {
145 numvector<typename std::remove_const<decltype(this->data[1] * y[2])>::type, 3> vec;
146 vec[0] = this->data[1] * y[2] - this->data[2] * y[1];
147 vec[1] = this->data[2] * y[0] - this->data[0] * y[2];
148 vec[2] = this->data[0] * y[1] - this->data[1] * y[0];
149 return vec;
150 }//operator^(...)
151
152
160 template <typename P>
161 HD auto operator^ (const numvector<P, 2>& y) const -> typename std::remove_const<decltype(this->data[0] * y[1])>::type
162 {
163 return (this->data[0] * y[1] - this->data[1] * y[0]);
164 }//operator^(...)
165
166
174 template <typename P>
176 {
177 for (size_t i = 0; i < n; ++i)
178 this->data[i] *= c;
179 return *this;
180 }//operator*=(...)
181
182
190 template <typename P>
192 {
193 for (size_t i = 0; i < n; ++i)
194 this->data[i] /= c;
195 return *this;
196 }//operator/=(...)
197
198
206 template <typename P>
208 {
209 for (size_t i = 0; i < n; ++i)
210 this->data[i] += y[i];
211 return *this;
212 }//operator+=(...)
213
214
222 template <typename P>
224 {
225 for (size_t i = 0; i < n; ++i)
226 this->data[i] -= y[i];
227 return *this;
228 }//operator-=(...)
229
230
237 template <typename P>
238 HD auto operator+(const numvector<P, n>& y) const -> numvector<typename std::remove_const<decltype(this->data[0] + y[0])>::type, n>
239 {
240 numvector<typename std::remove_const<decltype(this->data[0] + y[0])>::type, n> res;
241 for (size_t i = 0; i < n; ++i)
242 res[i] = this->data[i] + y[i];
243 return res;
244 }//operator+(...)
245
246
253 template <typename P>
254 HD auto operator-(const numvector<P, n>& y) const -> numvector<typename std::remove_const<decltype(this->data[0] - y[0])>::type, n>
255 {
256 numvector<typename std::remove_const<decltype(this->data[0] - y[0])>::type, n> res;
257 for (size_t i = 0; i < n; ++i)
258 res[i] = this->data[i] - y[i];
259 return res;
260 }//operator-(...)
261
262
269 template <typename P>
270 HD auto operator*(const P c) const -> numvector<typename std::remove_const<decltype(this->data[0] * c)>::type, n>
271 {
272 numvector<typename std::remove_const<decltype(this->data[0] * c)>::type, n> res;
273 for (size_t i = 0; i < n; ++i)
274 res[i] = c * this->data[i];
275 return res;
276 }//operator*(...)
277
278
285 {
286 numvector<T, n> res;
287 for (size_t i = 0; i < n; ++i)
288 res[i] = -this->data[i];
289 return res;
290 }//operator-()
291
292
299 {
300 return *this;
301 }//operator+()
302
303
310 template <typename P>
311 HD bool operator==(const numvector<P, n>& y) const
312 {
313 for (size_t i = 0; i < n; ++i)
314 if (this->data[i] != y[i])
315 return false;
316 return true;
317 }//operator==(...)
318
319
326 template <typename P>
327 HD bool operator!=(const numvector<P, n>& y) const
328 {
329 return !(*this == y);
330 }//operator!=(...)
331
332
333
334
340 HD auto norm1() const -> typename std::remove_const<typename std::remove_reference<decltype(this->data[0])>::type>::type
341 {
342 typename std::remove_const<typename std::remove_reference<decltype(this->data[0])>::type>::type res = 0;
343 for (size_t i = 0; i < n; ++i)
344 res += abs(this->data[i]);
345 return res;
346 }//norm1()
347
348
354 HD auto norminf() const -> typename std::remove_const<typename std::remove_reference<decltype(this->data[0])>::type>::type
355 {
356 typename std::remove_const<typename std::remove_reference<decltype(this->data[0])>::type>::type res = 0;
357 for (size_t i = 0; i < n; ++i)
358 {
359 if (abs(this->data[i]) > res)
360 res = abs(this->data[i]);
361 }
362 return res;
363 }//norminf()
364
365
373 template <typename P = double>
374 HD P length() const
375 {
376 P res = *this & *this;
377 return sqrt(res);
378 }//length()
379
380
386 HD auto length2() const -> typename std::remove_const<typename std::remove_reference<decltype(this->data[0])>::type>::type
387 {
388 return (*this & *this);
389 }//length2()
390
391
401 template <typename P = double>
402 HD auto unit(P newlen = 1) const -> numvector<typename std::remove_const<decltype(this->data[0] * newlen)>::type, n>
403 {
404 auto ilen = static_cast<decltype(this->data[0] * newlen)>(newlen / std::max(this->length(), 1e-16));
405 return (*this * ilen);
406 }//unit(...)
407
408
409
418 template <typename P = double>
419 HD void normalize(P newlen = 1.0)
420 {
421 auto ilen = static_cast<decltype(this->data[0] * newlen)>(newlen / std::max(this->length(), 1e-16));
422 *this *= ilen;
423 }//normalize(...)
424
425
426
432 template <typename P>
433 HD size_t member(const P& s) const
434 {
435 for (size_t i = 0; i < n; ++i)
436 if (this->data[i] == s)
437 return i;
438
439 return static_cast<size_t>(-1);
440 }//member(...)
441
442
443
448 template <typename P>
449 operator std::set<P>() const
450 {
451 std::set<P> newset;
452 for (size_t i = 0; i < n; ++i)
453 newset.insert(this->data[i]);
454 return newset;
455 }//toSet()
456
457
462 template <typename P>
463 operator std::vector<P>() const
464 {
465 std::vector<P> vec;
466 vec.reserve(n);
467 for (size_t i = 0; i < n; ++i)
468 vec.push_back(this->data[i]);
469 return vec;
470 }
471
472
482 {
483#ifndef __CUDACC__
484 if (k > n)
485 throw;
486#endif
487 if (k == n)
488 return *this;
489
490 numvector<T, n> res;
491
492 //for (size_t i = 0; i < n; ++i)
493 // res[i] = r[(i + k) % n];
494
495 for (size_t i = 0; i < n - k; ++i)
496 res[i] = this->data[i + k];
497 for (size_t i = n - k; i < n; ++i)
498 res[i] = this->data[i + k - n];
499 return res;
500 }//rotateLeft(...)
501
502
503
512 {
513 numvector<T, 2> res;
514 res[0] = -this->data[1];
515 res[1] = this->data[0];
516 return res;
517 }//kcross()
518
519
527 template <typename P = T>
529 {
530 for (size_t i = 0; i < n; ++i)
531 this->data[i] = val;
532 return *this;
533 }
534
535
543 template <typename P = T>
545 {
546 numvector<T, n> res;
547 res = ((*this & v) / (v & v))* v;
548
549 return res;
550 }
551
552
558 template<typename P>
559 HD auto dist2To(const numvector<P, n>& y) const -> typename std::remove_const<decltype(this->data[0] - y[0])>::type
560 {
561 return (*this - y).length2();
562 }//dist2To(...)
563
564
571 template<typename R = double, typename P>
573 {
574 R res = (*this - y) & (*this - y);
575 return sqrt(res);
576 }//distTo(...)
577
578
580 numvector() = default;
581
582
587 template <typename P>
588 explicit numvector(const P c)
589 {
590 for (size_t i = 0; i < n; ++i)
591 this->data[i] = c;
592 }//numvector(...)
593
594
595
602 {
603 //for (size_t i = 0; i < n; ++i)
604 // r[i] = vec[i];
605 memcpy(this->data, vec.data, n * sizeof(T));
606 }//numvector(...)
607
608
614 template <typename P>
616 {
617 for (size_t i = 0; i < n; ++i)
618 this->data[i] = vec[i];
619 }//numvector(...)
620
621
628 {
629 //for (size_t i = 0; i < n; ++i)
630 // r[i] = vec[i];
631 memcpy(this->data, vec.data, n * sizeof(T));
632 return *this;
633 }//numvector(...)
634
635
641 template <typename P>
643 {
644 for (size_t i = 0; i < n; ++i)
645 this->data[i] = vec[i];
646 }//numvector(...)
647
648
656 template <typename P>
657 numvector(const std::vector<P>& vec)
658 {
659 if (vec.size() != n)
660 throw;
661 for (size_t i = 0; i < n; ++i)
662 this->data[i] = vec[i];
663 }//numvector(...)
664
665
666#if !defined(__CUDACC__)
673 numvector(const std::initializer_list<T>& z)
674 {
675 if (z.size() != n)
676 throw;
677 for (size_t i = 0; i < n; ++i)
678 this->data[i] = *(z.begin() + i);
679 }//numvector(...)
680
681
682
689 template <typename P>
690 numvector(const std::initializer_list<P>& z)
691 {
692 if (z.size() != n)
693 throw;
694 for (size_t i = 0; i < n; ++i)
695 this->data[i] = *(z.begin() + i);
696 }//numvector(...)
697#endif
698
699
709 template <typename P, size_t p>
710 explicit numvector(const numvector<P, p>& vec, T add = 0)
711 {
712 size_t minPN = (p < n) ? p : n;
713 for (size_t i = 0; i < minPN; ++i)
714 this->data[i] = vec[i];
715 for (size_t i = minPN; i < n; ++i)
716 this->data[i] = add;
717 }//numvector(...)
718
719
720// ////////////////////////////////////////////////////////////////////////////
721// //// Далее deprecate-функции для ПОЛНОЙ СОВМЕСТИМОСТИ со старой версией ////
722// //// -------------------- ////
723// ////////////////////////////////////////////////////////////////////////////
724//
725// /// \brief Оператор присваивания всем компонентам вектора одного и того же числа
726// DEPRECATED numvector<T, n>& operator=(double c)
727// {
728// toZero(c);
729// return *this;
730// }//operator(...)
731
732
733// /// \brief Построение множества std::set на основе вектора
734// ///
735// /// \return множество типа std::set, состоящее из тех же элементов, что исходный вектор
736// DEPRECATED std::set<T> toSet() const
737// {
738// //(deprecate: use implicit type conversion)
739//
740// std::set<T> newset;
741// for (size_t i = 0; i < n; ++i)
742// newset.insert(this->data[i]);
743// return newset;
744// }//toSet()
745
746
747// /// \brief Построение вектора std::vector на основе вектора
748// ///
749// /// \return вектор типа std::vector, состоящий из тех же элементов, что исходный вектор
750// DEPRECATED std::vector<T> toVector() const
751// {
752// //(deprecate: use implicit type conversion)
753//
754// std::vector<T> vec;
755// vec.reserve(n);
756// for (size_t i = 0; i < n; ++i)
757// vec.push_back(this->data[i]);
758// return vec;
759// }
760
761 }; //class numvector
762
763// /// \todo Исследовать целесообразность наличия нешаблонного умножения
764// inline numvector<double, 3> operator*(double c, const numvector<double, 3>& x)
765// {
766// numvector<double, 3> res(x);
767// for (size_t i = 0; i < 3; ++i)
768// res[i] *= c;
769// return res;
770// }//operator*(...)
771
779 template<typename T, size_t n>
781 {
782 numvector<T, n> res(x);
783 for (size_t i = 0; i < n; ++i)
784 res[i] *= c;
785 return res;
786 }//operator*(...)
787
788
797 template<typename T, typename P, size_t n>
798 HD auto operator*(const P c, const numvector<T, n>& x) -> numvector<typename std::remove_const<decltype(x[0] * c)>::type, n>
799 {
800 numvector<typename std::remove_const<decltype(x[0] * c)>::type, n> res;
801 for (size_t i = 0; i < n; ++i)
802 res[i] = x[i] * c;
803 return res;
804 }//operator*(...)
805
806
807#if !defined(__CUDACC__)
819 template<typename T, typename P, typename R>
821 {
822 z = { x[1] * y[2] - x[2] * y[1], x[2] * y[0] - x[0] * y[2], x[0] * y[1] - x[1] * y[0] };
823 }//cross(...)
824#endif
825
826
835 template<typename T, typename P, size_t n>
836 HD auto dist2(const numvector<T, n>& x, const numvector<P, n>& y) -> typename std::remove_const<decltype(x[0] - y[0])>::type
837 {
838 numvector<typename std::remove_const<decltype(x[0] - y[0])>::type, n> p = x - y;
839 return p.length2();
840 }//dist2(...)
841
842
851 template<typename R = double, typename T, typename P, size_t n>
853 {
854 numvector<R, n> p = x - y;
855 return sqrt(p&p);
856 }//dist(...)
857
858
868 template<typename T, size_t n>
869 std::ostream& operator<< (std::ostream& str, const numvector<T, n>& x)
870 {
871 str << "{ ";
872 for (size_t j = 0; j < n - 1; ++j)
873 str << x[j] << ", ";
874 str << x[n - 1];
875 str << " }";
876 return str;
877 }//operator<<(...)
878
879
883
884
895 template<typename T, typename P, typename R, typename S, size_t n>
896 inline std::pair<numvector<T, n>, numvector<P, n>>& operator+=(std::pair<numvector<T, n>, numvector<P, n>>& a, const std::pair<numvector<R, n>, numvector<S, n>>& b)
897 {
898 a.first += b.first;
899 a.second += b.second;
900 return a;
901 }//operator+=(...)
902
903
914 template<typename T, typename P, typename R, typename S, size_t n>
915 inline auto operator+(const std::pair<numvector<T, n>, numvector<P, n>>& a, const std::pair<numvector<R, n>, numvector<S, n>>& b) -> \
916 std::pair<numvector<typename std::remove_const<decltype(a.first[0] + b.first[0])>::type, n>, numvector<typename std::remove_const<decltype(a.second[0] + b.second[0])>::type, n >>
917 {
918 std::pair<numvector<typename std::remove_const<decltype(a.first[0] + b.first[0])>::type, n>, numvector<typename std::remove_const<decltype(a.second[0] + b.second[0])>::type, n >> res;
919 res.first = a.first + b.first;
920 res.second = a.second + b.second;
921 return res;
922 }//operator+(...)
923
924
934 template<typename T, typename P, typename R, size_t n>
935 inline std::pair<numvector<T, n>, numvector<P, n>>& operator*=(std::pair<numvector<T, n>, numvector<P, n>>& a, R c)
936 {
937 a.first *= c;
938 a.second *= c;
939 return a;
940 }//operator*=(...)
941
942
952 template<typename T, typename P, typename R, size_t n>
953 inline auto operator*(R c, const std::pair<numvector<T, n>, numvector<P, n>>& a) -> \
954 std::pair<numvector<typename std::remove_const<decltype(c * a.first[0])>::type, n>, numvector<typename std::remove_const<decltype(c * a.second[0])>::type, n >>
955 {
956 std::pair<numvector<typename std::remove_const<decltype(c * a.first[0])>::type, n>, numvector<typename std::remove_const<decltype(c * a.second[0])>::type, n >> res;
957 res.first = c * a.first;
958 res.second = c * a.second;
959 return res;
960 }//operator*(...)
961
962
972 template<typename T, typename P, typename R, size_t n>
973 inline auto operator*(const std::pair<numvector<T, n>, numvector<P, n>>& a, R c) -> \
974 std::pair<numvector<typename std::remove_const<decltype(a.first[0] * c)>::type, n>, numvector<typename std::remove_const<decltype(a.second[0] * c)>::type, n >>
975 {
976 return c * a;
977 }//operator*(...)
978
979
990 template<typename T, typename P, size_t n>
991 std::ostream& operator<< (std::ostream& str, const std::pair<numvector<T, n>, numvector<P, n>>& x)
992 {
993 str << "{ " << x.first << ", " << x.second << " }";
994 return str;
995 }//operator<<
996
997
999 // Далее deprecate-функции для ПОЛНОЙ СОВМЕСТИМОСТИ со старой версией //
1000 // -------------------- //
1002
1003// /// \brief Умножение квадратной матрицы на вектор (без приведения типов)
1004// ///
1005// /// \tparam T тип данных компонент матрицы и вектора
1006// /// \tparam n размерность матрицы и вектора
1007// /// \param[in] A константная ссылка на матрицу
1008// /// \param[in] x константная ссылка на вектор
1009// /// \return вектор результат умножения матрицы на вектор
1010// template<typename T, size_t n>
1011// DEPRECATED inline numvector<T, n> dot(const numvector<numvector<T, n>, n>& A, const numvector<T, n>& x)
1012// {
1013// //deprecate: use nummatrix.operator& instead of dot(numvector<numvector<>>, numvector<>)
1014//
1015// numvector<T, n> res;
1016// for (size_t i = 0; i < n; ++i)
1017// res[i] = A[i] & x;
1018// return res;
1019// }//dot(...)
1020
1021
1022// /// \brief Умножение вектора на квадратную матрицу (без приведения типов)
1023// ///
1024// /// \tparam T тип данных компонент матрицы и вектора
1025// /// \tparam n размерность матрицы и вектора
1026// /// \param[in] A константная ссылка на матрицу
1027// /// \param[in] x константная ссылка на вектор
1028// /// \return вектор результат умножения матрицы на вектор
1029// template<typename T, size_t n>
1030// DEPRECATED inline numvector<T, n> dot(const numvector<T, n>& x, const numvector<numvector<T, n>, n>& A)
1031// {
1032// //deprecate: use operator&(numvector<>, nummatrix<>) instead of dot(numvector<>, numvector<numvector<>>)
1033//
1034// numvector<T, n> res;
1035// for (size_t i = 0; i < n; ++i)
1036// {
1037// res[i] = 0.0;
1038// for (size_t j = 0; j < n; ++j)
1039// res[i] += x[j] * A[j][i];
1040// }
1041// return res;
1042// }//dot(...)
1043
1044
1045// /// \brief Умножение квадратной матрицы на вектор
1046// ///
1047// /// \tparam T тип данных вектора и матрицы
1048// /// \tparam n длина вектора и размерность матрицы
1049// /// \param[in] A константная ссылка на матрицу
1050// /// \param[in] x константная ссылка на вектор
1051// /// \return вектор --- результат умножения матрицы на вектор
1052// template<typename T, size_t n>
1053// DEPRECATED inline numvector<T, n> matDotVec(const numvector<numvector<T, n>, n>& A, const numvector<T, n>& x)
1054// {
1055// //deprecate: use nummatrix.operator& instead of matDotVec(numvector<numvector<>>, numvector<>)
1056//
1057// numvector<T, n> res;
1058// for (size_t i = 0; i < n; ++i)
1059// res[i] = A[i] * x;
1060// return res;
1061// }//dot(...)
1062
1063
1064// /// \brief Умножение вектора на вектор той же размерности внешним образом
1065// ///
1066// /// \tparam T тип данных компонент векторов
1067// /// \tparam n размерность векторов
1068// /// \param[in] x константная ссылка на первый вектор
1069// /// \param[in] y константная ссылка на второй вектор
1070// /// \return матрицу ранга 1, являющюуся внешним (кронекеровым) произведением двух векторов
1071// template<typename T, size_t n>
1072// DEPRECATED inline numvector<numvector<T, n>, n> KronProd(const numvector<T, n>& x, const numvector<T, n>& y)
1073// {
1074// //deprecate: use nummatrix.operator|(numvector<>, numvector<>) instead of KronProd(numvector<>, numvector<>)
1075// numvector<numvector<T, n>, n> res;
1076// for (size_t i = 0; i < n; ++i)
1077// for (size_t j = 0; j < n; ++j)
1078// res[i][j] = x[i] * y[j];
1079// return res;
1080// }//KronProd(...)
1081
1082
1083// /// \brief Транспонирование квадратной матрицы
1084// ///
1085// /// \tparam T тип данных компонент матрицы
1086// /// \tparam n размерность матрицы
1087// /// \return транспонированную матрицу
1088// template<typename T, size_t n>
1089// DEPRECATED inline numvector<numvector<T, n>, n> Transpose(const numvector<numvector<T, n>, n>& A)
1090// {
1091// //deprecate: use member class nummatrix.transpose() instead of Transpose(numvector<numvector>)
1092//
1093// numvector<numvector<T, n>, n> res;
1094// for (size_t i = 0; i < n; ++i)
1095// for (size_t j = 0; j < n; ++j)
1096// res[i][j] = A[j][i];
1097// return res;
1098// }
1099
1100
1111 template<typename T, typename P, size_t n>
1113 {
1114 //deprecate: use numvector.operator^ instead of cross3(numvector<>,numvector<>)
1115
1116 return (x[0] * y[1] - x[1] * y[0]);
1117 }//cross3(...)
1118
1119
1120// /// \brief Скалярное умножение двух векторов
1121// ///
1122// /// \param[in] x константная ссылка на первый множитель
1123// /// \param[in] y константная ссылка на второй множитель
1124// /// \return результат скалярного умножения
1125// DEPRECATED inline double operator*(const Point2D& x, const Point2D& y)
1126// {
1127// //deprecate: use numvector.operator& instead of operator*
1128//
1129// const numvector<double, 2> xx = *(reinterpret_cast<const numvector<double, 2>*>(&x));
1130// const numvector<double, 2> yy = *(reinterpret_cast<const numvector<double, 2>*>(&y));
1131// return (xx & yy);
1132// }//operator*(...)
1133
1134
1135// /// \brief Скалярное умножение двух векторов
1136// ///
1137// /// \param[in] x константная ссылка на первый множитель
1138// /// \param[in] y константная ссылка на второй множитель
1139// /// \return результат скалярного умножения
1140// DEPRECATED inline double operator*(const numvector<double, 2>& x, const Point2D& y)
1141// {
1142// //deprecate: use numvector.operator& instead of operator*
1143//
1144// const numvector<double, 2> yy = *(reinterpret_cast<const numvector<double, 2>*>(&y));
1145// return (x & yy);
1146// }//operator*(...)
1147
1148
1149// /// \brief Скалярное умножение двух векторов
1150// ///
1151// /// \param[in] x константная ссылка на первый множитель
1152// /// \param[in] y константная ссылка на второй множитель
1153// /// \return результат скалярного умножения
1154// DEPRECATED inline double operator*(const Point2D& x, const numvector<double, 2>& y)
1155// {
1156// //deprecate: use numvector.operator& instead of operator*
1157//
1158// const numvector<double, 2> xx = *(reinterpret_cast<const numvector<double, 2>*>(&x));
1159// return (xx & y);
1160// }//operator*(...)
1161
1162
1163// /// \brief Скалярное умножение двух векторов
1164// ///
1165// /// \param[in] x константная ссылка на первый множитель
1166// /// \param[in] y константная ссылка на второй множитель
1167// /// \return результат скалярного умножения
1168// DEPRECATED inline double operator*(const Point& x, const Point& y)
1169// {
1170// //deprecate: use numvector.operator& instead of operator*
1171//
1172// const numvector<double, 2> xx = *(reinterpret_cast<const numvector<double, 2>*>(&x));
1173// const numvector<double, 2> yy = *(reinterpret_cast<const numvector<double, 2>*>(&y));
1174// return (xx & yy);
1175// }//operator*(...)
1176
1177
1178// /// \brief Скалярное умножение двух векторов
1179// ///
1180// /// \param[in] x константная ссылка на первый множитель
1181// /// \param[in] y константная ссылка на второй множитель
1182// /// \return результат скалярного умножения
1183// DEPRECATED inline double operator*(const numvector<double, 2>& x, const Point& y)
1184// {
1185// //deprecate: use numvector.operator& instead of operator*
1186//
1187// const numvector<double, 2> yy = *(reinterpret_cast<const numvector<double, 2>*>(&y));
1188// return (x & yy);
1189// }//operator*(...)
1190
1191
1192// /// \brief Скалярное умножение двух векторов
1193// ///
1194// /// \param[in] x константная ссылка на первый множитель
1195// /// \param[in] y константная ссылка на второй множитель
1196// /// \return результат скалярного умножения
1197// DEPRECATED inline double operator*(const Point& x, const numvector<double, 2>& y)
1198// {
1199// //deprecate: use numvector.operator& instead of operator*
1200//
1201// const numvector<double, 2> xx = *(reinterpret_cast<const numvector<double, 2>*>(&x));
1202// return (xx & y);
1203// }//operator*(...)
1204
1205
1206
1207
1208// /// \brief Скалярное умножение двух векторов
1209// ///
1210// /// \param[in] x константная ссылка на первый множитель
1211// /// \param[in] y константная ссылка на второй множитель
1212// /// \return результат скалярного умножения
1213// DEPRECATED inline double operator*(const numvector<double, 2>& x, const numvector<double, 2>& y)
1214// {
1215// //deprecate: use numvector.operator& instead of operator*
1216//
1217// return (x & y);
1218// }//operator*(...)
1219
1220
1221// /// \brief Скалярное умножение двух векторов
1222// ///
1223// /// \param[in] x константная ссылка на первый множитель
1224// /// \param[in] y константная ссылка на второй множитель
1225// /// \return результат скалярного умножения
1226// DEPRECATED inline double operator*(const numvector<double, 3>& x, const numvector<double, 3>& y)
1227// {
1228// //deprecate: use numvector.operator& instead of operator*
1229//
1230// return (x & y);
1231// }//operator*(...)
1232
1233}//namespace VMlib
1234
1235using VMlib::numvector;
1236using VMlib::dist2;
1237
1238#endif
Шаблонный класс, определяющий вектор фиксированной длины Фактически представляет собой массив,...
Definition numvector.h:99
const numvector< T, n > & operator+() const
Оператор "+" унарного плюса
Definition numvector.h:298
numvector< T, n > rotateLeft(size_t k) const
"Вращение" вектора на несколько позиций влево
Definition numvector.h:481
R distTo(const numvector< P, n > &y)
Вычисление расстояния между двумя точками
Definition numvector.h:572
auto operator*(const P c) const -> numvector< typename std::remove_const< decltype(this->data[0] *c)>::type, n >
Оператор "*" умножения вектора на число (вектор слева, число справа)
Definition numvector.h:270
const T & operator[](size_t i) const
Definition numvector.h:109
numvector< T, n > & operator-=(const numvector< P, n > &y)
Оператор "-=" вычитания другого вектора
Definition numvector.h:223
T & operator[](size_t i)
Definition numvector.h:104
numvector(const numvector< P, n > &vec)
Шаблонный конструктор копирования
Definition numvector.h:615
numvector(const P c)
Конструктор, инициализирующий весь вектор одной и той же константой
Definition numvector.h:588
numvector(const numvector< T, n > &vec)
Нешаблонный конструктор копирования
Definition numvector.h:601
numvector< T, n > proj(const numvector< P, n > &v)
Проекция вектора на вектор v.
Definition numvector.h:544
auto dist2To(const numvector< P, n > &y) const -> typename std::remove_const< decltype(this->data[0] - y[0])>::type
Вычисление квадрата расстояния до другой точки
Definition numvector.h:559
numvector(const std::vector< P > &vec)
Конструктор инициализации с помощью std::vector.
Definition numvector.h:657
numvector< T, 2 > kcross() const
Геометрический поворот двумерного вектора на 90 градусов
Definition numvector.h:511
numvector(const std::initializer_list< P > &z)
Шаблонный конструктор инициализации списком
Definition numvector.h:690
auto length2() const -> typename std::remove_const< typename std::remove_reference< decltype(this->data[0])>::type >::type
Вычисление квадрата нормы (длины) вектора
Definition numvector.h:386
auto operator&(const numvector< P, n > &y) const -> typename std::remove_const< decltype(this->data[0] *y[0])>::type
Оператор "&" скалярного умножения
Definition numvector.h:126
numvector< T, n > & operator+=(const numvector< P, n > &y)
Оператор "+=" прибавления другого вектора
Definition numvector.h:207
numvector< T, n > & toZero(P val=0)
Установка всех компонент вектора в константу (по умолчанию — нуль)
Definition numvector.h:528
numvector(const std::initializer_list< T > &z)
Нешаблонный конструктор инициализации списком
Definition numvector.h:673
numvector< T, n > operator-() const
Оператор "-" унарного минуса
Definition numvector.h:284
size_t member(const P &s) const
Проверка вхождения элемента в вектор
Definition numvector.h:433
size_t size() const
Definition numvector.h:114
auto operator+(const numvector< P, n > &y) const -> numvector< typename std::remove_const< decltype(this->data[0]+y[0])>::type, n >
Оператор "+" сложения двух векторов
Definition numvector.h:238
auto unit(P newlen=1) const -> numvector< typename std::remove_const< decltype(this->data[0] *newlen)>::type, n >
Вычисление орта вектора или вектора заданной длины, коллинеарного данному
Definition numvector.h:402
P length() const
Вычисление 2-нормы (длины) вектора
Definition numvector.h:374
numvector< T, n > & operator/=(P c)
Оператор "/=" деления вектора на действительное число
Definition numvector.h:191
auto norminf() const -> typename std::remove_const< typename std::remove_reference< decltype(this->data[0])>::type >::type
Вычисление inf-нормы вектора
Definition numvector.h:354
numvector(const numvector< P, p > &vec, T add=0)
Явный конструктор инициализации вектором другой размерности
Definition numvector.h:710
auto norm1() const -> typename std::remove_const< typename std::remove_reference< decltype(this->data[0])>::type >::type
Вычисление 1-нормы вектора
Definition numvector.h:340
numvector< T, n > & operator=(const numvector< T, n > &vec)
Нешаблонный оператор копирования
Definition numvector.h:627
numvector< T, n > operator=(const numvector< P, n > &vec)
Шаблонный оператор копирования
Definition numvector.h:642
numvector()=default
Пустой конструктор
auto operator^(const numvector< P, 3 > &y) const -> numvector< typename std::remove_const< decltype(this->data[1] *y[2])>::type, 3 >
Оператор "^" векторного произведения
Definition numvector.h:143
void normalize(P newlen=1.0)
Нормирование вектора на заданную длину
Definition numvector.h:419
auto operator-(const numvector< P, n > &y) const -> numvector< typename std::remove_const< decltype(this->data[0] - y[0])>::type, n >
Оператор "-" вычитания двух векторов
Definition numvector.h:254
bool operator==(const numvector< P, n > &y) const
Оператор "==" логического равенства
Definition numvector.h:311
bool operator!=(const numvector< P, n > &y) const
Перегрузка оператора "!=" логического неравенства
Definition numvector.h:327
numvector< T, n > & operator*=(P c)
Оператор "*=" домножения вектора на действительное число
Definition numvector.h:175
numvector< T, n > operator*(double c, const numvector< T, n > &x)
Оператор "*" умножения вектора на число (число слева, вектор справа)
Definition numvector.h:780
std::pair< numvector< T, n >, numvector< P, n > > & operator*=(std::pair< numvector< T, n >, numvector< P, n > > &a, R c)
Оператор домножения "*=" пары векторов на число (пара слева, число справа)
Definition numvector.h:935
void cross(const numvector< T, 3 > &x, const numvector< P, 3 > &y, numvector< R, 3 > &z)
Быстрое вычисление векторного произведения
Definition numvector.h:820
R dist(const numvector< T, n > &x, const numvector< P, n > &y)
Вычисление расстояния между двумя точками
Definition numvector.h:852
auto operator+(const std::pair< numvector< T, n >, numvector< P, n > > &a, const std::pair< numvector< R, n >, numvector< S, n > > &b) -> std::pair< numvector< typename std::remove_const< decltype(a.first[0]+b.first[0])>::type, n >, numvector< typename std::remove_const< decltype(a.second[0]+b.second[0])>::type, n > >
Оператор сложения "+" для пар векторов
Definition numvector.h:915
std::pair< numvector< T, n >, numvector< P, n > > & operator+=(std::pair< numvector< T, n >, numvector< P, n > > &a, const std::pair< numvector< R, n >, numvector< S, n > > &b)
Оператор прибавления "+=" для пар векторов
Definition numvector.h:896
double cross3(const numvector< T, n > &x, const numvector< P, n > &y)
Вычисление третьей компоненты векторного произведения
Definition numvector.h:1112
auto dist2(const numvector< T, n > &x, const numvector< P, n > &y) -> typename std::remove_const< decltype(x[0] - y[0])>::type
Вычисление квадрата расстояния между двумя точками
Definition numvector.h:836
std::ostream & operator<<(std::ostream &_stream, const std::vector< T > &_vec)
Переопределение оператора "<<" для вывода в поток вектора std::vector.
Definition defs.h:290
#define DEPRECATED
Definition numvector.h:66
#define HD
Definition numvector.h:63