Wire up task 4

This commit is contained in:
hodasemi 2019-06-22 16:51:52 +02:00
parent c170f3d716
commit f89a16075a
3 changed files with 318 additions and 376 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
exercise1/build/
exercise2/build/
exercise3/build/
exercise4/build/
.vscode/ipch

21
.vscode/tasks.json vendored
View file

@ -77,6 +77,27 @@
"options": {
"cwd": "/usr/bin"
}
},
{
"label": "Run Exercise 4",
"type": "shell",
"command": "cd exercise4/build/cmake/ && ./exercise4",
"dependsOn": "Build Exercise 4",
"problemMatcher": []
},
{
"label": "Build Exercise 4",
"type": "shell",
"command": "cd exercise4/build/cmake && cmake . && make -j16",
"problemMatcher": [],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": true
}
},
]
}

View file

@ -16,13 +16,11 @@ At the end of this file the data types "point2d", "point3d" and
#pragma once
#include <iostream>
#include <algorithm>
#include <cassert>
#include <math.h>
#include <numeric>
#ifdef _MSC_VER
#pragma warning(push)
@ -55,7 +53,6 @@ public:
std::copy(first, last, begin());
}
tiny_vec(size_t n, const T *marray);
~tiny_vec();
@ -114,64 +111,48 @@ public:
tiny_vec operator-() const;
tiny_vec &operator+=(int s);
tiny_vec &operator+=(float s);
tiny_vec &operator+=(double s);
tiny_vec operator+(int s) const;
tiny_vec operator+(float s) const;
tiny_vec operator+(double s) const;
tiny_vec &operator-=(int s);
tiny_vec &operator-=(float s);
tiny_vec &operator-=(double s);
tiny_vec operator-(int s) const;
tiny_vec operator-(float s) const;
tiny_vec operator-(double s) const;
tiny_vec &operator*=(int s);
tiny_vec &operator*=(float s);
tiny_vec &operator*=(double s);
tiny_vec operator*(int s) const;
tiny_vec operator*(float s) const;
tiny_vec operator*(double s) const;
tiny_vec &operator/=(int s);
tiny_vec &operator/=(float s);
tiny_vec &operator/=(double s);
tiny_vec operator/(int s) const;
tiny_vec operator/(float s) const;
@ -206,7 +187,6 @@ public:
T y() const { return _data[1]; };
T z() const { return _data[2]; };
void sort();
void random_shuffle();
@ -232,15 +212,11 @@ public:
T length() const;
void normalize();
};
template <typename T, int N>
tiny_vec<T, N>::tiny_vec() {}
template <typename T, int N>
tiny_vec<T, N>::tiny_vec(size_t n, const T *marray)
{
@ -285,7 +261,6 @@ void tiny_vec<T,N>::set(const T& x, const T& y)
{
_data[0] = x;
_data[1] = y;
}
template <typename T, int N>
void tiny_vec<T, N>::set(const T &x, const T &y, const T &z)
@ -293,7 +268,6 @@ void tiny_vec<T,N>::set(const T& x, const T& y,const T& z)
_data[0] = x;
_data[1] = y;
_data[2] = z;
}
template <typename T, int N>
void tiny_vec<T, N>::set(const T &x, const T &y, const T &z, const T &w)
@ -316,7 +290,6 @@ tiny_vec<T,N>::operator T*()
return _data;
}
template <typename T, int N>
tiny_vec<T, N>::operator const T *() const
{
@ -341,26 +314,22 @@ tiny_vec<T,N>& tiny_vec<T,N>::operator=(int s)
return *this;
}
template <typename T, int N>
tiny_vec<T, N> &tiny_vec<T, N>::operator=(const tiny_vec &v)
{
if(&v== this) return *this;
if (&v == this)
return *this;
std::copy(v.begin(), v.end(), begin());
return *this;
}
template <typename T, int N>
void tiny_vec<T, N>::fill(const T &s)
{
std::fill(begin(), end(), s);
}
template <typename T, int N>
void tiny_vec<T, N>::zeros()
{
@ -377,8 +346,6 @@ void tiny_vec<T,N>::ones()
std::fill(begin(), end(), one);
}
template <typename T, int N>
typename tiny_vec<T, N>::iterator tiny_vec<T, N>::begin()
{
@ -433,7 +400,6 @@ bool tiny_vec<T,N>::operator==(const tiny_vec<T,N>& v) const
return std::equal(begin(), end(), v.begin());
}
template <typename T, int N>
bool tiny_vec<T, N>::operator!=(const tiny_vec<T, N> &v) const
{
@ -446,8 +412,6 @@ tiny_vec<T,N> tiny_vec<T,N>::operator-() const
return (T)-1 * *this;
}
template <typename T, int N>
tiny_vec<T, N> &tiny_vec<T, N>::operator+=(int s)
{
@ -475,8 +439,6 @@ tiny_vec<T,N>& tiny_vec<T,N>::operator+=(double s)
return *this;
}
template <typename T, int N>
tiny_vec<T, N> tiny_vec<T, N>::operator+(int s) const
{
@ -485,7 +447,6 @@ tiny_vec<T,N> tiny_vec<T,N>::operator+(int s) const
return r;
}
template <typename T, int N>
tiny_vec<T, N> tiny_vec<T, N>::operator+(float s) const
{
@ -502,8 +463,6 @@ tiny_vec<T,N> tiny_vec<T,N>::operator+(double s) const
return r;
}
template <typename T, int N>
tiny_vec<T, N> &tiny_vec<T, N>::operator-=(int s)
{
@ -533,8 +492,6 @@ tiny_vec<T,N>& tiny_vec<T,N>::operator-=(double s)
return *this;
}
template <typename T, int N>
tiny_vec<T, N> tiny_vec<T, N>::operator-(int s) const
{
@ -543,8 +500,6 @@ tiny_vec<T,N> tiny_vec<T,N>::operator-(int s) const
return r;
}
template <typename T, int N>
tiny_vec<T, N> tiny_vec<T, N>::operator-(float s) const
{
@ -553,8 +508,6 @@ tiny_vec<T,N> tiny_vec<T,N>::operator-(float s) const
return r;
}
template <typename T, int N>
tiny_vec<T, N> tiny_vec<T, N>::operator-(double s) const
{
@ -563,8 +516,6 @@ tiny_vec<T,N> tiny_vec<T,N>::operator-(double s) const
return r;
}
template <typename T, int N>
tiny_vec<T, N> &tiny_vec<T, N>::operator*=(int s)
{
@ -592,8 +543,6 @@ tiny_vec<T,N>& tiny_vec<T,N>::operator*=(double s)
return *this;
}
template <typename T, int N>
tiny_vec<T, N> tiny_vec<T, N>::operator*(int s) const
{
@ -618,8 +567,6 @@ tiny_vec<T,N> tiny_vec<T,N>::operator*(double s) const
return r;
}
template <typename T, int N>
tiny_vec<T, N> &tiny_vec<T, N>::operator/=(int s)
{
@ -647,8 +594,6 @@ tiny_vec<T,N>& tiny_vec<T,N>::operator/=(double s)
return *this;
}
template <typename T, int N>
tiny_vec<T, N> tiny_vec<T, N>::operator/(int s) const
{
@ -683,7 +628,6 @@ tiny_vec<T,N>& tiny_vec<T,N>::operator+=(const tiny_vec& v)
return *this;
}
template <typename T, int N>
tiny_vec<T, N> tiny_vec<T, N>::operator+(const tiny_vec &v) const
{
@ -692,7 +636,6 @@ tiny_vec<T,N> tiny_vec<T,N>::operator+(const tiny_vec& v) const
return r;
}
template <typename T, int N>
tiny_vec<T, N> &tiny_vec<T, N>::operator-=(const tiny_vec &v)
{
@ -702,7 +645,6 @@ tiny_vec<T,N>& tiny_vec<T,N>::operator-=(const tiny_vec& v)
return *this;
}
template <typename T, int N>
tiny_vec<T, N> tiny_vec<T, N>::operator-(const tiny_vec &v) const
{
@ -711,7 +653,6 @@ tiny_vec<T,N> tiny_vec<T,N>::operator-(const tiny_vec& v) const
return r;
}
template <typename T, int N>
tiny_vec<T, N> &tiny_vec<T, N>::operator*=(const tiny_vec &v)
{
@ -720,7 +661,6 @@ tiny_vec<T,N>& tiny_vec<T,N>::operator*=(const tiny_vec& v)
return *this;
}
template <typename T, int N>
tiny_vec<T, N> tiny_vec<T, N>::operator*(const tiny_vec &v) const
{
@ -729,7 +669,6 @@ tiny_vec<T,N> tiny_vec<T,N>::operator*(const tiny_vec& v) const
return r;
}
template <typename T, int N>
tiny_vec<T, N> &tiny_vec<T, N>::operator/=(const tiny_vec &v)
{
@ -739,7 +678,6 @@ tiny_vec<T,N>& tiny_vec<T,N>::operator/=(const tiny_vec& v)
return *this;
}
template <typename T, int N>
tiny_vec<T, N> tiny_vec<T, N>::operator/(const tiny_vec<T, N> &v) const
{
@ -748,7 +686,6 @@ tiny_vec<T,N> tiny_vec<T,N>::operator/(const tiny_vec<T,N>& v) const
return r;
}
template <typename T, int N>
T &tiny_vec<T, N>::operator()(size_t i)
{
@ -811,7 +748,6 @@ size_t tiny_vec<T,N>::max_index() const
return std::distance(begin(), std::max_element(begin(), end()));
}
template <typename T, int N>
T tiny_vec<T, N>::sqr_length() const
{
@ -830,14 +766,12 @@ T tiny_vec<T,N>::length() const
return sqrt(l);
}
template <typename T, int N>
tiny_vec<T, N> operator+(const T &s, const tiny_vec<T, N> &v)
{
return v + s;
}
template <typename T, int N>
tiny_vec<T, N> operator+(int s, const tiny_vec<T, N> &v)
{
@ -850,21 +784,18 @@ tiny_vec<T,N> operator-(const T& s, const tiny_vec<T,N>& v)
return -v + s;
}
template <typename T, int N>
tiny_vec<T, N> operator-(int s, const tiny_vec<T, N> &v)
{
return -v + (T)s;
}
template <typename T, int N>
tiny_vec<T, N> operator*(const T &s, const tiny_vec<T, N> &v)
{
return v * s;
}
template <typename T, int N>
tiny_vec<T, N> operator*(int s, const tiny_vec<T, N> &v)
{
@ -889,8 +820,6 @@ T dot(const tiny_vec<T,N>& v1, const tiny_vec<T,N>& v2)
return std::inner_product(v1.begin(), v1.end(), v2.begin(), (T)0);
}
template <typename T>
tiny_vec<T, 3> cross(const tiny_vec<T, 3> &b, const tiny_vec<T, 3> &c)
{
@ -901,7 +830,6 @@ tiny_vec<T,3> cross(const tiny_vec<T,3>& b, const tiny_vec<T,3>& c)
return a;
}
template <typename T, int N>
tiny_vec<T, N + 1> homog(const tiny_vec<T, N> &v)
{
@ -923,9 +851,6 @@ tiny_vec<T,N-1> unhomog(const tiny_vec<T,N>& v)
return vh;
}
template <typename T, int N>
std::ostream &operator<<(std::ostream &out, const tiny_vec<T, N> &v)
{
@ -936,7 +861,6 @@ std::ostream& operator<<(std::ostream& out, const tiny_vec<T,N>& v)
return out;
}
template <typename T, int N>
std::istream &operator>>(std::istream &in, tiny_vec<T, N> &v)
{
@ -954,8 +878,6 @@ void tiny_vec<T,N>::normalize()
operator/=(l);
}
typedef tiny_vec<double, 2> point2d;
typedef tiny_vec<double, 3> point3d;
typedef tiny_vec<double, 4> point4d;
@ -963,8 +885,6 @@ typedef tiny_vec<double, 4> point4d;
#pragma warning(pop)
#endif
typedef tiny_vec<double, 2> vec2d;
typedef tiny_vec<double, 3> vec3d;
typedef tiny_vec<double, 4> vec4d;