PeriDyno 1.0.0
Loading...
Searching...
No Matches
Vector2D.h
Go to the documentation of this file.
1#pragma once
2#include <glm/vec2.hpp>
3#include <iostream>
4
5#include "VectorBase.h"
6
7namespace dyno {
8
9 template <typename T, int Dim> class SquareMatrix;
10
11 template <typename T>
12 class Vector<T, 2>
13 {
14 public:
15 typedef T VarType;
16
17 DYN_FUNC Vector();
18 DYN_FUNC explicit Vector(T);
19 DYN_FUNC Vector(T x, T y);
20 DYN_FUNC Vector(const Vector<T, 2>&);
21 DYN_FUNC ~Vector();
22
23 DYN_FUNC static int dims() { return 2; }
24
25 DYN_FUNC T& operator[] (unsigned int);
26 DYN_FUNC const T& operator[] (unsigned int) const;
27
28 DYN_FUNC const Vector<T, 2> operator+ (const Vector<T, 2> &) const;
29 DYN_FUNC Vector<T, 2>& operator+= (const Vector<T, 2> &);
30 DYN_FUNC const Vector<T, 2> operator- (const Vector<T, 2> &) const;
31 DYN_FUNC Vector<T, 2>& operator-= (const Vector<T, 2> &);
32 DYN_FUNC const Vector<T, 2> operator* (const Vector<T, 2> &) const;
33 DYN_FUNC Vector<T, 2>& operator*= (const Vector<T, 2> &);
34 DYN_FUNC const Vector<T, 2> operator/ (const Vector<T, 2> &) const;
35 DYN_FUNC Vector<T, 2>& operator/= (const Vector<T, 2> &);
36
37 DYN_FUNC Vector<T, 2>& operator= (const Vector<T, 2> &);
38
39 DYN_FUNC bool operator== (const Vector<T, 2> &) const;
40 DYN_FUNC bool operator!= (const Vector<T, 2> &) const;
41
42 DYN_FUNC const Vector<T, 2> operator* (T) const;
43 DYN_FUNC const Vector<T, 2> operator- (T) const;
44 DYN_FUNC const Vector<T, 2> operator+ (T) const;
45 DYN_FUNC const Vector<T, 2> operator/ (T) const;
46
47 DYN_FUNC Vector<T, 2>& operator+= (T);
48 DYN_FUNC Vector<T, 2>& operator-= (T);
49 DYN_FUNC Vector<T, 2>& operator*= (T);
50 DYN_FUNC Vector<T, 2>& operator/= (T);
51
52 DYN_FUNC const Vector<T, 2> operator - (void) const;
53
54 DYN_FUNC T norm() const;
55 DYN_FUNC T normSquared() const;
56 DYN_FUNC Vector<T, 2>& normalize();
57 DYN_FUNC T cross(const Vector<T, 2> &)const;
58 DYN_FUNC T dot(const Vector<T, 2>&) const;
59 DYN_FUNC Vector<T, 2> minimum(const Vector<T, 2> &) const;
60 DYN_FUNC Vector<T, 2> maximum(const Vector<T, 2> &) const;
61
62 DYN_FUNC T* getDataPtr() { return &data_.x; }
63
64 friend std::ostream& operator<<(std::ostream &out, const Vector<T, 2>& vec)
65 {
66 out << "(" << vec[0] << ", " << vec[1] << ")";
67 return out;
68 }
69
70 public:
71 union
72 {
73 glm::tvec2<T> data_; //default: zero vector
74 struct { T x, y; };
75 };
76 };
77
78 template class Vector<float, 2>;
79 template class Vector<double, 2>;
80
85} //end of namespace dyno
86
87#include "Vector2D.inl"
DYN_FUNC ~Vector()
Definition VectorBase.h:27
DYN_FUNC Vector()
Definition VectorBase.h:26
#define T(t)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
DYN_FUNC Vector< T, 3 > cross(Vector< T, 3 > const &U, Vector< T, 3 > const &V)
Definition SimpleMath.h:211
DYN_FUNC T dot(Vector< T, 2 > const &U, Vector< T, 2 > const &V)
Definition SimpleMath.h:199
Vector< float, 2 > Vec2f
Definition Vector2D.h:81
Vector< double, 2 > Vec2d
Definition Vector2D.h:82
Vector< uint32_t, 2 > Vec2u
Definition Vector2D.h:83
Vector< int, 2 > Vec2i
Definition Vector2D.h:84
DYN_FUNC const Complex< T > operator/(S scale, const Complex< T > &complex)
Definition Complex.inl:253
DYN_FUNC T minimum(const T &v0, const T &v1)
Definition SimpleMath.h:120
DYN_FUNC const Complex< T > operator*(S scale, const Complex< T > &complex)
Definition Complex.inl:247
DYN_FUNC bool operator==(const priority_queue< T, Container, Compare > &a, const priority_queue< T, Container, Compare > &b)
DYN_FUNC bool operator!=(const priority_queue< T, Container, Compare > &a, const priority_queue< T, Container, Compare > &b)
DYN_FUNC T maximum(const T &v0, const T &v1)
Definition SimpleMath.h:160
DYN_FUNC const Complex< T > operator-(S scale, const Complex< T > &complex)
Definition Complex.inl:241
DYN_FUNC const Complex< T > operator+(S scale, const Complex< T > &complex)
Definition Complex.inl:235
TEMPLATE_TYPENAME_T VEC2_T normalize(const VEC2_T &v)
Definition vgMath.h:421