diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bdf74ff..e1e94e8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -553,7 +553,7 @@ list ( typeidx.cpp typeidx.hpp types.hpp - types/bits.hpp + types/sized.hpp types/comparator.hpp types/description.cpp types/description.hpp diff --git a/bitwise.hpp b/bitwise.hpp index d3475a1c..5e4e4bea 100644 --- a/bitwise.hpp +++ b/bitwise.hpp @@ -8,7 +8,6 @@ #pragma once -#include "types/bits.hpp" #include "debug/assert.hpp" #include diff --git a/coord/ops.hpp b/coord/ops.hpp index 7fc58823..1cd02225 100644 --- a/coord/ops.hpp +++ b/coord/ops.hpp @@ -17,7 +17,6 @@ #include "../tuple/value.hpp" #include "../debug/assert.hpp" #include "../maths.hpp" -#include "../types/bits.hpp" #include diff --git a/endian.hpp b/endian.hpp index 0e8aa480..0e3c02a9 100644 --- a/endian.hpp +++ b/endian.hpp @@ -9,7 +9,7 @@ #pragma once #include "std.hpp" -#include "types/bits.hpp" +#include "types/sized.hpp" #include #include @@ -196,8 +196,8 @@ namespace cruft { "endian conversion is only defined for integrals currently"); union { - typename sized_type::sint sint; - typename sized_type::uint uint; + typename types::sized::bytes::sint sint; + typename types::sized::bytes::uint uint; }; if (std::is_signed::value) diff --git a/fixed.hpp b/fixed.hpp index 8f257a8a..855daac5 100644 --- a/fixed.hpp +++ b/fixed.hpp @@ -6,10 +6,9 @@ * Copyright 2011-2014 Danny Robson */ -#ifndef __UTIL_FIXED_HPP -#define __UTIL_FIXED_HPP +#pragma once -#include "types/bits.hpp" +#include "types/sized.hpp" #include "maths.hpp" #include @@ -30,8 +29,8 @@ namespace cruft { static_assert (E > 0); static_assert ((I + E) % 8 == 0); - using sint_t = typename bits_type::sint; - using uint_t = typename bits_type::uint; + using sint_t = typename types::sized::bits::sint; + using uint_t = typename types::sized::bits::uint; using native_type = typename std::conditional< std::is_signed::value, @@ -40,8 +39,8 @@ namespace cruft { using integer_type = typename std::conditional< std::is_signed::value, - typename bits_type::sint, - typename bits_type::uint + typename types::sized::bits::sint, + typename types::sized::bits::uint >::type; explicit fixed (double); @@ -112,5 +111,3 @@ namespace cruft { template std::ostream& operator<< (std::ostream&, fixed); } - -#endif // __UTIL_FIXED_HPP diff --git a/float.cpp b/float.cpp index bd11fc53..aeece28a 100644 --- a/float.cpp +++ b/float.cpp @@ -22,7 +22,7 @@ ieee_float::ieee_float (void) //----------------------------------------------------------------------------- template -ieee_float::ieee_float (floating_t _floating): +ieee_float::ieee_float (real_t _floating): m_floating (_floating) { ; } @@ -72,16 +72,31 @@ ieee_float::is_nan (void) const { /////////////////////////////////////////////////////////////////////////////// +namespace { + template + struct has_float : public std::false_type { }; + + template + struct has_float< + BitsV, + std::void_t< + typename cruft::types::sized::bits::real + > + > : public std::true_type { }; +} + + +//----------------------------------------------------------------------------- template bool -ieee_float::operator==(floating_t _floating) const { +ieee_float::operator==(real_t _floating) const { // TODO: This method really shouldn't be generated if there's no // representative native floating point type. But I'm sick of // C++'s template bullshit for tonight. - CHECK (bits_type::has_floating); + CHECK (has_float::value); union { - floating_t _floating; + real_t _floating; uint_t _uint; } convertor; @@ -94,8 +109,8 @@ ieee_float::operator==(floating_t _floating) const { /////////////////////////////////////////////////////////////////////////////// template bool -ieee_float::almost_equal (floating_t a, - floating_t b) +ieee_float::almost_equal (real_t a, + real_t b) { return almost_equal (a, b, 128u); } @@ -105,8 +120,8 @@ ieee_float::almost_equal (floating_t a, // Based on the Cygnus `AlmostEqual2sComplement` function template bool -ieee_float::almost_equal (floating_t _a, - floating_t _b, +ieee_float::almost_equal (real_t _a, + real_t _b, unsigned ulps) { // Ensure ULPs is small enough that the default NaNs won't compare as @@ -114,7 +129,7 @@ ieee_float::almost_equal (floating_t _a, CHECK_LE (ulps, 4 * 1024 * 1024u); union { - floating_t f; + real_t f; sint_t s; uint_t u; } a, b; @@ -132,9 +147,9 @@ ieee_float::almost_equal (floating_t _a, // Re-base negative floats to be continuous against +ve/-ve 0 static const union { - floating_t f; + real_t f; sint_t s; - } NEG_ZERO { -floating_t {0} }; + } NEG_ZERO { -real_t {0} }; if (a.s < 0) a.s = NEG_ZERO.s - a.s; @@ -149,6 +164,6 @@ ieee_float::almost_equal (floating_t _a, /////////////////////////////////////////////////////////////////////////////// -template class cruft::ieee_float< 5, 10>; // ieee_half +//template class cruft::ieee_float< 5, 10>; // ieee_half template class cruft::ieee_float< 8, 23>; // ieee_single; template class cruft::ieee_float<11, 52>; // ieee_double; \ No newline at end of file diff --git a/float.hpp b/float.hpp index 18ffbc1d..b1be5af1 100644 --- a/float.hpp +++ b/float.hpp @@ -9,7 +9,7 @@ #ifndef __FLOAT_HPP #define __FLOAT_HPP -#include "types/bits.hpp" +#include "types/sized.hpp" /////////////////////////////////////////////////////////////////////////////// @@ -24,14 +24,14 @@ namespace cruft { static const unsigned int BIAS = (1 << (EXPONENT - 1)) - 1; - typedef typename bits_type::sint sint_t; - typedef typename bits_type::uint uint_t; - typedef typename bits_type::floating floating_t; + using sint_t = typename types::sized::bits::sint; + using uint_t = typename types::sized::bits::uint; + using real_t = typename types::sized::bits::real; protected: union { - uint_t m_bits; - floating_t m_floating; + uint_t m_bits; + real_t m_floating; struct { uint_t sign : 1; @@ -42,7 +42,7 @@ namespace cruft { public: ieee_float (void); - ieee_float (floating_t _floating); + ieee_float (real_t _floating); ieee_float (const ieee_float &rhs); static unsigned int bias (void) @@ -58,22 +58,22 @@ namespace cruft { bool is_subnormal (void) const; bool is_inifinity (void) const; bool is_nan (void) const; - bool operator== (floating_t) const; + bool operator== (real_t) const; - static bool almost_equal (floating_t, floating_t); - static bool almost_equal (floating_t, floating_t, unsigned ulps); + static bool almost_equal (real_t, real_t); + static bool almost_equal (real_t, real_t, unsigned ulps); }; - typedef ieee_float< 5, 10> ieee_half; + //typedef ieee_float< 5, 10> ieee_half; typedef ieee_float< 8, 23> ieee_single; typedef ieee_float<11, 52> ieee_double; - extern template class ieee_float< 5,10>; + //extern template class ieee_float< 5,10>; extern template class ieee_float< 8,23>; extern template class ieee_float<11,52>; - static_assert (sizeof(ieee_half ) == 2, "ieee_half must be 2 bytes"); + //static_assert (sizeof(ieee_half ) == 2, "ieee_half must be 2 bytes"); static_assert (sizeof(ieee_single ) == 4, "ieee_single must be 4 bytes"); static_assert (sizeof(ieee_double ) == 8, "ieee_double must be 8 bytes"); } diff --git a/geom/sample/surface.hpp b/geom/sample/surface.hpp index 63c367b1..36931be4 100644 --- a/geom/sample/surface.hpp +++ b/geom/sample/surface.hpp @@ -26,9 +26,14 @@ namespace cruft::geom::sample { /// Approximate a poisson disc sampling through the "Mitchell's Best /// Candidate" algorithm. /// - /// Try to keep adding a new point to a set. Each new point is the - /// best of a set of candidates. The 'best' is the point that is - /// furthest from all selected points. + /// We try to keep adding a new point to an output set. + /// * Generate `candidates_count` new points + /// * Remove any point that fails AcceptT + /// * Order the points by minimum distance to the output set + /// * Remove any point with a distance less than DistanceT + /// * Select the point with the highest distance + /// + /// Keep iterating until no point is added to the output set. /// /// \tparam SamplerT A surface sampler /// \tparam DistanceT The type of point-to-point distances diff --git a/hash/fletcher.hpp b/hash/fletcher.hpp index f51b0e8b..873937d7 100644 --- a/hash/fletcher.hpp +++ b/hash/fletcher.hpp @@ -6,10 +6,9 @@ * Copyright 2010-2016 Danny Robson */ -#ifndef __UTIL_HASH_FLETCHER_HPP -#define __UTIL_HASH_FLETCHER_HPP +#pragma once -#include "../types/bits.hpp" +#include "../types/sized.hpp" #include "../view.hpp" #include @@ -22,7 +21,7 @@ namespace cruft::hash { class fletcher { public: using digest_t = DigestT; - using part_t = typename bytes_type::uint; + using part_t = typename types::sized::bytes::uint; fletcher (part_t modulus, part_t a, part_t b); @@ -38,7 +37,3 @@ namespace cruft::hash { const state_t m_initial; }; } - - -#endif - diff --git a/types/bits.hpp b/types/bits.hpp deleted file mode 100644 index f8189854..00000000 --- a/types/bits.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * Copyright 2011 Danny Robson - */ - -#ifndef __UTIL_TYPES_BITS_HPP -#define __UTIL_TYPES_BITS_HPP - -#include -#include - -namespace cruft { - template - struct bits_type; - - - template <> struct bits_type< 8u> { - static const bool has_floating = false; - - typedef uint8_t uint; - typedef int8_t sint; - typedef uint8_t floating; - }; - - - template <> struct bits_type<16u> { - static const bool has_floating = false; - - typedef uint16_t uint; - typedef int16_t sint; - typedef uint16_t floating; - }; - - - template <> struct bits_type<32u> { - static const bool has_floating = true; - - typedef uint32_t uint; - typedef int32_t sint; - typedef float floating; - }; - - - template <> struct bits_type<64u> { - static const bool has_floating = true; - - typedef uint64_t uint; - typedef int64_t sint; - typedef double floating; - }; - - - template - struct bytes_type : public bits_type - { }; - - - template - struct sized_type : public bits_type - { }; - - - template - using bits_uint_t = typename bits_type::uint; - - template - using bytes_uint_t = typename bytes_type::uint; -} -#endif diff --git a/types/sized.hpp b/types/sized.hpp new file mode 100644 index 00000000..ee9b70c0 --- /dev/null +++ b/types/sized.hpp @@ -0,0 +1,59 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2011-2020 Danny Robson + */ + +#pragma once + +#include "../std.hpp" + +#include + + +namespace cruft::types::sized { + template + struct bits; + + + template <> + struct bits< 8u> { + using uint = u08; + using sint = i08; + }; + + + template <> + struct bits<16u> { + using uint = u16; + using sint = i16; + }; + + + template <> + struct bits<32u> { + using uint = u32; + using sint = i32; + using real = f32; + }; + + + template <> + struct bits<64u> { + using uint = u64; + using sint = i64; + using real = f64; + }; + + + template + struct bytes : public bits + { }; + + + template + struct sized_type : public bits + { }; +}