From c126769533aa8fc51bbd109301ea2488c0ccd319 Mon Sep 17 00:00:00 2001 From: vng Date: Tue, 25 Jan 2011 10:23:17 +0200 Subject: [PATCH] Use our "std" headers instead of native. --- geometry/distance.hpp | 5 +++-- geometry/rect2d.hpp | 29 ++++++++++++++++++----------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/geometry/distance.hpp b/geometry/distance.hpp index 28b9aa7147..0214dc4d2a 100644 --- a/geometry/distance.hpp +++ b/geometry/distance.hpp @@ -2,7 +2,8 @@ #include "../base/base.hpp" -#include +#include "../std/limits.hpp" +#include "../std/static_assert.hpp" // Similarly to namespace m2 - 2d math, this is a namespace for nd math. namespace mn @@ -12,7 +13,7 @@ template class DistanceToLineSquare { private: // we do not support unsigned points!!! - STATIC_ASSERT(std::numeric_limits::is_signed); + STATIC_ASSERT(numeric_limits::is_signed); public: DistanceToLineSquare(PointT p0, PointT p1) diff --git a/geometry/rect2d.hpp b/geometry/rect2d.hpp index a4cd5a6b79..563d7b849c 100644 --- a/geometry/rect2d.hpp +++ b/geometry/rect2d.hpp @@ -6,6 +6,7 @@ #include "../std/algorithm.hpp" #include "../std/limits.hpp" +#include "../std/type_traits.hpp" #include "../base/start_mem_debug.hpp" @@ -16,14 +17,13 @@ namespace m2 template struct min_max_value; template struct min_max_value { - T get_min() { return numeric_limits::max(); } - // TODO: There is an overflow here: -(-128) != 127. - T get_max() { return -get_min(); } + T get_min() { return -get_max(); } + T get_max() { return numeric_limits::max(); } }; template struct min_max_value { - T get_min() { return numeric_limits::max(); } - T get_max() { return numeric_limits::min(); } + T get_min() { return numeric_limits::min(); } + T get_max() { return numeric_limits::max(); } }; } @@ -31,6 +31,8 @@ namespace m2 template class Rect { + enum { IsSigned = numeric_limits::is_signed }; + T m_minX, m_minY, m_maxX, m_maxY; public: @@ -57,16 +59,21 @@ namespace m2 static Rect GetInfiniteRect() { - T const tMax = numeric_limits::max(); - // This works for both ints and floats. - T const tMin = min(-tMax, numeric_limits::min()); - return Rect(tMin, tMin, tMax, tMax); + Rect r; + r.MakeInfinite(); + return r; } void MakeEmpty() { - m_minX = m_minY = impl::min_max_value::is_signed>().get_min(); - m_maxX = m_maxY = impl::min_max_value::is_signed>().get_max(); + m_minX = m_minY = impl::min_max_value().get_max(); + m_maxX = m_maxY = impl::min_max_value().get_min(); + } + + void MakeInfinite() + { + m_minX = m_minY = impl::min_max_value().get_min(); + m_maxX = m_maxY = impl::min_max_value().get_max(); } void Add(m2::Point const & p)