From 1a30c8427f7711064462ee436de614f90dbad002 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 31 Mar 2018 18:09:09 +0200 Subject: Fix and improve wall handling Use three neighbor cells for bounceback instead of three directions of a single cell. Generalize neighbor cell determination using normal vector of wall. --- src/vector.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/vector.h b/src/vector.h index 55c7663..e0dc239 100644 --- a/src/vector.h +++ b/src/vector.h @@ -4,41 +4,43 @@ inline double sq(double x) noexcept { return x * x; } +template struct Vector { - double data[2]; + T data[2]; - double comp(int x, int y) const { + T comp(int x, int y) const { return x*data[0] + y*data[1]; } - double norm() const { + T norm() const { return std::sqrt(sq(data[0]) + sq(data[1])); } - double& operator[](std::size_t i) { + T& operator[](std::size_t i) { return data[i]; } - double operator[](std::size_t i) const { + T operator[](std::size_t i) const { return data[i]; } - Vector operator*(double scalar) const { - return Vector{ + Vector operator*(T scalar) const { + return Vector{ data[0] * scalar, data[1] * scalar }; } - Vector& operator+=(const Vector& rhs) { + Vector& operator+=(const Vector& rhs) { data[0] += rhs[0]; data[1] += rhs[1]; return *this; } }; -Vector operator*(double scalar, const Vector& vec) { - return Vector{ +template +Vector operator*(T scalar, const Vector& vec) { + return Vector{ vec[0] * scalar, vec[1] * scalar }; -- cgit v1.2.3