diff --git a/geometry/region2d.hpp b/geometry/region2d.hpp index 1c69202880..8a24cde225 100644 --- a/geometry/region2d.hpp +++ b/geometry/region2d.hpp @@ -11,11 +11,6 @@ namespace m2 { namespace detail { - // Get a big type for storing middle calculations (x*y) to avoid overflow. - template struct BigType; - template <> struct BigType<0> { typedef int64_t type; }; - template <> struct BigType<1> { typedef double type; }; - struct DefEqualFloat { template @@ -44,20 +39,31 @@ namespace m2 } }; - template struct EqualSelector; - template <> struct EqualSelector<1> { typedef DefEqualFloat type; }; - template <> struct EqualSelector<0> { typedef DefEqualInt type; }; + template struct TraitsType; + template <> struct TraitsType<1> + { + typedef DefEqualFloat EqualType; + typedef double BigType; + }; + template <> struct TraitsType<0> + { + typedef DefEqualInt EqualType; + typedef int64_t BigType; + }; } template class Region - { - typedef vector internal_container; - + { public: typedef PointT value_type; typedef typename PointT::value_type coord_type; + private: + typedef vector internal_container; + typedef detail::TraitsType::value> traits_type; + + public: Region() {} template @@ -107,7 +113,7 @@ namespace m2 size_t const numPoints = m_points.size(); - typedef typename detail::BigType::value>::type BigCoordT; + typedef typename traits_type::BigType BigCoordT; typedef Point BigPointT; BigPointT prev = BigPointT(m_points[numPoints - 1]) - BigPointT(pt); @@ -126,7 +132,7 @@ namespace m2 ASSERT_NOT_EQUAL ( curr.y, prev.y, () ); BigCoordT const delta = prev.y - curr.y; - BigCoordT cp = CrossProduct(curr, prev); + BigCoordT const cp = CrossProduct(curr, prev); if (!equalF.EqualZero(cp, delta)) { @@ -153,7 +159,7 @@ namespace m2 bool Contains(PointT const & pt) const { - return Contains(pt, typename detail::EqualSelector::value>::type()); + return Contains(pt, typename traits_type::EqualType()); } private: