From 962c3303908e841e4ba17932749640d3e380d3c6 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 3 Jan 2013 19:17:04 +0100 Subject: [PATCH] (Rect|Cube) Fixed ExtendTo method (Close #6) Former-commit-id: 066d87f52361d1c30ec6521b637308ee4541bba1 --- include/Nazara/Math/Cube.inl | 22 ++++++++++++++++------ include/Nazara/Math/Rect.inl | 16 ++++++++++++---- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/include/Nazara/Math/Cube.inl b/include/Nazara/Math/Cube.inl index 7be978993..b03c2e7df 100644 --- a/include/Nazara/Math/Cube.inl +++ b/include/Nazara/Math/Cube.inl @@ -63,12 +63,17 @@ bool NzCube::Contains(const NzCube& cube) const template NzCube& NzCube::ExtendTo(const NzVector3& point) { + width = std::max(x + width, point.x); + height = std::max(y + height, point.y); + depth = std::max(z + depth, point.z); + x = std::min(x, point.x); y = std::min(y, point.y); z = std::min(z, point.z); - width = std::max(x + width, point.x) - x; - height = std::max(y + height, point.y) - y; - depth = std::max(z + depth, point.z) - z; + + width -= x; + height -= y; + depth -= z; return *this; } @@ -76,12 +81,17 @@ NzCube& NzCube::ExtendTo(const NzVector3& point) template NzCube& NzCube::ExtendTo(const NzCube& cube) { + width = std::max(x + width, cube.x + cube.width); + height = std::max(y + height, cube.y + cube.height); + depth = std::max(z + depth, cube.z + cube.depth); + x = std::min(x, cube.x); y = std::min(y, cube.y); z = std::min(z, cube.z); - width = std::max(x + width, cube.x + cube.width) - x; - height = std::max(y + height, cube.y + cube.height) - y; - depth = std::max(z + depth, cube.z + cube.depth) - z; + + width -= x; + height -= y; + depth -= z; return *this; } diff --git a/include/Nazara/Math/Rect.inl b/include/Nazara/Math/Rect.inl index c637a15ac..86d680ad0 100644 --- a/include/Nazara/Math/Rect.inl +++ b/include/Nazara/Math/Rect.inl @@ -56,10 +56,14 @@ bool NzRect::Contains(const NzRect& rect) const template NzRect& NzRect::ExtendTo(const NzVector2& point) { + width = std::max(x + width, point.x); + height = std::max(y + height, point.y); + x = std::min(x, point.x); y = std::min(y, point.y); - width = std::max(x + width, point.x) - x; - height = std::max(y + height, point.y) - y; + + width -= x; + height -= y; return *this; } @@ -67,10 +71,14 @@ NzRect& NzRect::ExtendTo(const NzVector2& point) template NzRect& NzRect::ExtendTo(const NzRect& rect) { + width = std::max(x + width, rect.x + rect.width); + height = std::max(y + height, rect.y + rect.height); + x = std::min(x, rect.x); y = std::min(y, rect.y); - width = std::max(x + width, rect.x + rect.width) - x; - height = std::max(x + height, rect.y + rect.height) - y; + + width -= x; + height -= y; return *this; }