40#ifndef GEOGRAM_BASIC_VECG
41#define GEOGRAM_BASIC_VECG
48#include <initializer_list>
69 template <index_t DIM,
class T>
86 for(
index_t i = 0; i < DIM; i++) {
105 for(
index_t i = 0; i < DIM; i++) {
111 template <
class T2, index_t DIM2>
116 for(
index_t i = 0; i < DIM; i++) {
131 for(
index_t i = 0; i < DIM; i++) {
140 vecng(
const std::initializer_list<T>& Vi) {
198 for(
index_t i = 0; i < DIM; i++) {
199 result += data_[i] * data_[i];
218 for(
index_t i = 0; i < DIM; i++) {
219 result +=
geo_sqr(v.data_[i] - data_[i]);
243 for(
index_t i = 0; i < DIM; i++) {
244 data_[i] += v.data_[i];
257 for(
index_t i = 0; i < DIM; i++) {
258 data_[i] -= v.data_[i];
274 for(
index_t i = 0; i < DIM; i++) {
291 for(
index_t i = 0; i < DIM; i++) {
306 for(
index_t i = 0; i < DIM; i++) {
307 result.data_[i] += v.data_[i];
321 for(
index_t i = 0; i < DIM; i++) {
322 result.data_[i] -= v.data_[i];
339 for(
index_t i = 0; i < DIM; i++) {
340 result.data_[i] *= T(s);
357 for(
index_t i = 0; i < DIM; i++) {
358 result.data_[i] /= T(s);
370 for(
index_t i = 0; i < DIM; i++) {
371 result.data_[i] = -data_[i];
387 template <index_t DIM,
class T>
392 for(
index_t i = 0; i < DIM; i++) {
393 result += v1[i] * v2[i];
409 template <
class T2, index_t DIM,
class T>
414 for(
index_t i = 0; i < DIM; i++) {
415 result[i] = T(s) * v[i];
429 template <index_t DIM,
class T>
441 template <index_t DIM,
class T>
454 template <index_t DIM,
class T>
469 template <index_t DIM,
class T>
485 template <index_t DIM,
class T>
506 template <index_t DIM,
class T>
510 return (T(1) - s) * v1 + s * v2;
541 vecng(
const T& x_in,
const T& y_in) :
573 vecng(
const std::initializer_list<T>& Vi) {
587 return x * x + y * y;
592 return sqrt(x * x + y * y);
599 return dx * dx + dy * dy;
711 return v1.x * v2.x + v1.y * v2.y;
725 return v1.x * v2.y - v1.y * v2.x;
732 template <
class T2,
class T>
768 vecng(
const T& x_in,
const T& y_in,
const T& z_in) :
778 vecng(T&& x_in, T&& y_in, T&& z_in) :
804 vecng(
const std::initializer_list<T>& Vi) {
818 return x * x + y * y + z * z;
823 return sqrt(x * x + y * y + z * z);
831 return dx * dx + dy * dy + dz * dz;
950 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
965 det2x2(v1.y, v2.y, v1.z, v2.z),
966 det2x2(v1.z, v2.z, v1.x, v2.x),
967 det2x2(v1.x, v2.x, v1.y, v2.y)
975 template <
class T2,
class T>
979 return vecng<3, T>(T(s) * v.x, T(s) * v.y, T(s) * v.z);
1012 vecng(
const T& x_in,
const T& y_in,
const T& z_in,
const T& w_in) :
1023 vecng(T&& x_in, T&& y_in, T&& z_in, T&& w_in) :
1052 vecng(
const std::initializer_list<T>& Vi) {
1066 return x * x + y * y + z * z + w * w;
1071 return sqrt(x * x + y * y + z * z + w * w);
1080 return dx * dx + dy * dy + dz * dz + dw * dw;
1133 return vector_type(x + v.x, y + v.y, z + v.z, w + v.w);
1138 return vector_type(x - v.x, y - v.y, z - v.z, w - v.w);
1144 return vector_type(x * T(s), y * T(s), z * T(s), w * T(s));
1150 return vector_type(x / T(s), y / T(s), z / T(s), w / T(s));
1198 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
1205 template <
class T2,
class T>
1209 return vecng<4, T>(T(s) * v.x, T(s) * v.y, T(s) * v.z, T(s) * v.w);
1221 template <index_t DIM,
class T>
1222 inline std::ostream& operator<< (
1225 const char* sep =
"";
1226 for(
index_t i = 0; i < DIM; i++) {
1243 template <index_t DIM,
class T>
1244 inline std::istream& operator>> (
1248 while(isspace(in.peek())) {
1251 if(in.peek() ==
'[' || in.peek() ==
'{') {
1254 while(isspace(in.peek())) {
1257 for(
index_t i = 0; i < DIM; i++) {
1259 while(isspace(in.peek())) {
1262 if(in.peek() ==
',') {
1265 while(isspace(in.peek())) {
1269 if(in.peek() ==
']' || in.peek() ==
'}') {
Assertion checking mechanism.
#define geo_debug_assert(x)
Verifies that a condition is met.
T distance2(const vector_type &v) const
vecng(const T &x_in, const T &y_in)
Constructs a vector from coordinates.
T distance(const vector_type &v) const
T * data()
Gets modifiable vector data.
index_t dimension() const
Gets the vector dimension.
const T * data() const
Gets non-modifiable vector data.
void optimize()
Optimizes coordinate representation.
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
T length() const
Gets the length of the vector.
vecng(const std::initializer_list< T > &Vi)
T value_type
The type of the vector coordinates.
vecng(T &&x_in, T &&y_in)
Constructs a vector from coordinates.
vecng()
Default vector constructor.
vecng(const T2 *v)
Constructs a vector from an array.
vecng< dim, T > vector_type
This vector type.
T length2() const
Gets the squared length of the vector.
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
void optimize()
Optimizes coordinate representation.
vecng()
Default vector constructor.
vecng(T &&x_in, T &&y_in, T &&z_in)
Constructs a vector from coordinates.
T * data()
Gets modifiable vector data.
T value_type
The type of the vector coordinates.
T distance2(const vector_type &v) const
const T * data() const
Gets non-modifiable vector data.
T length2() const
Gets the squared length of the vector.
vecng(const T2 *v)
Constructs a vector from an array.
vecng(const std::initializer_list< T > &Vi)
vecng< dim, T > vector_type
This vector type.
T distance(const vector_type &v) const
index_t dimension() const
Gets the vector dimension.
T length() const
Gets the length of the vector.
vecng(const T &x_in, const T &y_in, const T &z_in)
Constructs a vector from coordinates.
T distance2(const vector_type &v) const
vecng(const std::initializer_list< T > &Vi)
vecng(const T &x_in, const T &y_in, const T &z_in, const T &w_in)
Constructs a vector from coordinates.
T length2() const
Gets the squared length of the vector.
vecng< dim, T > vector_type
This vector type.
T value_type
The type of the vector coordinates.
vecng()
Default vector constructor.
const T * data() const
Gets non-modifiable vector data.
index_t dimension() const
Gets the vector dimension.
vecng(const T2 *v)
Constructs a vector from an array.
T * data()
Gets modifiable vector data.
T length() const
Gets the length of the vector.
vecng(T &&x_in, T &&y_in, T &&z_in, T &&w_in)
Constructs a vector from coordinates.
T distance(const vector_type &v) const
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
vector_type operator*(T2 s) const
Multiplies a vector by a scalar.
T & operator[](index_t i)
Gets a modifiable vector coordinate.
vector_type & operator-=(const vector_type &v)
Subtracts a vector in place.
vecng< DIM, T > normalize(const vecng< DIM, T > &v)
Normalizes a vector.
vecng< 3, T > cross(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the cross product of 2 vectors.
T value_type
The type of the vector coordinates.
T length2(const vecng< DIM, T > &v)
Gets the square norm of a vector.
T det(const vecng< 2, T > &v1, const vecng< 2, T > &v2)
Computes the determinant of 2 vectors.
T distance2(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Gets the square distance between 2 vectors.
T length2() const
Gets the squared length of the vector.
T * data()
Gets modifiable vector data.
vector_type & operator/=(T2 s)
Divides by a scalar in place.
T dot(const vecng< 4, T > &v1, const vecng< 4, T > &v2)
Computes the dot product of 2 vectors.
T length() const
Gets the length of the vector.
const T * data() const
Gets non-modifiable vector data.
T length(const vecng< DIM, T > &v)
Gets the norm of a vector.
index_t dimension() const
Gets the vector dimension.
vector_type operator-() const
Negates a vector.
vector_type & operator*=(T2 s)
Multiplies by a scalar in place.
vector_type operator+(const vector_type &v) const
Adds 2 vectors.
vector_type operator/(T2 s) const
Divides a vector by a scalar.
vector_type & operator+=(const vector_type &v)
Adds a vector in place.
vecng()
Default vector constructor.
vecng< DIM, T > vector_type
This vector type.
T dot(const vecng< 2, T > &v1, const vecng< 2, T > &v2)
Computes the dot product of 2 vectors.
vecng< DIM, T > mix(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2, T s)
Computes a weighted barycenter.
T distance(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Gets the distance between 2 vectors.
T distance(const vector_type &v) const
Gets the distance to a vector.
vecng(const vecng< DIM, T2 > &v)
Constructs a vector by copy.
T distance2(const vector_type &v) const
Gets the squared distance to a vector.
vecng(const std::initializer_list< T > &Vi)
Constructs a vector from an initializer list.
vecng(const T2 *v)
Constructs a vector from an array.
static constexpr index_t dim
The dimension of the vector.
T dot(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Computes the dot product of 2 vectors.
Determinants for small sizes.
Common include file, providing basic definitions. Should be included before anything else by all head...
Types and functions for memory manipulation.
void optimize_number_representation(T &x)
place holder for optimizing internal number representation
Global Vorpaline namespace.
T dot(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the dot product of 2 vectors. vecng
T geo_sqr(T x)
Gets the square value of a value.
geo_index_t index_t
The type for storing and manipulating indices.
T det2x2(const T &a11, const T &a12, const T &a21, const T &a22)
Computes a two-by-two determinant.
Types and functions for numbers manipulation.