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;
561 vecng(
const std::initializer_list<T>& Vi) {
572 return x * x + y * y;
577 return sqrt(x * x + y * y);
584 return dx * dx + dy * dy;
696 return v1.
x * v2.
x + v1.
y * v2.
y;
710 return v1.
x * v2.
y - v1.
y * v2.
x;
717 template <
class T2,
class T>
776 vecng(
const std::initializer_list<T>& Vi) {
787 return x * x + y * y + z * z;
792 return sqrt(x * x + y * y + z * z);
800 return dx * dx + dy * dy + dz * dz;
919 return v1.
x * v2.
x + v1.
y * v2.
y + v1.
z * v2.
z;
944 template <
class T2,
class T>
981 vecng(T x_in, T y_in, T z_in, T w_in) :
1007 vecng(
const std::initializer_list<T>& Vi) {
1018 return x * x + y * y + z * z + w * w;
1023 return sqrt(x * x + y * y + z * z + w * w);
1032 return dx * dx + dy * dy + dz * dz + dw * dw;
1085 return vector_type(x + v.x, y + v.y, z + v.z, w + v.w);
1090 return vector_type(x - v.x, y - v.y, z - v.z, w - v.w);
1096 return vector_type(x * T(s), y * T(s), z * T(s), w * T(s));
1102 return vector_type(x / T(s), y / T(s), z / T(s), w / T(s));
1150 return v1.
x * v2.
x + v1.
y * v2.
y + v1.
z * v2.
z + v1.
w * v2.
w;
1157 template <
class T2,
class T>
1173 template <index_t DIM,
class T>
1177 const char* sep =
"";
1178 for(
index_t i = 0; i < DIM; i++) {
1195 template <index_t DIM,
class T>
1200 while(isspace(in.peek())) {
1203 if(in.peek() ==
'[') {
1206 while(isspace(in.peek())) {
1209 for(
index_t i = 0; i < DIM; i++) {
1211 while(isspace(in.peek())) {
1214 if(in.peek() ==
',') {
1217 while(isspace(in.peek())) {
1221 if(in.peek() ==
']') {
Assertion checking mechanism.
#define geo_debug_assert(x)
Verifies that a condition is met.
Specialization of class vecng for DIM == 2.
T distance2(const vector_type &v) const
Gets the squared distance to a vector.
vecng(T x_in, T y_in)
Constructs a vector from coordinates.
T distance(const vector_type &v) const
Gets the distance to a vector.
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()
Default vector constructor.
vecng(const T2 *v)
Constructs a vector from an array.
T * data()
Gets modifiable vector data.
vecng< dim, T > vector_type
This vector type.
T length2() const
Gets the squared length of the vector.
Specialization of class vecng for DIM == 3.
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
void optimize()
Optimizes coordinate representation.
vecng()
Default vector constructor.
T value_type
The type of the vector coordinates.
T distance2(const vector_type &v) const
Gets the squared distance to a vector.
T length2() const
Gets the squared length of the vector.
const T * data() const
Gets non-modifiable vector data.
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.
vecng(T x_in, T y_in, T z_in)
Constructs a vector from coordinates.
T distance(const vector_type &v) const
Gets the distance to a vector.
index_t dimension() const
Gets the vector dimension.
T length() const
Gets the length of the vector.
T * data()
Gets modifiable vector data.
Specialization of class vecn3 for DIM == 4.
const T * data() const
Gets non-modifiable vector data.
T distance2(const vector_type &v) const
Gets the squared distance to a vector.
vecng(const std::initializer_list< T > &Vi)
T length2() const
Gets the squared length of the vector.
vecng(T x_in, T y_in, T z_in, T w_in)
Constructs a vector from coordinates.
vecng< dim, T > vector_type
This vector type.
T value_type
The type of the vector coordinates.
vecng()
Default vector constructor.
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.
T distance(const vector_type &v) const
Gets the distance to a vector.
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.
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 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.
T dot(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the dot product of 2 vectors.
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+(const vector_type &v) const
Adds 2 vectors.
vector_type & operator+=(const vector_type &v)
Adds a vector in place.
T * data()
Gets modifiable vector data.
const T * data() const
Gets non-modifiable vector data.
vector_type operator/(T2 s) const
Divides a vector by a scalar.
vector_type & operator*=(T2 s)
Multiplies by a scalar 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.
static const index_t dim
The dimension of the vector.
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.
T dot(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Computes the dot product of 2 vectors.
vector_type & operator-=(const vector_type &v)
Subtracts a vector in place.
vector_type & operator/=(T2 s)
Divides by a scalar in place.
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 geo_sqr(T x)
Gets the square value of a value.
geo_index_t index_t
The type for storing and manipulating indices.
std::ostream & operator<<(std::ostream &out, const Quaternion &q)
Writes a Quaternion to a stream.
vecng< DIM, FT > operator*(const Matrix< DIM, FT > &M, const vecng< DIM, FT > &x)
Computes a matrix vector product.
T det2x2(const T &a11, const T &a12, const T &a21, const T &a22)
Computes a two-by-two determinant.
std::istream & operator>>(std::istream &in, Quaternion &q)
Reads a Quaternion from a stream.
Types and functions for numbers manipulation.