From 7a7cfc3092bd53cf65b13252cc2c59d4152ab51e Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 9 Jun 2013 15:50:56 +0200 Subject: [PATCH] Added [Box|Rect]::Translate Former-commit-id: 72b4cd351a7233df89709366fbe7ce59e4ba94e7 --- include/Nazara/Math/Box.hpp | 1 + include/Nazara/Math/Box.inl | 10 ++++++++++ include/Nazara/Math/Rect.hpp | 2 ++ include/Nazara/Math/Rect.inl | 9 +++++++++ 4 files changed, 22 insertions(+) diff --git a/include/Nazara/Math/Box.hpp b/include/Nazara/Math/Box.hpp index feb16a81b..d301d5cec 100644 --- a/include/Nazara/Math/Box.hpp +++ b/include/Nazara/Math/Box.hpp @@ -67,6 +67,7 @@ class NzBox NzString ToString() const; NzBox& Transform(const NzMatrix4& matrix, bool applyTranslation = true); + NzBox& Translate(const NzVector3& translation); T& operator[](unsigned int i); T operator[](unsigned int i) const; diff --git a/include/Nazara/Math/Box.inl b/include/Nazara/Math/Box.inl index bd6f8cc7a..b9387a262 100644 --- a/include/Nazara/Math/Box.inl +++ b/include/Nazara/Math/Box.inl @@ -397,6 +397,16 @@ NzBox& NzBox::Transform(const NzMatrix4& matrix, bool applyTranslation) return Set(center - halfSize, center + halfSize); } +template +NzBox& NzBox::Translate(const NzVector3& translation) +{ + x += translation.x; + y += translation.y; + z += translation.z; + + return *this; +} + template T& NzBox::operator[](unsigned int i) { diff --git a/include/Nazara/Math/Rect.hpp b/include/Nazara/Math/Rect.hpp index b899e9bf0..17a60778b 100644 --- a/include/Nazara/Math/Rect.hpp +++ b/include/Nazara/Math/Rect.hpp @@ -56,6 +56,8 @@ class NzRect NzString ToString() const; + NzRect& Translate(const NzVector2& translation); + T& operator[](unsigned int i); T operator[](unsigned int i) const; diff --git a/include/Nazara/Math/Rect.inl b/include/Nazara/Math/Rect.inl index 981c5fba5..5973df9ef 100644 --- a/include/Nazara/Math/Rect.inl +++ b/include/Nazara/Math/Rect.inl @@ -281,6 +281,15 @@ NzString NzRect::ToString() const return ss << "Rect(" << x << ", " << y << ", " << width << ", " << height << ')'; } +template +NzRect& NzRect::Translate(const NzVector2& translation) +{ + x += translation.x; + y += translation.y; + + return *this; +} + template T& NzRect::operator[](unsigned int i) {