rename root namespace from util to cruft
This places, at long last, the core library code into the same namespace as the extended library code.
This commit is contained in:
parent
803acc9a87
commit
f6056153e3
@ -420,8 +420,9 @@ DEPENDS
|
||||
|
||||
|
||||
###############################################################################
|
||||
add_library(cruft-util ${UTIL_FILES})
|
||||
target_include_directories(cruft-util PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
add_library(cruft ${UTIL_FILES})
|
||||
add_library(cruft-util ALIAS cruft)
|
||||
target_include_directories(cruft PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
|
||||
search_libs (SHM_LIBS shm_open rt)
|
||||
@ -429,21 +430,21 @@ search_libs (DL_LIBS dlopen dl)
|
||||
search_libs (CLOCK_LIBS clock_gettime rt c)
|
||||
search_libs (MATH_LIBS cos m)
|
||||
|
||||
target_link_libraries(cruft-util ${SHM_LIBS})
|
||||
target_link_libraries(cruft-util ${DL_LIBS})
|
||||
target_link_libraries(cruft-util ${CLOCK_LIBS})
|
||||
target_link_libraries(cruft-util ${MATH_LIBS})
|
||||
target_link_libraries(cruft ${SHM_LIBS})
|
||||
target_link_libraries(cruft ${DL_LIBS})
|
||||
target_link_libraries(cruft ${CLOCK_LIBS})
|
||||
target_link_libraries(cruft ${MATH_LIBS})
|
||||
|
||||
# HACK: -ldl isn't getting discovered correctly so we add it unconditionally
|
||||
# for the time being.
|
||||
target_link_libraries(cruft-util dl)
|
||||
target_link_libraries(cruft dl)
|
||||
|
||||
|
||||
###############################################################################
|
||||
foreach (tool cpuid poisson macro scratch)
|
||||
add_executable (util_${tool} tools/${tool}.cpp)
|
||||
set_target_properties (util_${tool} PROPERTIES OUTPUT_NAME ${tool})
|
||||
target_link_libraries (util_${tool} cruft-util)
|
||||
target_link_libraries (util_${tool} cruft)
|
||||
target_include_directories(util_${tool} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
endforeach ()
|
||||
|
||||
@ -547,7 +548,7 @@ if (TESTS)
|
||||
foreach(t ${TEST_BIN})
|
||||
string(REPLACE "/" "_" name "test/${t}")
|
||||
add_executable(util_${name} test/${t}.cpp)
|
||||
target_link_libraries(util_${name} PRIVATE cruft-util)
|
||||
target_link_libraries(util_${name} PRIVATE cruft)
|
||||
target_include_directories(util_${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_test(NAME util_${name} COMMAND util_${name})
|
||||
set_tests_properties(util_${name} PROPERTIES FAIL_REGULAR_EXPRESSION "not ok -")
|
||||
@ -561,12 +562,5 @@ endif ()
|
||||
|
||||
|
||||
###############################################################################
|
||||
get_directory_property (HAS_PARENT PARENT_DIRECTORY)
|
||||
if (HAS_PARENT)
|
||||
set (CRUFT_UTIL_FOUND 1 PARENT_SCOPE)
|
||||
endif ()
|
||||
|
||||
|
||||
##-----------------------------------------------------------------------------
|
||||
configure_file(libcruft-util-system.pc.in libcruft-util.pc)
|
||||
configure_file(libcruft.pc.in libcruft.pc)
|
||||
configure_file(Doxyfile.in Doxyfile)
|
||||
|
@ -1,4 +1,4 @@
|
||||
== libcruft-util
|
||||
== libcruft
|
||||
|
||||
A simple cross-platform C++ utility library.
|
||||
|
||||
|
@ -14,14 +14,14 @@
|
||||
//#include <iostream>
|
||||
//
|
||||
//
|
||||
//using util::adapter::scalar;
|
||||
//using cruft::adapter::scalar;
|
||||
//
|
||||
//
|
||||
//void
|
||||
//foo (void) {
|
||||
// std::vector<std::tuple<int,int,int>> vals;
|
||||
//
|
||||
// using iterator_t = util::adapter::scalar<0, decltype(vals.begin ())>;
|
||||
// using iterator_t = cruft::adapter::scalar<0, decltype(vals.begin ())>;
|
||||
//
|
||||
// static_assert (
|
||||
// std::is_same<
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
|
||||
namespace util::adapter {
|
||||
namespace cruft::adapter {
|
||||
namespace container {
|
||||
// reverse a container for range-based-for
|
||||
template <typename T>
|
||||
|
@ -15,4 +15,4 @@
|
||||
//
|
||||
// this particular instantiation isn't necessarily required by any user, it's
|
||||
// just convenient.
|
||||
template void cruft::util::sort::soa (int*, int*, bool (*)(int,int), double*);
|
||||
template void cruft::cruft::sort::soa (int*, int*, bool (*)(int,int), double*);
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace cruft::util::sort {
|
||||
namespace cruft::cruft::sort {
|
||||
namespace detail {
|
||||
template <typename IndexA, typename IndexB, typename RandomIt>
|
||||
void
|
||||
@ -140,7 +140,7 @@ namespace cruft::util::sort {
|
||||
// reorder function.
|
||||
// TODO: avoid the need for this inverse array.
|
||||
decltype (indices) dest (indices.size ());
|
||||
for (decltype(size) i = 0; i < ::util::cast::sign<ssize_t> (dest.size ()); ++i) {
|
||||
for (decltype(size) i = 0; i < ::cruft::cast::sign<ssize_t> (dest.size ()); ++i) {
|
||||
dest[indices[i]] = i;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
// C++11 allocator concept conformant(ish) allocator adaptor, going from our
|
||||
// allocator interface to that of the STL and friends.
|
||||
namespace util::alloc {
|
||||
namespace cruft::alloc {
|
||||
template <typename ValueT, typename BackingT>
|
||||
class allocator {
|
||||
public:
|
||||
@ -28,7 +28,7 @@ namespace util::alloc {
|
||||
{ ; }
|
||||
|
||||
|
||||
util::view<ValueT*>
|
||||
cruft::view<ValueT*>
|
||||
allocate (size_t count)
|
||||
{
|
||||
return {
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace util::alloc {
|
||||
namespace cruft::alloc {
|
||||
/// wraps a block allocator with an interface suitable for allocating
|
||||
/// individual objects.
|
||||
template <class T>
|
||||
@ -49,13 +49,13 @@ namespace util::alloc {
|
||||
release (U *u)
|
||||
{
|
||||
u->~U ();
|
||||
m_store.template deallocate<U> (util::view {u,1u});
|
||||
m_store.template deallocate<U> (cruft::view {u,1u});
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
template <typename U>
|
||||
using deleter_t = util::memory::owner_deleter<
|
||||
using deleter_t = cruft::memory::owner_deleter<
|
||||
U,arena<T>,&arena::release
|
||||
>;
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace util::alloc {
|
||||
namespace cruft::alloc {
|
||||
template <typename BackingT>
|
||||
class forwarding {
|
||||
public:
|
||||
|
@ -10,7 +10,7 @@
|
||||
#define __UTIL_ALLOC_FWD_HPP
|
||||
|
||||
|
||||
namespace util::alloc {
|
||||
namespace cruft::alloc {
|
||||
namespace raw {
|
||||
class affix;
|
||||
class fallback;
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include "affix.hpp"
|
||||
|
||||
using util::alloc::raw::affix;
|
||||
using cruft::alloc::raw::affix;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace util::alloc::raw {
|
||||
namespace cruft::alloc::raw {
|
||||
/// a raw memory allocator which initialises an instance of PrefixT
|
||||
/// immediately before each allocation and, if specified, an instance
|
||||
/// of SuffixT after the allocation.
|
||||
@ -25,13 +25,13 @@ namespace util::alloc::raw {
|
||||
class affix {
|
||||
|
||||
template <typename T>
|
||||
util::view<T*> allocate (size_t bytes);
|
||||
cruft::view<T*> allocate (size_t bytes);
|
||||
|
||||
template <typename T>
|
||||
util::view<T*> allocate (size_t bytes, size_t align);
|
||||
cruft::view<T*> allocate (size_t bytes, size_t align);
|
||||
|
||||
template <typename T>
|
||||
void deallocate (util::view<std::byte*>);
|
||||
void deallocate (cruft::view<std::byte*>);
|
||||
|
||||
std::byte* begin (void);
|
||||
const std::byte* begin (void) const;
|
||||
|
@ -15,14 +15,14 @@
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
|
||||
namespace util::alloc::raw::aligned {
|
||||
namespace cruft::alloc::raw::aligned {
|
||||
/// wraps a child allocator and enforces a fixed alignment
|
||||
template <typename ChildT>
|
||||
class direct {
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
template <typename ...Args>
|
||||
direct (util::view<std::byte*> _data, std::size_t _alignment, Args &&...args):
|
||||
direct (cruft::view<std::byte*> _data, std::size_t _alignment, Args &&...args):
|
||||
m_successor (_data, std::forward<Args> (args)...),
|
||||
m_alignment (_alignment)
|
||||
{ ; }
|
||||
@ -39,7 +39,7 @@ namespace util::alloc::raw::aligned {
|
||||
//---------------------------------------------------------------------
|
||||
template <typename T>
|
||||
auto
|
||||
deallocate (util::view<T*> ptr)
|
||||
deallocate (cruft::view<T*> ptr)
|
||||
{
|
||||
return m_successor.template deallocate<T> (ptr);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
|
||||
namespace util::alloc::raw::aligned {
|
||||
namespace cruft::alloc::raw::aligned {
|
||||
/// wraps a child allocator and enforces a fixed alignment that is
|
||||
/// independant of the alignment of the provided source buffer.
|
||||
///
|
||||
@ -45,7 +45,7 @@ namespace util::alloc::raw::aligned {
|
||||
class foreign {
|
||||
public:
|
||||
template <typename ...Args>
|
||||
foreign (util::view<std::byte*> _data, std::size_t _alignment, Args &&...args):
|
||||
foreign (cruft::view<std::byte*> _data, std::size_t _alignment, Args &&...args):
|
||||
m_successor (
|
||||
view<std::byte*> {
|
||||
reinterpret_cast<std::byte*> (_alignment),
|
||||
@ -60,7 +60,7 @@ namespace util::alloc::raw::aligned {
|
||||
|
||||
|
||||
template <typename T>
|
||||
util::view<T*>
|
||||
cruft::view<T*>
|
||||
allocate (std::size_t count)
|
||||
{
|
||||
auto root = m_successor.template allocate<T> (count);
|
||||
@ -68,12 +68,12 @@ namespace util::alloc::raw::aligned {
|
||||
|
||||
// we can't use alignment cast here because it will almost
|
||||
// certainly fail the tests it performs.
|
||||
return { util::cast::ffs<T*> (base + m_offset), count };
|
||||
return { cruft::cast::ffs<T*> (base + m_offset), count };
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto
|
||||
deallocate (util::view<T*> ptr)
|
||||
deallocate (cruft::view<T*> ptr)
|
||||
{
|
||||
auto base = ptr.template cast<char*> ();
|
||||
auto next = base - m_offset;
|
||||
@ -81,7 +81,7 @@ namespace util::alloc::raw::aligned {
|
||||
// we can't use alignment cast here because it will almost
|
||||
// certainly fail the tests it performs.
|
||||
return m_successor.template deallocate<T> (
|
||||
util::view<T*> { util::cast::ffs<T*> (next), ptr.size () }
|
||||
cruft::view<T*> { cruft::cast::ffs<T*> (next), ptr.size () }
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
namespace util::alloc::raw {
|
||||
namespace cruft::alloc::raw {
|
||||
// wraps an allocator given at construction time, forwarding all calls to
|
||||
// the inner object. used to allow virtual dispatch of the non-virtual
|
||||
// allocator interface.
|
||||
@ -93,8 +93,8 @@ namespace util::alloc::raw {
|
||||
virtual ~interface () { ; }
|
||||
|
||||
// allocation management
|
||||
virtual util::view<std::byte*> allocate (size_t bytes) = 0;
|
||||
virtual util::view<std::byte*> allocate (size_t bytes, size_t alignment) = 0;
|
||||
virtual cruft::view<std::byte*> allocate (size_t bytes) = 0;
|
||||
virtual cruft::view<std::byte*> allocate (size_t bytes, size_t alignment) = 0;
|
||||
|
||||
virtual void deallocate (void *ptr, size_t bytes) = 0;
|
||||
virtual void deallocate (void *ptr, size_t bytes, size_t alignment) = 0;
|
||||
@ -127,7 +127,7 @@ namespace util::alloc::raw {
|
||||
{ ; }
|
||||
|
||||
// allocation management
|
||||
util::view<std::byte*>
|
||||
cruft::view<std::byte*>
|
||||
allocate (size_t bytes) override
|
||||
{ return m_target.allocate (bytes); }
|
||||
|
||||
@ -135,7 +135,7 @@ namespace util::alloc::raw {
|
||||
// we can't totally eliminate this call given the point is to
|
||||
// expose the common API area, but we will throw if the operation
|
||||
// is unsupported in the child.
|
||||
util::view<std::byte*>
|
||||
cruft::view<std::byte*>
|
||||
allocate (size_t bytes, size_t alignment) override
|
||||
{
|
||||
if constexpr (has_aligned_allocate_v<ChildT>) {
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <cstddef>
|
||||
#include <tuple>
|
||||
|
||||
namespace util::alloc::raw {
|
||||
namespace cruft::alloc::raw {
|
||||
/// A raw memory allocator that allocates memory series of child
|
||||
/// allocators, preferring earlier allocators.
|
||||
template <typename ...ChildT>
|
||||
@ -25,15 +25,15 @@ namespace util::alloc::raw {
|
||||
{ ; }
|
||||
|
||||
template <typename T>
|
||||
util::view<T*>
|
||||
cruft::view<T*>
|
||||
allocate (size_t bytes);
|
||||
|
||||
template <typename T>
|
||||
util::view<T*>
|
||||
cruft::view<T*>
|
||||
allocate (size_t bytes, size_t align);
|
||||
|
||||
template <typename T>
|
||||
void deallocate (util::view<std::byte*> ptr);
|
||||
void deallocate (cruft::view<std::byte*> ptr);
|
||||
|
||||
private:
|
||||
std::tuple<ChildT&...> m_children;
|
||||
|
@ -11,11 +11,11 @@
|
||||
#include "../../pointer.hpp"
|
||||
#include "../../debug.hpp"
|
||||
|
||||
using util::alloc::raw::linear;
|
||||
using cruft::alloc::raw::linear;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
linear::linear (util::view<std::byte*> _data):
|
||||
linear::linear (cruft::view<std::byte*> _data):
|
||||
m_begin (_data.begin ()),
|
||||
m_end (_data.end ()),
|
||||
m_cursor (_data.begin ())
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
|
||||
namespace util::alloc::raw {
|
||||
namespace cruft::alloc::raw {
|
||||
// allocate progressively across a buffer without concern for deallocation.
|
||||
// deallocation is a noop; the only way to free allocations is via reset.
|
||||
class linear {
|
||||
@ -25,10 +25,10 @@ namespace util::alloc::raw {
|
||||
linear& operator= (const linear&) = delete;
|
||||
linear& operator= (linear&&) = delete;
|
||||
|
||||
linear (util::view<std::byte*> _data);
|
||||
linear (cruft::view<std::byte*> _data);
|
||||
|
||||
template <typename T>
|
||||
util::view<T*>
|
||||
cruft::view<T*>
|
||||
allocate (size_t count)
|
||||
{
|
||||
auto const bytes = count * sizeof (T);
|
||||
@ -37,27 +37,27 @@ namespace util::alloc::raw {
|
||||
|
||||
auto ptr = m_cursor;
|
||||
m_cursor += bytes;
|
||||
return { util::cast::alignment<T*> (ptr), count };
|
||||
return { cruft::cast::alignment<T*> (ptr), count };
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
util::view<T*>
|
||||
cruft::view<T*>
|
||||
allocate (size_t count, size_t alignment)
|
||||
{
|
||||
auto const bytes = count * sizeof (T);
|
||||
|
||||
auto ptr = util::align (m_cursor, alignment);
|
||||
auto ptr = cruft::align (m_cursor, alignment);
|
||||
if (ptr + bytes > m_end)
|
||||
throw std::bad_alloc ();
|
||||
|
||||
m_cursor = ptr + bytes;
|
||||
|
||||
return { util::cast::alignment<T*> (ptr), count };
|
||||
return { cruft::cast::alignment<T*> (ptr), count };
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void deallocate (util::view<T*> ptr)
|
||||
void deallocate (cruft::view<T*> ptr)
|
||||
{
|
||||
(void)ptr;
|
||||
}
|
||||
@ -81,12 +81,12 @@ namespace util::alloc::raw {
|
||||
CHECK_MOD (reinterpret_cast<uintptr_t> (ptr), sizeof (ValueT));
|
||||
CHECK_MOD (reinterpret_cast<uintptr_t> (data ()), sizeof (ValueT));
|
||||
|
||||
return ptr - util::cast::alignment<ValueT const*> (data ());
|
||||
return ptr - cruft::cast::alignment<ValueT const*> (data ());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t
|
||||
offset (util::view<T*> ptr) const
|
||||
offset (cruft::view<T*> ptr) const
|
||||
{
|
||||
return offset (ptr.data ());
|
||||
}
|
||||
|
@ -14,11 +14,11 @@
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace util::alloc::raw {
|
||||
namespace cruft::alloc::raw {
|
||||
class malloc {
|
||||
public:
|
||||
template <typename T>
|
||||
util::view<T*> allocate (size_t count)
|
||||
cruft::view<T*> allocate (size_t count)
|
||||
{
|
||||
return {
|
||||
reinterpret_cast<T*> (malloc (sizeof (T) * count)),
|
||||
@ -27,7 +27,7 @@ namespace util::alloc::raw {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
util::view<T*>
|
||||
cruft::view<T*>
|
||||
allocate (size_t count, size_t align)
|
||||
{
|
||||
void* ptr;
|
||||
@ -40,7 +40,7 @@ namespace util::alloc::raw {
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
deallocate (util::view<std::byte*> ptr)
|
||||
deallocate (cruft::view<std::byte*> ptr)
|
||||
{
|
||||
::free (ptr.data ());
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include <new>
|
||||
|
||||
using util::alloc::raw::null;
|
||||
using cruft::alloc::raw::null;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace util::alloc::raw {
|
||||
namespace cruft::alloc::raw {
|
||||
// allocator that always fails, throwing bad_alloc. deallocate will
|
||||
// succeed with nullptr as with delete, but is undefined with other values
|
||||
// (it is likely to at least assert).
|
||||
@ -25,14 +25,14 @@ namespace util::alloc::raw {
|
||||
null& operator= (const null&) = delete;
|
||||
|
||||
template <typename T>
|
||||
util::view<T*>
|
||||
cruft::view<T*>
|
||||
allocate (size_t count)
|
||||
{
|
||||
return allocate<T> (count, alignof (T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
util::view<T*>
|
||||
cruft::view<T*>
|
||||
allocate (size_t count, size_t align)
|
||||
{
|
||||
(void)count;
|
||||
@ -43,14 +43,14 @@ namespace util::alloc::raw {
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
deallocate (util::view<T*> ptr)
|
||||
deallocate (cruft::view<T*> ptr)
|
||||
{
|
||||
(void)ptr;
|
||||
CHECK_EQ (ptr.data (), static_cast<const void*> (nullptr));
|
||||
}
|
||||
|
||||
util::view<std::byte*> data (void);
|
||||
util::view<const std::byte*> data (void) const;
|
||||
cruft::view<std::byte*> data (void);
|
||||
cruft::view<const std::byte*> data (void) const;
|
||||
|
||||
std::byte* begin (void);
|
||||
const std::byte* begin (void) const;
|
||||
|
@ -12,11 +12,11 @@
|
||||
#include "../../pointer.hpp"
|
||||
#include "../../cast.hpp"
|
||||
|
||||
using util::alloc::raw::stack;
|
||||
using cruft::alloc::raw::stack;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
stack::stack (util::view<std::byte*> _data):
|
||||
stack::stack (cruft::view<std::byte*> _data):
|
||||
m_begin (_data.begin ()),
|
||||
m_end (_data.end ()),
|
||||
m_cursor (m_begin)
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace util::alloc::raw {
|
||||
namespace cruft::alloc::raw {
|
||||
// allocate memory from a buffer in a stacklike manner. deallocation that
|
||||
// is not correctly ordered has undefined (read 'bad') results.
|
||||
class stack {
|
||||
@ -25,10 +25,10 @@ namespace util::alloc::raw {
|
||||
stack& operator= (const stack&) = delete;
|
||||
stack& operator= (stack&&) = delete;
|
||||
|
||||
stack (util::view<std::byte*> _data);
|
||||
stack (cruft::view<std::byte*> _data);
|
||||
|
||||
template <typename T>
|
||||
util::view<T*>
|
||||
cruft::view<T*>
|
||||
allocate (size_t count, size_t alignment)
|
||||
{
|
||||
constexpr auto MIN_ALIGNMENT = sizeof (record::offset_t);
|
||||
@ -39,8 +39,8 @@ namespace util::alloc::raw {
|
||||
auto ptr = m_cursor + sizeof (record::offset_t);
|
||||
|
||||
// align the outgoing pointer if required
|
||||
alignment = util::max (MIN_ALIGNMENT, alignment);
|
||||
ptr = util::align (ptr, alignment);
|
||||
alignment = cruft::max (MIN_ALIGNMENT, alignment);
|
||||
ptr = cruft::align (ptr, alignment);
|
||||
|
||||
// ensure we haven't overrun our allocated segment
|
||||
if (ptr + bytes > m_end)
|
||||
@ -51,15 +51,15 @@ namespace util::alloc::raw {
|
||||
// (from the record struct). allows us to account for alignment.
|
||||
record r;
|
||||
r.as_bytes = ptr - sizeof (record::offset_t);
|
||||
*r.as_offset = util::cast::lossless <uint32_t> (ptr - m_cursor);
|
||||
*r.as_offset = cruft::cast::lossless <uint32_t> (ptr - m_cursor);
|
||||
|
||||
m_cursor = ptr + bytes;
|
||||
return { util::cast::alignment<T*> (ptr), count };
|
||||
return { cruft::cast::alignment<T*> (ptr), count };
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
util::view<T*>
|
||||
cruft::view<T*>
|
||||
allocate (size_t count)
|
||||
{
|
||||
return allocate<T> (count, alignof (T));
|
||||
@ -67,7 +67,7 @@ namespace util::alloc::raw {
|
||||
|
||||
|
||||
template <typename T>
|
||||
void deallocate (util::view<T*> _ptr)
|
||||
void deallocate (cruft::view<T*> _ptr)
|
||||
{
|
||||
auto ptr = reinterpret_cast<std::byte*> (_ptr.data ());
|
||||
|
||||
@ -82,8 +82,8 @@ namespace util::alloc::raw {
|
||||
}
|
||||
|
||||
|
||||
util::view<std::byte*> data (void);
|
||||
util::view<const std::byte*> data (void) const;
|
||||
cruft::view<std::byte*> data (void);
|
||||
cruft::view<const std::byte*> data (void) const;
|
||||
|
||||
std::byte* begin (void);
|
||||
const std::byte* begin (void) const;
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
namespace util::alloc::raw {
|
||||
namespace cruft::alloc::raw {
|
||||
template <typename AllocT, typename = std::void_t<>>
|
||||
struct has_aligned_allocate : std::false_type {};
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <cstdint>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace util::ascii {
|
||||
namespace cruft::ascii {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
constexpr inline
|
||||
bool
|
||||
@ -131,7 +131,7 @@ operator"" _hex2u8 (const char *str, size_t len)
|
||||
std::vector<uint8_t> res (len/2);
|
||||
|
||||
for (size_t i = 0; i < len; i += 2)
|
||||
res[i/2] = util::ascii::from_hex (str[i]) << 4 | util::ascii::from_hex (str[i+1]);
|
||||
res[i/2] = cruft::ascii::from_hex (str[i]) << 4 | cruft::ascii::from_hex (str[i+1]);
|
||||
return res;
|
||||
};
|
||||
|
||||
@ -147,8 +147,8 @@ operator"" _hex2array (void)
|
||||
constexpr CharT literal[] = { StrV... };
|
||||
|
||||
for (size_t i = 0; i < res.size (); ++i)
|
||||
res[i] = util::ascii::from_hex (literal[i*2+0]) << 4 |
|
||||
util::ascii::from_hex (literal[i*2+1]);
|
||||
res[i] = cruft::ascii::from_hex (literal[i*2+0]) << 4 |
|
||||
cruft::ascii::from_hex (literal[i*2+1]);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ debug::backtrace::backtrace (void):
|
||||
size_t last;
|
||||
size_t size = m_frames.size ();
|
||||
|
||||
while ((last = ::backtrace (&m_frames[0], util::cast::lossless <int> (m_frames.size ()))) == size)
|
||||
while ((last = ::backtrace (&m_frames[0], cruft::cast::lossless <int> (m_frames.size ()))) == size)
|
||||
m_frames.resize (size = m_frames.size () * 2);
|
||||
|
||||
CHECK_GT (last, 0u);
|
||||
@ -44,7 +44,7 @@ addr2line (const void *addr)
|
||||
using pstream_t = std::unique_ptr<FILE,decltype(&::pclose)>;
|
||||
|
||||
std::ostringstream cmd;
|
||||
cmd << ADDR2LINE << " -e " << util::image_path () << ' ' << std::hex << addr;
|
||||
cmd << ADDR2LINE << " -e " << cruft::image_path () << ' ' << std::hex << addr;
|
||||
|
||||
pstream_t stream (
|
||||
::popen (cmd.str ().c_str (), "r"),
|
||||
@ -52,7 +52,7 @@ addr2line (const void *addr)
|
||||
);
|
||||
|
||||
// inefficient to copy from vector to string, but it's not a high priority path
|
||||
auto data = util::slurp<char> (stream.get ());
|
||||
auto data = cruft::slurp<char> (stream.get ());
|
||||
return std::string (data.cbegin (), data.cend ());
|
||||
|
||||
#else
|
||||
@ -68,7 +68,7 @@ debug::operator <<(std::ostream &os, const debug::backtrace &rhs) {
|
||||
|
||||
// We don't use the array form of unique_ptr as clang fails on ambigious constructors
|
||||
typedef std::unique_ptr<char *, decltype(&std::free)> str_t;
|
||||
str_t names (backtrace_symbols (frames.data (), util::cast::lossless <int> (frames.size ())), ::free);
|
||||
str_t names (backtrace_symbols (frames.data (), cruft::cast::lossless <int> (frames.size ())), ::free);
|
||||
|
||||
for (unsigned int i = 0; i < frames.size (); ++i)
|
||||
os << frames[i] << '\t' << names.get()[i] << '\t' << addr2line (frames[i]);
|
||||
|
@ -59,7 +59,7 @@ backtrace::backtrace ()
|
||||
SymGetModuleBase64,
|
||||
nullptr))
|
||||
{
|
||||
util::win32::error::throw_code ();
|
||||
cruft::win32::error::throw_code ();
|
||||
}
|
||||
|
||||
// we've read the bottom of the stack
|
||||
|
@ -26,7 +26,7 @@ debug::backtrace::backtrace (void)
|
||||
|
||||
auto process = GetCurrentProcess();
|
||||
if (!SymInitialize (process, NULL, TRUE))
|
||||
util::win32::error::throw_code ();
|
||||
cruft::win32::error::throw_code ();
|
||||
|
||||
while (true) {
|
||||
auto res = CaptureStackBackTrace (1, m_frames.size (), m_frames.data (), NULL);
|
||||
|
44
bezier.cpp
44
bezier.cpp
@ -19,7 +19,7 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t N>
|
||||
util::bezier<N>::bezier (const util::point2f (&_points)[N+1])
|
||||
cruft::bezier<N>::bezier (const cruft::point2f (&_points)[N+1])
|
||||
{
|
||||
std::copy (_points, _points + N + 1, m_points);
|
||||
}
|
||||
@ -31,7 +31,7 @@ util::bezier<N>::bezier (const util::point2f (&_points)[N+1])
|
||||
// of other more comprehensive tests.
|
||||
template <size_t N>
|
||||
size_t
|
||||
util::bezier<N>::intersections (point2f p0, point2f p1) const
|
||||
cruft::bezier<N>::intersections (point2f p0, point2f p1) const
|
||||
{
|
||||
float A = p1.y - p0.y; // A = y2 - y1
|
||||
float B = p0.x - p1.x; // B = x1 - x2
|
||||
@ -63,7 +63,7 @@ util::bezier<N>::intersections (point2f p0, point2f p1) const
|
||||
continue;
|
||||
|
||||
// Find the line's intersection point
|
||||
const util::vector2f q = polynomial::eval (bcoeff, t);
|
||||
const cruft::vector2f q = polynomial::eval (bcoeff, t);
|
||||
|
||||
const auto s = almost_equal (p0.x, p1.x) ?
|
||||
(q.y-p0.y) / (p1.y-p0.y) :
|
||||
@ -80,8 +80,8 @@ util::bezier<N>::intersections (point2f p0, point2f p1) const
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t N>
|
||||
util::region2f
|
||||
util::bezier<N>::region (void) const
|
||||
cruft::region2f
|
||||
cruft::bezier<N>::region (void) const
|
||||
{
|
||||
float x0 = m_points[0].x;
|
||||
float y0 = m_points[0].y;
|
||||
@ -97,8 +97,8 @@ util::bezier<N>::region (void) const
|
||||
y1 = max (y1, m_points[i].y);
|
||||
}
|
||||
|
||||
util::point2f p0 { x0, y0 };
|
||||
util::point2f p1 { x1, y1 };
|
||||
cruft::point2f p0 { x0, y0 };
|
||||
cruft::point2f p1 { x1, y1 };
|
||||
|
||||
return { p0, p1 };
|
||||
}
|
||||
@ -106,8 +106,8 @@ util::bezier<N>::region (void) const
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t N>
|
||||
util::point2f&
|
||||
util::bezier<N>::operator[] (size_t idx)
|
||||
cruft::point2f&
|
||||
cruft::bezier<N>::operator[] (size_t idx)
|
||||
{
|
||||
CHECK_LE (idx, N);
|
||||
|
||||
@ -117,8 +117,8 @@ util::bezier<N>::operator[] (size_t idx)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t N>
|
||||
const util::point2f&
|
||||
util::bezier<N>::operator[] (size_t idx) const
|
||||
const cruft::point2f&
|
||||
cruft::bezier<N>::operator[] (size_t idx) const
|
||||
{
|
||||
CHECK_LE (idx, N);
|
||||
|
||||
@ -128,8 +128,8 @@ util::bezier<N>::operator[] (size_t idx) const
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t N>
|
||||
const util::point2f*
|
||||
util::bezier<N>::begin (void) const
|
||||
const cruft::point2f*
|
||||
cruft::bezier<N>::begin (void) const
|
||||
{
|
||||
return std::cbegin (m_points);
|
||||
}
|
||||
@ -137,8 +137,8 @@ util::bezier<N>::begin (void) const
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t N>
|
||||
const util::point2f*
|
||||
util::bezier<N>::end (void) const
|
||||
const cruft::point2f*
|
||||
cruft::bezier<N>::end (void) const
|
||||
{
|
||||
return std::cend (m_points);
|
||||
}
|
||||
@ -146,8 +146,8 @@ util::bezier<N>::end (void) const
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t N>
|
||||
const util::point2f*
|
||||
util::bezier<N>::cbegin (void) const
|
||||
const cruft::point2f*
|
||||
cruft::bezier<N>::cbegin (void) const
|
||||
{
|
||||
return std::cbegin (m_points);
|
||||
}
|
||||
@ -155,8 +155,8 @@ util::bezier<N>::cbegin (void) const
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t N>
|
||||
const util::point2f*
|
||||
util::bezier<N>::cend (void) const
|
||||
const cruft::point2f*
|
||||
cruft::bezier<N>::cend (void) const
|
||||
{
|
||||
return std::cend (m_points);
|
||||
}
|
||||
@ -165,7 +165,7 @@ util::bezier<N>::cend (void) const
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t N>
|
||||
std::ostream&
|
||||
util::operator<< (std::ostream &os, const bezier<N> &b)
|
||||
cruft::operator<< (std::ostream &os, const bezier<N> &b)
|
||||
{
|
||||
using value_type = decltype(*b.cbegin());
|
||||
|
||||
@ -182,8 +182,8 @@ util::operator<< (std::ostream &os, const bezier<N> &b)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INSTANTIATE(N) \
|
||||
template class util::bezier<N>; \
|
||||
template std::ostream& util::operator<< (std::ostream&, const bezier<N>&);
|
||||
template class cruft::bezier<N>; \
|
||||
template std::ostream& cruft::operator<< (std::ostream&, const bezier<N>&);
|
||||
|
||||
INSTANTIATE(1)
|
||||
INSTANTIATE(2)
|
||||
|
10
bezier.hpp
10
bezier.hpp
@ -14,7 +14,7 @@
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
struct sdot_t {
|
||||
float distance;
|
||||
float dot;
|
||||
@ -25,7 +25,7 @@ namespace util {
|
||||
public:
|
||||
using value_type = point2f::value_type;
|
||||
|
||||
bezier (const util::point2f (&)[N+1]);
|
||||
bezier (const cruft::point2f (&)[N+1]);
|
||||
|
||||
point2f eval (float t) const;
|
||||
|
||||
@ -35,11 +35,11 @@ namespace util {
|
||||
|
||||
size_t intersections (point2f from, point2f to) const;
|
||||
|
||||
util::vector2f tangent (float t) const;
|
||||
cruft::vector2f tangent (float t) const;
|
||||
// 1st derivative w.r.t. t
|
||||
util::vector2f d1 (float t) const noexcept;
|
||||
cruft::vector2f d1 (float t) const noexcept;
|
||||
// 2nd derivative w.r.t. t
|
||||
util::vector2f d2 (float t) const noexcept;
|
||||
cruft::vector2f d2 (float t) const noexcept;
|
||||
|
||||
float closest (point2f) const noexcept;
|
||||
|
||||
|
26
bezier1.cpp
26
bezier1.cpp
@ -12,7 +12,7 @@
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
point2f
|
||||
bezier<1>::eval (float t) const
|
||||
@ -33,20 +33,20 @@ namespace util {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
constexpr
|
||||
util::vector2f
|
||||
orthonormal (util::vector2f v)
|
||||
cruft::vector2f
|
||||
orthonormal (cruft::vector2f v)
|
||||
{
|
||||
const auto len = norm (v);
|
||||
CHECK_NEZ (len);
|
||||
return util::vector2f { -v.y / len, v.x / len };
|
||||
return cruft::vector2f { -v.y / len, v.x / len };
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
float
|
||||
bezier<1>::closest (util::point2f q) const noexcept
|
||||
bezier<1>::closest (cruft::point2f q) const noexcept
|
||||
{
|
||||
const auto ab = m_points[1] - m_points[0];
|
||||
const auto aq = q - m_points[0];
|
||||
@ -57,22 +57,22 @@ namespace util {
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
float
|
||||
bezier<1>::distance (util::point2f q) const noexcept
|
||||
bezier<1>::distance (cruft::point2f q) const noexcept
|
||||
{
|
||||
const auto ab = m_points[1] - m_points[0];
|
||||
const auto t = clamp (closest (q), 0.f, 1.f);
|
||||
const auto p = m_points[0] + t * ab;
|
||||
|
||||
return util::distance (q, p);
|
||||
return cruft::distance (q, p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
sdot_t
|
||||
bezier<1>::sdot (const point2f q) const noexcept
|
||||
@ -88,7 +88,7 @@ namespace util {
|
||||
|
||||
// if we're on the segment return the distance to the segment
|
||||
if (t >= 0 && t <= 1) {
|
||||
const auto ortho = util::vector2f { -ab.y, ab.x } / norm (ab);
|
||||
const auto ortho = cruft::vector2f { -ab.y, ab.x } / norm (ab);
|
||||
const auto d = dot (ortho, qa);
|
||||
|
||||
// not _entirely_ sure why we need this condition
|
||||
@ -109,9 +109,9 @@ namespace util {
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
std::array<util::vector2f,2>
|
||||
std::array<cruft::vector2f,2>
|
||||
bezier<1>::coeffs (void) const
|
||||
{
|
||||
auto &v = m_coeffs;
|
||||
|
18
bezier2.cpp
18
bezier2.cpp
@ -13,7 +13,7 @@
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
point2f
|
||||
bezier<2>::eval (float t) const
|
||||
@ -28,15 +28,15 @@ namespace util {
|
||||
(1 - t) * (1 - t) * P0 +
|
||||
2 * (1 - t) * t * P1 +
|
||||
t * t * P2
|
||||
).as<util::point> ();
|
||||
).as<cruft::point> ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
std::array<util::vector2f,3>
|
||||
std::array<cruft::vector2f,3>
|
||||
bezier<2>::coeffs (void) const
|
||||
{
|
||||
auto &v = m_coeffs;
|
||||
@ -51,9 +51,9 @@ namespace util {
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
util::vector2f
|
||||
cruft::vector2f
|
||||
bezier<2>::d1 (const float t) const noexcept
|
||||
{
|
||||
CHECK_LIMIT (t, 0.f, 1.f);
|
||||
@ -69,7 +69,7 @@ namespace util {
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
sdot_t
|
||||
bezier<2>::sdot (point2f q) const noexcept
|
||||
@ -167,10 +167,10 @@ namespace util {
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
float
|
||||
bezier<2>::distance (util::point2f q) const noexcept
|
||||
bezier<2>::distance (cruft::point2f q) const noexcept
|
||||
{
|
||||
return abs (sdot (q).distance);
|
||||
}
|
||||
|
48
bezier3.cpp
48
bezier3.cpp
@ -14,7 +14,7 @@
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
point2f
|
||||
bezier<3>::eval (float t) const
|
||||
@ -36,9 +36,9 @@ namespace util {
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
std::array<util::vector2f,4>
|
||||
std::array<cruft::vector2f,4>
|
||||
bezier<3>::coeffs (void) const
|
||||
{
|
||||
const auto &v = m_coeffs;
|
||||
@ -54,8 +54,8 @@ namespace util {
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
float refine_cubic (util::bezier<3> b,
|
||||
util::point2f target,
|
||||
float refine_cubic (cruft::bezier<3> b,
|
||||
cruft::point2f target,
|
||||
float t,
|
||||
float d,
|
||||
float p)
|
||||
@ -68,11 +68,11 @@ float refine_cubic (util::bezier<3> b,
|
||||
float t_l = std::max (0.f, t - p);
|
||||
float t_r = std::min (1.f, t + p);
|
||||
|
||||
util::point2f p_l = b.eval (t_l);
|
||||
util::point2f p_r = b.eval (t_r);
|
||||
cruft::point2f p_l = b.eval (t_l);
|
||||
cruft::point2f p_r = b.eval (t_r);
|
||||
|
||||
float d_l = util::distance (target, p_l);
|
||||
float d_r = util::distance (target, p_r);
|
||||
float d_l = cruft::distance (target, p_l);
|
||||
float d_r = cruft::distance (target, p_r);
|
||||
|
||||
if (d_l < d) { return refine_cubic (b, target, t_l, d_l, p); }
|
||||
if (d_r < d) { return refine_cubic (b, target, t_r, d_r, p); }
|
||||
@ -82,22 +82,22 @@ float refine_cubic (util::bezier<3> b,
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
// TODO: use a more reliable method like [Xiao-Dia Chen 2010]
|
||||
template <>
|
||||
float
|
||||
bezier<3>::distance (util::point2f target) const noexcept
|
||||
bezier<3>::distance (cruft::point2f target) const noexcept
|
||||
{
|
||||
static constexpr int SUBDIV = 32;
|
||||
std::array<util::point2f, SUBDIV> lookup;
|
||||
std::array<cruft::point2f, SUBDIV> lookup;
|
||||
|
||||
for (int i = 0; i < SUBDIV; ++i)
|
||||
lookup[i] = eval (i / (SUBDIV - 1.f));
|
||||
|
||||
size_t best = 0;
|
||||
for (size_t i = 1; i < lookup.size (); ++i) {
|
||||
auto d_i = util::distance2 (target, lookup[i]);
|
||||
auto d_b = util::distance2 (target, lookup[best]);
|
||||
auto d_i = cruft::distance2 (target, lookup[i]);
|
||||
auto d_b = cruft::distance2 (target, lookup[best]);
|
||||
|
||||
if (d_i < d_b)
|
||||
best = i;
|
||||
@ -106,16 +106,16 @@ namespace util {
|
||||
return refine_cubic (*this,
|
||||
target,
|
||||
best / float (SUBDIV - 1),
|
||||
util::distance (target, lookup[best]),
|
||||
cruft::distance (target, lookup[best]),
|
||||
1.f / SUBDIV);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
util::vector2f
|
||||
cruft::vector2f
|
||||
bezier<3>::tangent (const float t) const
|
||||
{
|
||||
CHECK_LIMIT (t, 0.f, 1.f);
|
||||
@ -130,9 +130,9 @@ namespace util {
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
util::vector2f
|
||||
cruft::vector2f
|
||||
bezier<3>::d1 (const float t) const noexcept
|
||||
{
|
||||
const auto &P0 = m_points[0];
|
||||
@ -148,9 +148,9 @@ namespace util {
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
util::vector2f
|
||||
cruft::vector2f
|
||||
bezier<3>::d2 (const float t) const noexcept
|
||||
{
|
||||
const auto &P0 = m_points[0];
|
||||
@ -165,7 +165,7 @@ namespace util {
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <>
|
||||
sdot_t
|
||||
bezier<3>::sdot (point2f src) const noexcept
|
||||
@ -180,14 +180,14 @@ namespace util {
|
||||
float t = std::numeric_limits<float>::quiet_NaN ();
|
||||
|
||||
// distance from A
|
||||
const auto d_a = util::sign (cross (ab, qa)) * norm (qa);
|
||||
const auto d_a = cruft::sign (cross (ab, qa)) * norm (qa);
|
||||
if (abs (d_a) < abs (d)) {
|
||||
d = d_a;
|
||||
t = -dot (ab, qa) / norm2 (ab);
|
||||
}
|
||||
|
||||
// distance from D
|
||||
const auto d_d = util::sign (cross (cd, qd)) * norm (qd);
|
||||
const auto d_d = cruft::sign (cross (cd, qd)) * norm (qd);
|
||||
if (abs (d_d) < abs (d)) {
|
||||
d = d_d;
|
||||
t = -dot (cd, qd) / norm2 (cd);
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
const uint8_t BITMASK_1BITS = 0x01;
|
||||
const uint8_t BITMASK_2BITS = 0x03;
|
||||
const uint8_t BITMASK_3BITS = 0x07;
|
||||
|
2
cast.hpp
2
cast.hpp
@ -15,7 +15,7 @@
|
||||
#include <limits>
|
||||
|
||||
|
||||
namespace util::cast {
|
||||
namespace cruft::cast {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// Safely cast a numeric type to its (un)signed counterpart, aborting if
|
||||
/// the dynamically checked result is not representable. May be optimised
|
||||
|
24
cmdopt.cpp
24
cmdopt.cpp
@ -15,8 +15,8 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace util::cmdopt;
|
||||
using namespace util::cmdopt::option;
|
||||
using namespace cruft::cmdopt;
|
||||
using namespace cruft::cmdopt::option;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -147,7 +147,7 @@ present::finish (void)
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace util::cmdopt::option {
|
||||
namespace cruft::cmdopt::option {
|
||||
template class value<uint16_t>;
|
||||
template class value<uint32_t>;
|
||||
template class value<uint64_t>;
|
||||
@ -172,7 +172,7 @@ count<T>::execute (void)
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace util::cmdopt::option {
|
||||
namespace cruft::cmdopt::option {
|
||||
template class count<unsigned>;
|
||||
}
|
||||
|
||||
@ -184,27 +184,27 @@ suffix_to_multiplier (char c)
|
||||
switch (c) {
|
||||
case 'e':
|
||||
case 'E':
|
||||
return util::pow (1024UL, 6u);
|
||||
return cruft::pow (1024UL, 6u);
|
||||
|
||||
case 'p':
|
||||
case 'P':
|
||||
return util::pow (1024UL, 5u);
|
||||
return cruft::pow (1024UL, 5u);
|
||||
|
||||
case 't':
|
||||
case 'T':
|
||||
return util::pow (1024UL, 4u);
|
||||
return cruft::pow (1024UL, 4u);
|
||||
|
||||
case 'g':
|
||||
case 'G':
|
||||
return util::pow (1024UL, 3u);
|
||||
return cruft::pow (1024UL, 3u);
|
||||
|
||||
case 'm':
|
||||
case 'M':
|
||||
return util::pow (1024UL, 2u);
|
||||
return cruft::pow (1024UL, 2u);
|
||||
|
||||
case 'k':
|
||||
case 'K':
|
||||
return util::pow (1024UL, 1u);
|
||||
return cruft::pow (1024UL, 1u);
|
||||
|
||||
default:
|
||||
const char str[2] = { c, '\0' };
|
||||
@ -426,13 +426,13 @@ parser::print_help (const int argc,
|
||||
else
|
||||
std::cout << '\t';
|
||||
|
||||
std::cout << std::setw (util::cast::lossless<int> (longwidth));
|
||||
std::cout << std::setw (cruft::cast::lossless<int> (longwidth));
|
||||
if (l != std::cend (m_long))
|
||||
std::cout << l->first << '\t';
|
||||
else
|
||||
std::cout << ' ' << '\t';
|
||||
|
||||
std::cout << std::setw (util::cast::lossless<int> (longexample)) << opt.handler->example () << '\t'
|
||||
std::cout << std::setw (cruft::cast::lossless<int> (longexample)) << opt.handler->example () << '\t'
|
||||
<< std::setw (0) << opt.description
|
||||
<< '\n';
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util::cmdopt {
|
||||
namespace cruft::cmdopt {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class error : public std::exception { };
|
||||
|
||||
|
28
colour.cpp
28
colour.cpp
@ -13,8 +13,8 @@
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
static util::srgba4f
|
||||
parse_hex (util::view<const char*> str)
|
||||
static cruft::srgba4f
|
||||
parse_hex (cruft::view<const char*> str)
|
||||
{
|
||||
if (str.size () != strlen ("#012345"))
|
||||
throw std::invalid_argument ("expected length of 7");
|
||||
@ -22,29 +22,29 @@ parse_hex (util::view<const char*> str)
|
||||
if (str[0] != '#')
|
||||
throw std::invalid_argument ("expected leading '#'");
|
||||
|
||||
if (!util::ascii::is_hex (str[1]) ||
|
||||
!util::ascii::is_hex (str[2]) ||
|
||||
!util::ascii::is_hex (str[3]) ||
|
||||
!util::ascii::is_hex (str[4]) ||
|
||||
!util::ascii::is_hex (str[5]) ||
|
||||
!util::ascii::is_hex (str[6]))
|
||||
if (!cruft::ascii::is_hex (str[1]) ||
|
||||
!cruft::ascii::is_hex (str[2]) ||
|
||||
!cruft::ascii::is_hex (str[3]) ||
|
||||
!cruft::ascii::is_hex (str[4]) ||
|
||||
!cruft::ascii::is_hex (str[5]) ||
|
||||
!cruft::ascii::is_hex (str[6]))
|
||||
{
|
||||
throw std::invalid_argument ("expected hex digits");
|
||||
}
|
||||
|
||||
uint8_t r = util::ascii::from_hex (str[1]) << 4u | util::ascii::from_hex (str[2]);
|
||||
uint8_t g = util::ascii::from_hex (str[3]) << 4u | util::ascii::from_hex (str[4]);
|
||||
uint8_t b = util::ascii::from_hex (str[5]) << 4u | util::ascii::from_hex (str[6]);
|
||||
uint8_t r = cruft::ascii::from_hex (str[1]) << 4u | cruft::ascii::from_hex (str[2]);
|
||||
uint8_t g = cruft::ascii::from_hex (str[3]) << 4u | cruft::ascii::from_hex (str[4]);
|
||||
uint8_t b = cruft::ascii::from_hex (str[5]) << 4u | cruft::ascii::from_hex (str[6]);
|
||||
|
||||
return util::srgba<4,uint8_t> { r, g, b, 255 }.template cast<float> ();
|
||||
return cruft::srgba<4,uint8_t> { r, g, b, 255 }.template cast<float> ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
util::srgba4f
|
||||
util::parse<util::srgba4f> (util::view<const char*> str)
|
||||
cruft::srgba4f
|
||||
cruft::parse<cruft::srgba4f> (cruft::view<const char*> str)
|
||||
{
|
||||
return parse_hex (str);
|
||||
}
|
12
colour.hpp
12
colour.hpp
@ -16,7 +16,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
/// An abstract colour POD type componsed of S components of type T.
|
||||
///
|
||||
/// Not to be used directly, instead the use of derived types is required.
|
||||
@ -33,7 +33,7 @@ namespace util {
|
||||
auto
|
||||
cast (void) const
|
||||
{
|
||||
::util::revalue_t<SelfT,U> ret;
|
||||
::cruft::revalue_t<SelfT,U> ret;
|
||||
std::transform (std::begin (*this),
|
||||
std::end (*this),
|
||||
std::begin (ret),
|
||||
@ -43,21 +43,21 @@ namespace util {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct util::coord::store<1,T,srgba<1,T>> {
|
||||
struct cruft::coord::store<1,T,srgba<1,T>> {
|
||||
union {
|
||||
struct { T r; };
|
||||
T data[1];
|
||||
};
|
||||
};
|
||||
template <typename T>
|
||||
struct util::coord::store<2,T,srgba<2,T>> {
|
||||
struct cruft::coord::store<2,T,srgba<2,T>> {
|
||||
union {
|
||||
struct { T r, g; };
|
||||
T data[2];
|
||||
};
|
||||
};
|
||||
template <typename T>
|
||||
struct util::coord::store<3,T,srgba<3,T>> {
|
||||
struct cruft::coord::store<3,T,srgba<3,T>> {
|
||||
union {
|
||||
struct { T r, g, b; };
|
||||
T data[3];
|
||||
@ -65,7 +65,7 @@ namespace util {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct util::coord::store<4,T,srgba<4,T>> {
|
||||
struct cruft::coord::store<4,T,srgba<4,T>> {
|
||||
union {
|
||||
struct { T r, g, b, a; };
|
||||
T data[4];
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
namespace util::coord {
|
||||
namespace cruft::coord {
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// the base class for all coordinate-like types.
|
||||
//
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
namespace coord {
|
||||
template <size_t S,typename T,typename ParentT> struct store;
|
||||
template <size_t,typename,typename> struct init;
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace util::coord {
|
||||
namespace cruft::coord {
|
||||
template <size_t S, typename T, typename SelfT>
|
||||
struct init;
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <ostream>
|
||||
#include <algorithm>
|
||||
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <
|
||||
typename K,
|
||||
typename = std::enable_if_t<is_coord_v<K>,void>
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
/// returns the data at a templated index in a coordinate.
|
||||
///
|
||||
/// specifically required for structured bindings support.
|
||||
@ -485,7 +485,7 @@ namespace util {
|
||||
return RetT {
|
||||
std::apply (
|
||||
func,
|
||||
::util::tuple::value::map (
|
||||
::cruft::tuple::value::map (
|
||||
static_cast<
|
||||
const value_t& (&)(const part_t&)
|
||||
> (
|
||||
@ -1078,7 +1078,7 @@ namespace util {
|
||||
constexpr auto
|
||||
sum (const K &k)
|
||||
{
|
||||
// DO NOT USE util::sum(begin, end) from maths.hpp
|
||||
// DO NOT USE cruft::sum(begin, end) from maths.hpp
|
||||
//
|
||||
// It would be nice to use kahan summation from maths.hpp but speed
|
||||
// and simplicity is more important for these fixed sized
|
||||
@ -1475,7 +1475,7 @@ namespace std {
|
||||
template <std::size_t,typename> typename K
|
||||
>
|
||||
class tuple_size<K<S,T>> : public std::enable_if_t<
|
||||
::util::is_coord_v<K<S,T>>,
|
||||
::cruft::is_coord_v<K<S,T>>,
|
||||
std::integral_constant<std::size_t, S>
|
||||
> { };
|
||||
|
||||
@ -1495,7 +1495,7 @@ namespace std {
|
||||
template <std::size_t,typename> typename K
|
||||
>
|
||||
class tuple_element<I,K<S,T>> : public std::enable_if<
|
||||
::util::is_coord_v<K<S,T>>,
|
||||
::cruft::is_coord_v<K<S,T>>,
|
||||
T
|
||||
> {};
|
||||
}
|
||||
@ -1513,13 +1513,13 @@ namespace std {
|
||||
template <std::size_t,typename> typename K
|
||||
>
|
||||
struct hash<K<S,T>> : enable_if<
|
||||
::util::is_coord_v<K<S,T>>
|
||||
::cruft::is_coord_v<K<S,T>>
|
||||
> {
|
||||
uint32_t operator() (K<S,T> k) const {
|
||||
uint32_t v = 0xdeadbeef;
|
||||
|
||||
for (T t: k)
|
||||
v = ::util::hash::mix (t, v);
|
||||
v = ::cruft::hash::mix (t, v);
|
||||
|
||||
return v;
|
||||
}
|
||||
@ -1530,12 +1530,12 @@ namespace std {
|
||||
template <
|
||||
typename CoordT,
|
||||
typename = std::enable_if_t<
|
||||
::util::is_coord_v<CoordT>, void
|
||||
::cruft::is_coord_v<CoordT>, void
|
||||
>
|
||||
>
|
||||
auto cos (CoordT val)
|
||||
{
|
||||
return ::util::invoke<CoordT> (::util::cos<typename CoordT::value_type>, val);
|
||||
return ::cruft::invoke<CoordT> (::cruft::cos<typename CoordT::value_type>, val);
|
||||
}
|
||||
|
||||
|
||||
@ -1543,12 +1543,12 @@ namespace std {
|
||||
template <
|
||||
typename CoordT,
|
||||
typename = std::enable_if_t<
|
||||
::util::is_coord_v<CoordT>, void
|
||||
::cruft::is_coord_v<CoordT>, void
|
||||
>
|
||||
>
|
||||
auto sin (CoordT val)
|
||||
{
|
||||
return ::util::invoke<CoordT> (::util::sin<typename CoordT::value_type>, val);
|
||||
return ::cruft::invoke<CoordT> (::cruft::sin<typename CoordT::value_type>, val);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
std::ostream&
|
||||
util::coord::operator<< (std::ostream &os, simd<S,T> val)
|
||||
cruft::coord::operator<< (std::ostream &os, simd<S,T> val)
|
||||
{
|
||||
return os << "[ "
|
||||
<< val[0] << ", "
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include "arm_neon.h"
|
||||
|
||||
namespace util::coord {
|
||||
namespace cruft::coord {
|
||||
struct alignas (16) simd {
|
||||
using value_type = float32x4_t;
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
namespace util::coord {
|
||||
namespace cruft::coord {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
constexpr int alignment = 16;
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Calculate a reasonable alignment for the given type and arity given what we
|
||||
// know about the platform. Only intended to be used with alignas specifiers.
|
||||
namespace util::coord::detail {
|
||||
namespace cruft::coord::detail {
|
||||
template <typename T>
|
||||
constexpr
|
||||
std::size_t
|
||||
@ -45,13 +45,13 @@ namespace util::coord::detail {
|
||||
}
|
||||
}
|
||||
|
||||
#define SIMD_ALIGN(S,T) alignas (util::coord::detail::alignment<T> (S))
|
||||
#define SIMD_ALIGN(S,T) alignas (cruft::coord::detail::alignment<T> (S))
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// defines the named member variables that a coordinate type is composed of
|
||||
#define DEFINE_COORD_STORE(TAG,...) \
|
||||
namespace util::coord { \
|
||||
namespace cruft::coord { \
|
||||
template <typename T> \
|
||||
struct store< \
|
||||
VA_ARGS_COUNT(__VA_ARGS__), \
|
||||
@ -70,10 +70,10 @@ namespace util::coord { \
|
||||
|
||||
#define DEFINE_STORE(KLASS,...) \
|
||||
template <typename T> \
|
||||
struct util::coord::store< \
|
||||
struct cruft::coord::store< \
|
||||
VA_ARGS_COUNT(__VA_ARGS__), \
|
||||
T, \
|
||||
::util::KLASS< \
|
||||
::cruft::KLASS< \
|
||||
VA_ARGS_COUNT(__VA_ARGS__), \
|
||||
T \
|
||||
> \
|
||||
@ -100,7 +100,7 @@ DEFINE_STORE(vector, x, y, z, w)
|
||||
|
||||
#undef DEFINE_STORE
|
||||
|
||||
namespace util::coord {
|
||||
namespace cruft::coord {
|
||||
template <size_t S, typename T, typename SelfT>
|
||||
struct store {
|
||||
T data[S];
|
||||
@ -110,57 +110,57 @@ namespace util::coord {
|
||||
|
||||
#if 0
|
||||
template <typename T>
|
||||
struct util::coord::store<1,T,::util::extent<1,T>> {
|
||||
struct cruft::coord::store<1,T,::cruft::extent<1,T>> {
|
||||
union { T data[1]; struct { T w; }; };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct util::coord::store<2,T,::util::extent<2,T>> {
|
||||
struct cruft::coord::store<2,T,::cruft::extent<2,T>> {
|
||||
union { struct { T w, h; }; T data[2]; };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct util::coord::store<3,T,::util::extent<3,T>> {
|
||||
struct cruft::coord::store<3,T,::cruft::extent<3,T>> {
|
||||
union { struct { T w, h, d; }; T data[3]; };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct util::coord::store<1,T,::util::point<1,T>> {
|
||||
struct cruft::coord::store<1,T,::cruft::point<1,T>> {
|
||||
union { struct { T x; }; T data[1]; };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct util::coord::store<2,T,::util::point<2,T>> {
|
||||
struct cruft::coord::store<2,T,::cruft::point<2,T>> {
|
||||
union { struct { T x, y; }; T data[2]; };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct util::coord::store<3,T,::util::point<3,T>> {
|
||||
struct cruft::coord::store<3,T,::cruft::point<3,T>> {
|
||||
union { struct { T x, y, z; }; T data[3]; };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct util::coord::store<4,T,::util::point<4,T>> {
|
||||
struct cruft::coord::store<4,T,::cruft::point<4,T>> {
|
||||
union { struct { T x, y, z, w; }; T data[4]; };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct util::coord::store<1,T,::util::vector<1,T>> {
|
||||
struct cruft::coord::store<1,T,::cruft::vector<1,T>> {
|
||||
union { struct { T x; }; T data[1]; };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct util::coord::store<2,T,::util::vector<2,T>> {
|
||||
struct cruft::coord::store<2,T,::cruft::vector<2,T>> {
|
||||
union { struct { T x, y; }; T data[2]; };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct util::coord::store<3,T,::util::vector<3,T>> {
|
||||
struct cruft::coord::store<3,T,::cruft::vector<3,T>> {
|
||||
union { struct { T x, y, z; }; T data[3]; };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct util::coord::store<4,T,::util::vector<4,T>> {
|
||||
struct cruft::coord::store<4,T,::cruft::vector<4,T>> {
|
||||
union { struct { T x, y, z, w; }; T data[4]; };
|
||||
};
|
||||
#endif
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// operation traits
|
||||
template <typename, typename>
|
||||
|
32
cpp.cpp
32
cpp.cpp
@ -13,9 +13,9 @@
|
||||
#include "io.hpp"
|
||||
#include "cast.hpp"
|
||||
|
||||
using util::cpp::include;
|
||||
using util::cpp::passthrough;
|
||||
using util::cpp::processor;
|
||||
using cruft::cpp::include;
|
||||
using cruft::cpp::passthrough;
|
||||
using cruft::cpp::processor;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -40,21 +40,21 @@ processor::add (std::string token, std::unique_ptr<directive> handler)
|
||||
void
|
||||
processor::process (std::ostream &os, const std::experimental::filesystem::path &src) const
|
||||
{
|
||||
const auto data = util::slurp<char> (src);
|
||||
const auto data = cruft::slurp<char> (src);
|
||||
context ctx;
|
||||
ctx.source.push (src);
|
||||
|
||||
util::tokeniser<const char*> tok (data, '\n');
|
||||
process (os, ctx, util::view (tok.begin (), tok.end ()));
|
||||
cruft::tokeniser<const char*> tok (data, '\n');
|
||||
process (os, ctx, cruft::view (tok.begin (), tok.end ()));
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
util::tokeniser<const char*>::iterator
|
||||
cruft::tokeniser<const char*>::iterator
|
||||
processor::process (
|
||||
std::ostream &os,
|
||||
context &ctx,
|
||||
util::view<util::tokeniser<const char*>::iterator> lines) const
|
||||
cruft::view<cruft::tokeniser<const char*>::iterator> lines) const
|
||||
{
|
||||
for (auto l = lines.begin (), last = lines.end (); l != last; ++l) {
|
||||
if (l->empty () || (*l)[0] != '#') {
|
||||
@ -62,7 +62,7 @@ processor::process (
|
||||
continue;
|
||||
}
|
||||
|
||||
auto tokens = util::tokeniser (*l, ' ');
|
||||
auto tokens = cruft::tokeniser (*l, ' ');
|
||||
auto head = tokens.begin ();
|
||||
auto head_string = std::string { head->begin () + 1, head->size () - 1 };
|
||||
|
||||
@ -125,10 +125,10 @@ passthrough::passthrough (const std::string &name):
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
util::tokeniser<const char*>::iterator
|
||||
cruft::tokeniser<const char*>::iterator
|
||||
passthrough::process (std::ostream &os,
|
||||
context&,
|
||||
util::view<util::tokeniser<const char*>::iterator> lines) const
|
||||
cruft::view<cruft::tokeniser<const char*>::iterator> lines) const
|
||||
{
|
||||
os << *lines.begin () << '\n';
|
||||
return lines.begin ()++;
|
||||
@ -142,20 +142,20 @@ include::include (processor &_parent):
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
util::tokeniser<const char*>::iterator
|
||||
cruft::tokeniser<const char*>::iterator
|
||||
include::process (std::ostream &os,
|
||||
context &ctx,
|
||||
util::view<util::tokeniser<const char*>::iterator> lines) const
|
||||
cruft::view<cruft::tokeniser<const char*>::iterator> lines) const
|
||||
{
|
||||
const auto name = lines.begin ()->slice (strlen("#include '"), -2);
|
||||
std::experimental::filesystem::path fragment { name.begin (), name.end () };
|
||||
|
||||
const auto target = ctx.source.top ().parent_path () / fragment;
|
||||
const auto data = util::slurp<char> (target);
|
||||
const auto data = cruft::slurp<char> (target);
|
||||
|
||||
ctx.source.push (target);
|
||||
util::tokeniser<const char*> tok (data, '\n');
|
||||
m_parent.process (os, ctx, util::view (tok.begin (), tok.end ()));
|
||||
cruft::tokeniser<const char*> tok (data, '\n');
|
||||
m_parent.process (os, ctx, cruft::view (tok.begin (), tok.end ()));
|
||||
|
||||
ctx.source.pop ();
|
||||
|
||||
|
22
cpp.hpp
22
cpp.hpp
@ -18,7 +18,7 @@
|
||||
#include <stdexcept>
|
||||
#include <stack>
|
||||
|
||||
namespace util::cpp {
|
||||
namespace cruft::cpp {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
struct context {
|
||||
std::stack<std::experimental::filesystem::path> source;
|
||||
@ -39,10 +39,10 @@ namespace util::cpp {
|
||||
///
|
||||
/// \param lines is a tokenised view over all the lines of the input
|
||||
/// \return the next line that processing should continue from
|
||||
virtual util::tokeniser<const char*>::iterator
|
||||
virtual cruft::tokeniser<const char*>::iterator
|
||||
process (std::ostream&,
|
||||
context&,
|
||||
util::view<util::tokeniser<const char*>::iterator> lines) const = 0;
|
||||
cruft::view<cruft::tokeniser<const char*>::iterator> lines) const = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -57,10 +57,10 @@ namespace util::cpp {
|
||||
std::experimental::filesystem::path
|
||||
resolve (const std::experimental::filesystem::path&) const;
|
||||
|
||||
util::tokeniser<const char*>::iterator
|
||||
cruft::tokeniser<const char*>::iterator
|
||||
process (std::ostream&,
|
||||
context&,
|
||||
util::view<util::tokeniser<const char*>::iterator>) const;
|
||||
cruft::view<cruft::tokeniser<const char*>::iterator>) const;
|
||||
|
||||
private:
|
||||
std::map<std::string, std::unique_ptr<directive>> m_directives;
|
||||
@ -79,10 +79,10 @@ namespace util::cpp {
|
||||
/// silently ignores configured directive by advancing the input cursor
|
||||
/// past the provided line without writing to the output stream.
|
||||
class ignore : public directive {
|
||||
util::tokeniser<const char*>::iterator
|
||||
cruft::tokeniser<const char*>::iterator
|
||||
process (std::ostream&,
|
||||
context&,
|
||||
util::view<util::tokeniser<const char*>::iterator> lines) const override
|
||||
cruft::view<cruft::tokeniser<const char*>::iterator> lines) const override
|
||||
{ return lines.begin ()++; }
|
||||
};
|
||||
|
||||
@ -94,10 +94,10 @@ namespace util::cpp {
|
||||
public:
|
||||
passthrough (const std::string &name);
|
||||
|
||||
virtual util::tokeniser<const char*>::iterator
|
||||
virtual cruft::tokeniser<const char*>::iterator
|
||||
process (std::ostream&,
|
||||
context&,
|
||||
util::view<util::tokeniser<const char*>::iterator>) const override;
|
||||
cruft::view<cruft::tokeniser<const char*>::iterator>) const override;
|
||||
|
||||
private:
|
||||
const std::string m_name;
|
||||
@ -113,10 +113,10 @@ namespace util::cpp {
|
||||
|
||||
void add (const std::experimental::filesystem::path&);
|
||||
|
||||
virtual util::tokeniser<const char*>::iterator
|
||||
virtual cruft::tokeniser<const char*>::iterator
|
||||
process (std::ostream&,
|
||||
context&,
|
||||
util::view<util::tokeniser<const char*>::iterator>) const override;
|
||||
cruft::view<cruft::tokeniser<const char*>::iterator>) const override;
|
||||
|
||||
private:
|
||||
processor &m_parent;
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include <iosfwd>
|
||||
|
||||
|
||||
namespace util::cpu {
|
||||
namespace cruft::cpu {
|
||||
struct base {
|
||||
struct {
|
||||
int logical;
|
||||
@ -22,7 +22,7 @@ namespace util::cpu {
|
||||
|
||||
|
||||
std::ostream&
|
||||
operator<< (std::ostream&, const util::cpu::base&);
|
||||
operator<< (std::ostream&, const cruft::cpu::base&);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <cstdint>
|
||||
#include <ostream>
|
||||
|
||||
using util::cpu::x86;
|
||||
using cruft::cpu::x86;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -89,15 +89,15 @@ x86::x86 ()
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
std::ostream&
|
||||
util::cpu::operator<< (std::ostream &os, const x86 &val)
|
||||
cruft::cpu::operator<< (std::ostream &os, const x86 &val)
|
||||
{
|
||||
return os << util::format::printf (
|
||||
return os << cruft::format::printf (
|
||||
"{ name: { vendor: '%!', product: '%!' }"
|
||||
", cores: { logical: %!, physical: %!, hyper_threading: %! }"
|
||||
", simd { sse: %!, sse2: %!, sse3: %!, ssse3: %!, sse41: %!, sse42: %! }"
|
||||
" }",
|
||||
util::view {val.vendor_name},
|
||||
util::view {val.product_name},
|
||||
cruft::view {val.vendor_name},
|
||||
cruft::view {val.product_name},
|
||||
val.cores.logical,
|
||||
val.cores.physical,
|
||||
val.cores.hyper_threading,
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace util::cpu {
|
||||
namespace cruft::cpu {
|
||||
struct x86 {
|
||||
x86 ();
|
||||
|
||||
@ -42,7 +42,7 @@ namespace util::cpu {
|
||||
};
|
||||
|
||||
std::ostream&
|
||||
operator<< (std::ostream&, const util::cpu::x86&);
|
||||
operator<< (std::ostream&, const cruft::cpu::x86&);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
18
debug.cpp
18
debug.cpp
@ -14,12 +14,12 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
using namespace util::debug;
|
||||
using namespace cruft::debug;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
util::debug::detail::panic (const char *msg)
|
||||
cruft::debug::detail::panic (const char *msg)
|
||||
{
|
||||
std::cerr << "PANIC: " << msg << "\n" << ::debug::backtrace () << std::endl;
|
||||
breakpoint ();
|
||||
@ -29,7 +29,7 @@ util::debug::detail::panic (const char *msg)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
util::debug::detail::not_implemented (const char *msg)
|
||||
cruft::debug::detail::not_implemented (const char *msg)
|
||||
{
|
||||
panic (msg);
|
||||
}
|
||||
@ -37,7 +37,7 @@ util::debug::detail::not_implemented (const char *msg)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
util::debug::detail::unreachable (const char *msg)
|
||||
cruft::debug::detail::unreachable (const char *msg)
|
||||
{
|
||||
panic (msg);
|
||||
}
|
||||
@ -69,7 +69,7 @@ warn (const char *msg)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
util::debug::init [[gnu::constructor]] (void)
|
||||
cruft::debug::init [[gnu::constructor]] (void)
|
||||
{
|
||||
if (debug_enabled || getenv("DEBUG")) {
|
||||
LOG_INFO ("minimal debug setup");
|
||||
@ -99,7 +99,7 @@ debug_wait [[gnu::constructor]] (void)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
bool
|
||||
util::debug::validator<float>::is_valid (const float &val) noexcept
|
||||
cruft::debug::validator<float>::is_valid (const float &val) noexcept
|
||||
{
|
||||
return !std::isnan (val);
|
||||
}
|
||||
@ -108,7 +108,7 @@ util::debug::validator<float>::is_valid (const float &val) noexcept
|
||||
//-----------------------------------------------------------------------------
|
||||
template <>
|
||||
bool
|
||||
util::debug::validator<double>::is_valid (const double &val) noexcept
|
||||
cruft::debug::validator<double>::is_valid (const double &val) noexcept
|
||||
{
|
||||
return !std::isnan (val);
|
||||
}
|
||||
@ -121,12 +121,12 @@ util::debug::validator<double>::is_valid (const double &val) noexcept
|
||||
//-----------------------------------------------------------------------------
|
||||
#define INSTANTIATE(KLASS) \
|
||||
template <> \
|
||||
struct util::debug::validator<KLASS> { \
|
||||
struct cruft::debug::validator<KLASS> { \
|
||||
static bool is_valid(KLASS const&); \
|
||||
}; \
|
||||
\
|
||||
bool \
|
||||
util::debug::validator<KLASS>::is_valid(KLASS const&) \
|
||||
cruft::debug::validator<KLASS>::is_valid(KLASS const&) \
|
||||
{ \
|
||||
return true; \
|
||||
}
|
||||
|
34
debug.hpp
34
debug.hpp
@ -120,12 +120,12 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define SCOPED_SANITY(A) \
|
||||
::util::debug::scoped_sanity PASTE(__scoped_sanity_checker,__LINE__) ((A)); \
|
||||
::cruft::debug::scoped_sanity PASTE(__scoped_sanity_checker,__LINE__) ((A)); \
|
||||
(void)PASTE(__scoped_sanity_checker,__LINE__);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define CHECK_SANITY(A,...) CHECK(::util::debug::is_valid ((A) __VA_OPT__(,) __VA_ARGS__))
|
||||
#define CHECK_SANITY(A,...) CHECK(::cruft::debug::is_valid ((A) __VA_OPT__(,) __VA_ARGS__))
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -134,7 +134,7 @@
|
||||
const auto &__a = (A); \
|
||||
const auto &__b = (B); \
|
||||
\
|
||||
if (!::util::almost_equal (__a, __b)) { \
|
||||
if (!::cruft::almost_equal (__a, __b)) { \
|
||||
std::cerr << "expected equality\n" \
|
||||
"__a: " #A " is " << __a << "\n" \
|
||||
"__b: " #B " is " << __b << "\n"; \
|
||||
@ -231,7 +231,7 @@
|
||||
const auto &__a = (A); \
|
||||
const auto &__b = (B); \
|
||||
\
|
||||
if (::util::almost_equal (__a, __b)) { \
|
||||
if (::cruft::almost_equal (__a, __b)) { \
|
||||
std::cerr << "expected inequality\n" \
|
||||
"__a: " << #A << " is " << __a << "\n" \
|
||||
"__b: " << #B << " is " << __b << "\n"; \
|
||||
@ -246,7 +246,7 @@
|
||||
DEBUG_ONLY ( \
|
||||
const auto &__a = (A); \
|
||||
\
|
||||
if (!::util::almost_zero (__a)) { \
|
||||
if (!::cruft::almost_zero (__a)) { \
|
||||
std::cerr << "expected zero\n" \
|
||||
"__a: " << #A << " is " << __a << "\n"; \
|
||||
breakpoint (); \
|
||||
@ -260,7 +260,7 @@
|
||||
DEBUG_ONLY ( \
|
||||
const auto &__a = (A); \
|
||||
\
|
||||
if (::util::exactly_zero (__a)) { \
|
||||
if (::cruft::exactly_zero (__a)) { \
|
||||
std::cerr << "expected non-zero\n" \
|
||||
"__a: " << #A << " is " << __a << '\n'; \
|
||||
breakpoint (); \
|
||||
@ -275,7 +275,7 @@
|
||||
const auto &__check_mod_v = (V); \
|
||||
const auto &__check_mod_m = (M); \
|
||||
\
|
||||
if (!::util::exactly_zero (__check_mod_v % __check_mod_m)) { \
|
||||
if (!::cruft::exactly_zero (__check_mod_v % __check_mod_m)) { \
|
||||
std::cerr << "expected zero modulus\n" \
|
||||
"__v: " << #V << " is " << __check_mod_v << "\n" \
|
||||
"__m: " << #M << " is " << __check_mod_m << "\n"; \
|
||||
@ -360,7 +360,7 @@
|
||||
/// useful for preventing optimisations eliding a variable.
|
||||
///
|
||||
/// stolen from Chandler Carruth's 2015 talk: "Tuning C++".
|
||||
namespace util::debug {
|
||||
namespace cruft::debug {
|
||||
template <class T>
|
||||
inline T*
|
||||
escape (T *t)
|
||||
@ -409,7 +409,7 @@ namespace util::debug {
|
||||
/// force the compiler to conceptually dirty the global memory space.
|
||||
///
|
||||
/// stolen from Chandler Carruth's 2015 talk: "Tuning C++".
|
||||
namespace util::debug {
|
||||
namespace cruft::debug {
|
||||
inline void
|
||||
clobber (void)
|
||||
{
|
||||
@ -422,7 +422,7 @@ void breakpoint (void);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util::debug::detail {
|
||||
namespace cruft::debug::detail {
|
||||
void
|
||||
panic [[noreturn]] (const char *msg);
|
||||
|
||||
@ -440,7 +440,7 @@ panic [[noreturn]] (const char *msg)
|
||||
{
|
||||
! msg
|
||||
? panic (msg)
|
||||
: util::debug::detail::panic (msg);
|
||||
: cruft::debug::detail::panic (msg);
|
||||
}
|
||||
|
||||
|
||||
@ -471,7 +471,7 @@ not_implemented [[noreturn]] (const char *msg)
|
||||
{
|
||||
! msg
|
||||
? not_implemented (msg)
|
||||
: util::debug::detail::not_implemented (msg);
|
||||
: cruft::debug::detail::not_implemented (msg);
|
||||
}
|
||||
|
||||
|
||||
@ -494,7 +494,7 @@ unreachable [[noreturn]] (const char *msg)
|
||||
{
|
||||
! msg
|
||||
? unreachable (msg)
|
||||
: util::debug::detail::unreachable (msg);
|
||||
: cruft::debug::detail::unreachable (msg);
|
||||
}
|
||||
|
||||
|
||||
@ -508,7 +508,7 @@ unreachable [[noreturn]] (void)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/// report a fatal error induced by an unhandled value, especially in switch
|
||||
/// statements. will almost invariably abort the application.
|
||||
namespace util::debug::detail {
|
||||
namespace cruft::debug::detail {
|
||||
template <typename T>
|
||||
void
|
||||
unhandled [[noreturn]] (T &&t) noexcept
|
||||
@ -524,7 +524,7 @@ template <typename T>
|
||||
constexpr void
|
||||
unhandled [[noreturn]] (T &&t) noexcept
|
||||
{
|
||||
util::debug::detail::unhandled (std::forward<T> (t));
|
||||
cruft::debug::detail::unhandled (std::forward<T> (t));
|
||||
}
|
||||
|
||||
|
||||
@ -546,7 +546,7 @@ void disable_fpe (void);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util::debug {
|
||||
namespace cruft::debug {
|
||||
void init (void);
|
||||
|
||||
|
||||
@ -586,7 +586,7 @@ namespace util::debug {
|
||||
struct validator<T*,ArgsT...> {
|
||||
static bool is_valid (const T *val, ArgsT const &...args) noexcept
|
||||
{
|
||||
return val && ::util::debug::is_valid (*val, args...);
|
||||
return val && ::cruft::debug::is_valid (*val, args...);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -65,12 +65,12 @@ class ViewPrinter(object):
|
||||
)
|
||||
|
||||
def build_cruft_dict():
|
||||
pretty_printers_dict[re.compile('^util::point.*$') ] = lambda title, val: CoordPrinter(title, val)
|
||||
pretty_printers_dict[re.compile('^util::vector.*$')] = lambda title, val: CoordPrinter(title, val)
|
||||
pretty_printers_dict[re.compile('^util::extent.*$')] = lambda title, val: CoordPrinter(title, val)
|
||||
pretty_printers_dict[re.compile('^util::colour.*$')] = lambda title, val: CoordPrinter(title, val)
|
||||
pretty_printers_dict[re.compile('^cruft::point.*$') ] = lambda title, val: CoordPrinter(title, val)
|
||||
pretty_printers_dict[re.compile('^cruft::vector.*$')] = lambda title, val: CoordPrinter(title, val)
|
||||
pretty_printers_dict[re.compile('^cruft::extent.*$')] = lambda title, val: CoordPrinter(title, val)
|
||||
pretty_printers_dict[re.compile('^cruft::colour.*$')] = lambda title, val: CoordPrinter(title, val)
|
||||
|
||||
pretty_printers_dict[re.compile('^util::view')] = lambda title, val: ViewPrinter(title, val)
|
||||
pretty_printers_dict[re.compile('^cruft::view')] = lambda title, val: ViewPrinter(title, val)
|
||||
|
||||
|
||||
def lookup(val):
|
||||
|
@ -42,7 +42,7 @@ prepare_debugger (void)
|
||||
{
|
||||
if (nullptr == LoadLibrary("exchndl.dll")) {
|
||||
auto code = GetLastError ();
|
||||
LOG_WARNING("Emergency debugger not loaded: %s", util::win32::error::code_string (code));
|
||||
LOG_WARNING("Emergency debugger not loaded: %s", cruft::win32::error::code_string (code));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include <array>
|
||||
|
||||
|
||||
namespace util::encode {
|
||||
namespace cruft::encode {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <int Size>
|
||||
struct alphabet {
|
||||
@ -137,7 +137,7 @@ namespace util::encode {
|
||||
|
||||
template <typename InputT, typename OutputT>
|
||||
static OutputT
|
||||
encode (OutputT dst, const util::view<InputT> src)
|
||||
encode (OutputT dst, const cruft::view<InputT> src)
|
||||
{
|
||||
// convert whole groups of symbols while we have enough bytes remaining
|
||||
auto cursor = std::cbegin (src);
|
||||
@ -184,7 +184,7 @@ namespace util::encode {
|
||||
//---------------------------------------------------------------------
|
||||
template <typename InputT, typename OutputT>
|
||||
static OutputT
|
||||
decode (OutputT dst, util::view<InputT> src)
|
||||
decode (OutputT dst, cruft::view<InputT> src)
|
||||
{
|
||||
if (src.empty ())
|
||||
return dst;
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
//-------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
constexpr T
|
||||
|
2
exe.hpp
2
exe.hpp
@ -11,7 +11,7 @@
|
||||
|
||||
#include <experimental/filesystem>
|
||||
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
std::experimental::filesystem::path image_path (void);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
std::experimental::filesystem::path
|
||||
util::image_path (void)
|
||||
cruft::image_path (void)
|
||||
{
|
||||
int name[] = {
|
||||
CTL_KERN,
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
std::experimental::filesystem::path
|
||||
util::image_path (void)
|
||||
cruft::image_path (void)
|
||||
{
|
||||
static const char PROC_SELF[] = "/proc/self/exe";
|
||||
|
||||
@ -33,7 +33,7 @@ retry:
|
||||
if (written < 0)
|
||||
posix::error::throw_code ();
|
||||
|
||||
if (util::cast::sign <size_t> (written) == resolved.size ()) {
|
||||
if (cruft::cast::sign <size_t> (written) == resolved.size ()) {
|
||||
resolved.resize (resolved.size () * 2);
|
||||
goto retry;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
std::experimental::filesystem::path
|
||||
util::image_path (void)
|
||||
cruft::image_path (void)
|
||||
{
|
||||
std::vector<char> resolved (256);
|
||||
|
||||
|
14
extent.cpp
14
extent.cpp
@ -14,7 +14,7 @@
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
using util::extent;
|
||||
using cruft::extent;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -35,7 +35,7 @@ extent<S,T>::extent (vector<S,T> _v)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
extent<S,T>
|
||||
extent<S,T>::expanded (util::vector<S,T> mag) const
|
||||
extent<S,T>::expanded (cruft::vector<S,T> mag) const
|
||||
{
|
||||
return *this + mag;
|
||||
}
|
||||
@ -46,7 +46,7 @@ template <size_t S, typename T>
|
||||
extent<S,T>
|
||||
extent<S,T>::expanded (T t) const
|
||||
{
|
||||
return *this + util::vector<S,T> {t};
|
||||
return *this + cruft::vector<S,T> {t};
|
||||
}
|
||||
|
||||
|
||||
@ -78,7 +78,7 @@ extent<S,T>::empty (void) const
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util::debug {
|
||||
namespace cruft::debug {
|
||||
template <size_t S, typename T>
|
||||
struct validator<extent<S,T>> {
|
||||
static bool is_valid (const extent<S,T> &e)
|
||||
@ -93,9 +93,9 @@ namespace util::debug {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#define INSTANTIATE_S_T(S,T) \
|
||||
template struct ::util::extent<S,T>; \
|
||||
template bool ::util::debug::is_valid (const ::util::extent<S,T>&); \
|
||||
template struct ::util::debug::validator<::util::extent<S,T>>;
|
||||
template struct ::cruft::extent<S,T>; \
|
||||
template bool ::cruft::debug::is_valid (const ::cruft::extent<S,T>&); \
|
||||
template struct ::cruft::debug::validator<::cruft::extent<S,T>>;
|
||||
|
||||
#define INSTANTIATE(T) \
|
||||
INSTANTIATE_S_T(1,T) \
|
||||
|
42
extent.hpp
42
extent.hpp
@ -17,17 +17,17 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
/**
|
||||
* A pure n-dimensional size, without positioning
|
||||
*/
|
||||
template <size_t S, typename T>
|
||||
struct extent : public ::util::coord::base<S,T,::util::extent<S,T>>
|
||||
struct extent : public ::cruft::coord::base<S,T,::cruft::extent<S,T>>
|
||||
{
|
||||
using ::util::coord::base<S,T,::util::extent<S,T>>::base;
|
||||
using ::cruft::coord::base<S,T,::cruft::extent<S,T>>::base;
|
||||
|
||||
extent () = default;
|
||||
explicit extent (::util::vector<S,T>);
|
||||
explicit extent (::cruft::vector<S,T>);
|
||||
|
||||
constexpr T
|
||||
area (void) const
|
||||
@ -61,9 +61,9 @@ namespace util {
|
||||
/// tests whether a point would lie within:
|
||||
/// region { origin, *this }, inclusive of borders.
|
||||
///
|
||||
/// included for parity with util::region.
|
||||
/// included for parity with cruft::region.
|
||||
constexpr bool
|
||||
inclusive (util::point<S,T> p) const
|
||||
inclusive (cruft::point<S,T> p) const
|
||||
{
|
||||
return all (p >= T{0} && p <= *this);
|
||||
}
|
||||
@ -71,22 +71,22 @@ namespace util {
|
||||
|
||||
/// tests whether a point would like within:
|
||||
/// region { origin, *this }, exclusive of the bottom-right border
|
||||
/// included for parity with util::region
|
||||
/// included for parity with cruft::region
|
||||
constexpr bool
|
||||
exclusive (point<S,T> p) const
|
||||
{
|
||||
return all (p >= T{0} && p < *this);
|
||||
}
|
||||
|
||||
::util::extent<S,T> expanded (::util::vector<S,T>) const;
|
||||
::util::extent<S,T> expanded (T) const;
|
||||
::util::extent<S,T> contracted (::util::vector<S,T>) const;
|
||||
::util::extent<S,T> contracted (T) const;
|
||||
::cruft::extent<S,T> expanded (::cruft::vector<S,T>) const;
|
||||
::cruft::extent<S,T> expanded (T) const;
|
||||
::cruft::extent<S,T> contracted (::cruft::vector<S,T>) const;
|
||||
::cruft::extent<S,T> contracted (T) const;
|
||||
|
||||
bool empty (void) const;
|
||||
|
||||
static constexpr
|
||||
::util::extent<S,T> max (void)
|
||||
::cruft::extent<S,T> max (void)
|
||||
{
|
||||
return extent<S,T> {
|
||||
std::numeric_limits<T>::max ()
|
||||
@ -95,7 +95,7 @@ namespace util {
|
||||
|
||||
|
||||
static constexpr
|
||||
::util::extent<S,T> min (void)
|
||||
::cruft::extent<S,T> min (void)
|
||||
{
|
||||
return extent<S,T> { 0 };
|
||||
}
|
||||
@ -150,7 +150,7 @@ namespace util {
|
||||
point<S,T> last {0};
|
||||
last[S-1] = this->data[S-1];
|
||||
|
||||
return util::view {
|
||||
return cruft::view {
|
||||
iterator {point<S,T> {0}, *this},
|
||||
iterator {last, *this}
|
||||
};
|
||||
@ -159,20 +159,20 @@ namespace util {
|
||||
|
||||
|
||||
template <size_t S, typename T>
|
||||
util::point<S,T>
|
||||
sample (util::extent<S,T> shape)
|
||||
cruft::point<S,T>
|
||||
sample (cruft::extent<S,T> shape)
|
||||
{
|
||||
return sample (shape, util::random::generator ());
|
||||
return sample (shape, cruft::random::generator ());
|
||||
}
|
||||
|
||||
|
||||
template <size_t S, typename T, typename GeneratorT>
|
||||
util::point<S,T>
|
||||
sample (util::extent<S,T> shape, GeneratorT &&gen)
|
||||
cruft::point<S,T>
|
||||
sample (cruft::extent<S,T> shape, GeneratorT &&gen)
|
||||
{
|
||||
util::point<S,T> p;
|
||||
cruft::point<S,T> p;
|
||||
for (size_t i = 0; i < S; ++i)
|
||||
p[i] = util::random::uniform (0, shape[i], gen);
|
||||
p[i] = cruft::random::uniform (0, shape[i], gen);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
52
fixed.cpp
52
fixed.cpp
@ -12,7 +12,7 @@
|
||||
|
||||
#include <ostream>
|
||||
|
||||
using namespace util;
|
||||
using namespace cruft;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -89,8 +89,8 @@ fixed<T,I,E>::to_integer (native_type n)
|
||||
// Fixed operators
|
||||
#define SIMPLE_FIXED_REF(OP) \
|
||||
template <typename T, unsigned I, unsigned E> \
|
||||
util::fixed<T,I,E>& \
|
||||
util::fixed<T,I,E>::operator OP (const fixed<T,I,E> rhs) \
|
||||
cruft::fixed<T,I,E>& \
|
||||
cruft::fixed<T,I,E>::operator OP (const fixed<T,I,E> rhs) \
|
||||
{ \
|
||||
m_value OP rhs.m_value; \
|
||||
return *this; \
|
||||
@ -102,8 +102,8 @@ SIMPLE_FIXED_REF(+=)
|
||||
|
||||
#define SIMPLE_FIXED_LIT(OP) \
|
||||
template <typename T, unsigned I, unsigned E> \
|
||||
util::fixed<T,I,E> \
|
||||
util::fixed<T,I,E>::operator OP (const fixed<T,I,E> rhs) const \
|
||||
cruft::fixed<T,I,E> \
|
||||
cruft::fixed<T,I,E>::operator OP (const fixed<T,I,E> rhs) const \
|
||||
{ \
|
||||
fixed<T,I,E> v; \
|
||||
v.m_value = m_value OP rhs.m_value; \
|
||||
@ -152,18 +152,18 @@ SIMPLE_INTEGER_LIT(/)
|
||||
#define LOGIC_OP(OP) \
|
||||
template <typename T, unsigned I, unsigned E> \
|
||||
bool \
|
||||
util::operator OP (util::fixed<T,I,E> a, \
|
||||
util::fixed<T,I,E> b) \
|
||||
cruft::operator OP (cruft::fixed<T,I,E> a, \
|
||||
cruft::fixed<T,I,E> b) \
|
||||
{ \
|
||||
return a.to_native () OP b.to_native (); \
|
||||
} \
|
||||
\
|
||||
template <typename T, unsigned I, unsigned E> \
|
||||
bool \
|
||||
util::operator OP (util::fixed<T,I,E> a, \
|
||||
typename util::fixed<T,I,E>::integer_type b) \
|
||||
cruft::operator OP (cruft::fixed<T,I,E> a, \
|
||||
typename cruft::fixed<T,I,E>::integer_type b) \
|
||||
{ \
|
||||
return a OP util::fixed<T,I,E>::from_integer (b); \
|
||||
return a OP cruft::fixed<T,I,E>::from_integer (b); \
|
||||
}
|
||||
|
||||
LOGIC_OP(==)
|
||||
@ -178,7 +178,7 @@ LOGIC_OP(>=)
|
||||
// iostream operators
|
||||
template <typename T, unsigned I, unsigned E>
|
||||
std::ostream&
|
||||
util::operator<< (std::ostream &os, fixed<T,I,E> v)
|
||||
cruft::operator<< (std::ostream &os, fixed<T,I,E> v)
|
||||
{
|
||||
return os << v.to_double ();
|
||||
}
|
||||
@ -188,22 +188,22 @@ util::operator<< (std::ostream &os, fixed<T,I,E> v)
|
||||
// Instantiations
|
||||
|
||||
#define INSTANTIATE(T,I,E) \
|
||||
template class util::fixed<T,I,E>; \
|
||||
template std::ostream& util::operator<< (std::ostream&, fixed<T,I,E>); \
|
||||
template bool util::operator== (util::fixed<T,I,E>, util::fixed<T,I,E>); \
|
||||
template bool util::operator!= (util::fixed<T,I,E>, util::fixed<T,I,E>); \
|
||||
template bool util::operator< (util::fixed<T,I,E>, util::fixed<T,I,E>); \
|
||||
template bool util::operator<= (util::fixed<T,I,E>, util::fixed<T,I,E>); \
|
||||
template bool util::operator> (util::fixed<T,I,E>, util::fixed<T,I,E>); \
|
||||
template bool util::operator>= (util::fixed<T,I,E>, util::fixed<T,I,E>); \
|
||||
template bool util::operator== (util::fixed<T,I,E>, typename util::fixed<T,I,E>::integer_type); \
|
||||
template bool util::operator!= (util::fixed<T,I,E>, typename util::fixed<T,I,E>::integer_type); \
|
||||
template bool util::operator< (util::fixed<T,I,E>, typename util::fixed<T,I,E>::integer_type); \
|
||||
template bool util::operator<= (util::fixed<T,I,E>, typename util::fixed<T,I,E>::integer_type); \
|
||||
template bool util::operator> (util::fixed<T,I,E>, typename util::fixed<T,I,E>::integer_type); \
|
||||
template bool util::operator>= (util::fixed<T,I,E>, typename util::fixed<T,I,E>::integer_type);
|
||||
template class cruft::fixed<T,I,E>; \
|
||||
template std::ostream& cruft::operator<< (std::ostream&, fixed<T,I,E>); \
|
||||
template bool cruft::operator== (cruft::fixed<T,I,E>, cruft::fixed<T,I,E>); \
|
||||
template bool cruft::operator!= (cruft::fixed<T,I,E>, cruft::fixed<T,I,E>); \
|
||||
template bool cruft::operator< (cruft::fixed<T,I,E>, cruft::fixed<T,I,E>); \
|
||||
template bool cruft::operator<= (cruft::fixed<T,I,E>, cruft::fixed<T,I,E>); \
|
||||
template bool cruft::operator> (cruft::fixed<T,I,E>, cruft::fixed<T,I,E>); \
|
||||
template bool cruft::operator>= (cruft::fixed<T,I,E>, cruft::fixed<T,I,E>); \
|
||||
template bool cruft::operator== (cruft::fixed<T,I,E>, typename cruft::fixed<T,I,E>::integer_type); \
|
||||
template bool cruft::operator!= (cruft::fixed<T,I,E>, typename cruft::fixed<T,I,E>::integer_type); \
|
||||
template bool cruft::operator< (cruft::fixed<T,I,E>, typename cruft::fixed<T,I,E>::integer_type); \
|
||||
template bool cruft::operator<= (cruft::fixed<T,I,E>, typename cruft::fixed<T,I,E>::integer_type); \
|
||||
template bool cruft::operator> (cruft::fixed<T,I,E>, typename cruft::fixed<T,I,E>::integer_type); \
|
||||
template bool cruft::operator>= (cruft::fixed<T,I,E>, typename cruft::fixed<T,I,E>::integer_type);
|
||||
|
||||
template class util::fixed<signed,8,8>;
|
||||
template class cruft::fixed<signed,8,8>;
|
||||
|
||||
INSTANTIATE(signed, 2,14)
|
||||
INSTANTIATE(signed,16,16)
|
||||
|
26
fixed.hpp
26
fixed.hpp
@ -15,7 +15,7 @@
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <
|
||||
// whether the type is signed or unsigned. supply an appropriately
|
||||
// signed type here; it won't be used for anything else.
|
||||
@ -96,19 +96,19 @@ namespace util {
|
||||
}
|
||||
|
||||
|
||||
template <typename T, unsigned I, unsigned E> bool operator== (util::fixed<T,I,E>, util::fixed<T,I,E>);
|
||||
template <typename T, unsigned I, unsigned E> bool operator!= (util::fixed<T,I,E>, util::fixed<T,I,E>);
|
||||
template <typename T, unsigned I, unsigned E> bool operator< (util::fixed<T,I,E>, util::fixed<T,I,E>);
|
||||
template <typename T, unsigned I, unsigned E> bool operator<= (util::fixed<T,I,E>, util::fixed<T,I,E>);
|
||||
template <typename T, unsigned I, unsigned E> bool operator> (util::fixed<T,I,E>, util::fixed<T,I,E>);
|
||||
template <typename T, unsigned I, unsigned E> bool operator>= (util::fixed<T,I,E>, util::fixed<T,I,E>);
|
||||
template <typename T, unsigned I, unsigned E> bool operator== (cruft::fixed<T,I,E>, cruft::fixed<T,I,E>);
|
||||
template <typename T, unsigned I, unsigned E> bool operator!= (cruft::fixed<T,I,E>, cruft::fixed<T,I,E>);
|
||||
template <typename T, unsigned I, unsigned E> bool operator< (cruft::fixed<T,I,E>, cruft::fixed<T,I,E>);
|
||||
template <typename T, unsigned I, unsigned E> bool operator<= (cruft::fixed<T,I,E>, cruft::fixed<T,I,E>);
|
||||
template <typename T, unsigned I, unsigned E> bool operator> (cruft::fixed<T,I,E>, cruft::fixed<T,I,E>);
|
||||
template <typename T, unsigned I, unsigned E> bool operator>= (cruft::fixed<T,I,E>, cruft::fixed<T,I,E>);
|
||||
|
||||
template <typename T, unsigned I, unsigned E> bool operator== (util::fixed<T,I,E>, typename util::fixed<T,I,E>::integer_type);
|
||||
template <typename T, unsigned I, unsigned E> bool operator!= (util::fixed<T,I,E>, typename util::fixed<T,I,E>::integer_type);
|
||||
template <typename T, unsigned I, unsigned E> bool operator< (util::fixed<T,I,E>, typename util::fixed<T,I,E>::integer_type);
|
||||
template <typename T, unsigned I, unsigned E> bool operator<= (util::fixed<T,I,E>, typename util::fixed<T,I,E>::integer_type);
|
||||
template <typename T, unsigned I, unsigned E> bool operator> (util::fixed<T,I,E>, typename util::fixed<T,I,E>::integer_type);
|
||||
template <typename T, unsigned I, unsigned E> bool operator>= (util::fixed<T,I,E>, typename util::fixed<T,I,E>::integer_type);
|
||||
template <typename T, unsigned I, unsigned E> bool operator== (cruft::fixed<T,I,E>, typename cruft::fixed<T,I,E>::integer_type);
|
||||
template <typename T, unsigned I, unsigned E> bool operator!= (cruft::fixed<T,I,E>, typename cruft::fixed<T,I,E>::integer_type);
|
||||
template <typename T, unsigned I, unsigned E> bool operator< (cruft::fixed<T,I,E>, typename cruft::fixed<T,I,E>::integer_type);
|
||||
template <typename T, unsigned I, unsigned E> bool operator<= (cruft::fixed<T,I,E>, typename cruft::fixed<T,I,E>::integer_type);
|
||||
template <typename T, unsigned I, unsigned E> bool operator> (cruft::fixed<T,I,E>, typename cruft::fixed<T,I,E>::integer_type);
|
||||
template <typename T, unsigned I, unsigned E> bool operator>= (cruft::fixed<T,I,E>, typename cruft::fixed<T,I,E>::integer_type);
|
||||
|
||||
template <typename T, unsigned I, unsigned E>
|
||||
std::ostream& operator<< (std::ostream&, fixed<T,I,E>);
|
||||
|
@ -107,7 +107,7 @@ ns::is_directory (const path &p)
|
||||
struct stat buf;
|
||||
|
||||
if (stat (p.c_str (), &buf))
|
||||
::util::errno_error::throw_code ();
|
||||
::cruft::errno_error::throw_code ();
|
||||
|
||||
return S_ISDIR (buf.st_mode);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using util::ieee_float;
|
||||
using cruft::ieee_float;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -149,6 +149,6 @@ ieee_float<E, S>::almost_equal (floating_t _a,
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template class util::ieee_float< 5, 10>; // ieee_half
|
||||
template class util::ieee_float< 8, 23>; // ieee_single;
|
||||
template class util::ieee_float<11, 52>; // ieee_double;
|
||||
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;
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
template <unsigned int EXPONENT, unsigned int SIGNIFICAND>
|
||||
class ieee_float
|
||||
{
|
||||
|
@ -14,7 +14,7 @@
|
||||
// disable some noisy warnings (doubly so given -Werror)
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
|
||||
namespace util::format {
|
||||
namespace cruft::format {
|
||||
std::ostream&
|
||||
operator<< (std::ostream &os, type_t val)
|
||||
{
|
||||
@ -138,8 +138,8 @@ namespace util::format {
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
util::format::parsed
|
||||
util::format::printf (util::view<const char*> fmt)
|
||||
cruft::format::parsed
|
||||
cruft::format::printf (cruft::view<const char*> fmt)
|
||||
{
|
||||
std::vector<specifier> specs;
|
||||
specifier s;
|
||||
@ -167,8 +167,8 @@ util::format::printf (util::view<const char*> fmt)
|
||||
///
|
||||
/// in the event of a parsing error the function will throw. makes no
|
||||
/// attempt to cater for constexpr validation.
|
||||
util::format::parsed
|
||||
util::format::python (util::view<const char*> fmt)
|
||||
cruft::format::parsed
|
||||
cruft::format::python (cruft::view<const char*> fmt)
|
||||
{
|
||||
std::vector<specifier> specs;
|
||||
|
||||
|
38
format.hpp
38
format.hpp
@ -19,7 +19,7 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
namespace util::format {
|
||||
namespace cruft::format {
|
||||
/// denotes the stated data type of one specifier
|
||||
enum class type_t {
|
||||
/// an internal type that indicates a span of literal text to copy
|
||||
@ -37,7 +37,7 @@ namespace util::format {
|
||||
REAL,
|
||||
|
||||
/// a C style string, or equivalent C++ type (std::string,
|
||||
/// std::string_view, util::view, etc, ...)
|
||||
/// std::string_view, cruft::view, etc, ...)
|
||||
STRING,
|
||||
/// a single character
|
||||
CHAR,
|
||||
@ -56,7 +56,7 @@ namespace util::format {
|
||||
/// the sub-region of the format specifier that we parsed for this
|
||||
/// information. probably only useful for the LITERAL type as we just
|
||||
/// copy the view into the output buffer directly.
|
||||
util::view<const char*> fmt = util::view<const char*> {nullptr};
|
||||
view<const char*> fmt = view<const char*> {nullptr};
|
||||
|
||||
int parameter = -1;
|
||||
|
||||
@ -125,7 +125,7 @@ namespace util::format {
|
||||
{ ; }
|
||||
|
||||
auto specifiers (void) const
|
||||
{ return util::make_view (m_parsed.m_specifiers); }
|
||||
{ return view (m_parsed.m_specifiers); }
|
||||
|
||||
template <size_t Index>
|
||||
auto
|
||||
@ -149,7 +149,7 @@ namespace util::format {
|
||||
auto
|
||||
specifiers (void) const&
|
||||
{
|
||||
return util::view {m_specifiers};
|
||||
return view {m_specifiers};
|
||||
}
|
||||
|
||||
template <size_t Index>
|
||||
@ -181,7 +181,7 @@ namespace util::format {
|
||||
/// if the format specifier is invalid the function will throw an error at
|
||||
/// runtime. specifically does not make allowances for constexpr
|
||||
/// validation.
|
||||
parsed printf (util::view<const char*>);
|
||||
parsed printf (view<const char*>);
|
||||
|
||||
|
||||
/// parses a format specifier in the style of PEP3101 (with the notable
|
||||
@ -189,13 +189,13 @@ namespace util::format {
|
||||
///
|
||||
/// in the event of a parsing error the function will throw. makes no
|
||||
/// attempt to cater for constexpr validation.
|
||||
parsed python (util::view<const char*>);
|
||||
parsed python (view<const char*>);
|
||||
|
||||
|
||||
/// parses a printf format string and binds parameters for rendering.
|
||||
template <typename ...Args>
|
||||
auto
|
||||
printf (util::view<const char*> fmt, Args &&...args)
|
||||
printf (view<const char*> fmt, Args &&...args)
|
||||
{
|
||||
return printf (fmt) (args...);
|
||||
}
|
||||
@ -204,7 +204,7 @@ namespace util::format {
|
||||
/// parses a python format string and binds parameters for rendering.
|
||||
template <typename ...Args>
|
||||
auto
|
||||
python (util::view<const char*> fmt, Args &&...args)
|
||||
python (view<const char*> fmt, Args &&...args)
|
||||
{
|
||||
return python (fmt) (args...);
|
||||
}
|
||||
@ -234,7 +234,7 @@ namespace util::format {
|
||||
break;
|
||||
|
||||
case type_t::STRING:
|
||||
if (!std::is_same_v<ValueT, util::view<const char*>> && !std::is_same_v<ValueT, std::string>)
|
||||
if (!std::is_same_v<ValueT, view<const char*>> && !std::is_same_v<ValueT, std::string>)
|
||||
throw std::runtime_error ("expected string value");
|
||||
break;
|
||||
|
||||
@ -348,11 +348,11 @@ namespace util::format {
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (std::is_same_v<util::view<const char*>, ValueT>) {
|
||||
if constexpr (std::is_same_v<view<const char*>, ValueT>) {
|
||||
if (spec.precision >= 0) {
|
||||
std::copy_n (
|
||||
std::begin (val),
|
||||
util::min (spec.precision, static_cast<int> (val.size ())),
|
||||
min (spec.precision, static_cast<int> (val.size ())),
|
||||
std::ostream_iterator<char> (os)
|
||||
);
|
||||
return os;
|
||||
@ -416,7 +416,7 @@ namespace util::format {
|
||||
static std::ostream&
|
||||
write (std::ostream &os, specifier spec, const char (&val)[N]) {
|
||||
if (spec.type == type_t::STRING || spec.type == type_t::USER)
|
||||
return value<util::view<const char*>>::write (os, spec, util::view<const char*> (val));
|
||||
return value<view<const char*>>::write (os, spec, view<const char*> (val));
|
||||
throw std::runtime_error ("invalid data type");
|
||||
}
|
||||
};
|
||||
@ -426,7 +426,7 @@ namespace util::format {
|
||||
struct value<char[N]> {
|
||||
static std::ostream&
|
||||
write (std::ostream &os, specifier spec, const char (&val)[N]) {
|
||||
return value<util::view<const char*>>::write (os, spec, util::view<const char*> (val));
|
||||
return value<view<const char*>>::write (os, spec, view<const char*> (val));
|
||||
}
|
||||
};
|
||||
|
||||
@ -438,7 +438,7 @@ namespace util::format {
|
||||
if (!val)
|
||||
return os << "(nil)";
|
||||
if (spec.type == type_t::STRING || spec.type == type_t::USER)
|
||||
return value<util::view<const char*>>::write (os, spec, util::view<const char*> { val, val + strlen (val) });
|
||||
return value<view<const char*>>::write (os, spec, view<const char*> { val, val + strlen (val) });
|
||||
if (spec.type == type_t::POINTER)
|
||||
return value<const void*>::write (os, spec, val);
|
||||
throw std::runtime_error ("invalid data type");
|
||||
@ -453,7 +453,7 @@ namespace util::format {
|
||||
if (!val)
|
||||
return os << "(nil)";
|
||||
if (spec.type == type_t::STRING || spec.type == type_t::USER)
|
||||
return value<util::view<const char*>>::write (os, spec, util::view<const char*> { val, val + strlen (val) });
|
||||
return value<view<const char*>>::write (os, spec, view<const char*> { val, val + strlen (val) });
|
||||
if (spec.type == type_t::POINTER)
|
||||
return value<const void*>::write (os, spec, val);
|
||||
throw std::runtime_error ("invalid data type");
|
||||
@ -465,8 +465,8 @@ namespace util::format {
|
||||
struct value<const std::string&> {
|
||||
static std::ostream&
|
||||
write (std::ostream &os, specifier spec, const std::string &val) {
|
||||
return value<util::view<const char*>>::write (
|
||||
os, spec, util::view<const char*> (val.data (), val.data () + val.size ())
|
||||
return value<view<const char*>>::write (
|
||||
os, spec, view<const char*> (val.data (), val.data () + val.size ())
|
||||
);
|
||||
}
|
||||
};
|
||||
@ -511,7 +511,7 @@ namespace util::format {
|
||||
if constexpr (Index < sizeof... (DataT)) {
|
||||
using value_t = std::tuple_element_t<Index,std::tuple<DataT...>>;
|
||||
value<value_t>::write (os, s, data.template get<Index> ());
|
||||
return write<Index+1> (os, util::make_view (cursor+1,specifiers.end ()), data);
|
||||
return write<Index+1> (os, make_view (cursor+1,specifiers.end ()), data);
|
||||
} else {
|
||||
throw std::runtime_error ("insufficient data parameters");
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include <ostream>
|
||||
|
||||
using util::fourcc;
|
||||
using cruft::fourcc;
|
||||
|
||||
static_assert (sizeof(fourcc) == 4, "fourcc must be a 4 byte POD");
|
||||
|
||||
@ -64,7 +64,7 @@ fourcc::operator uint32_t (void) const {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
std::ostream&
|
||||
util::operator<< (std::ostream &os, fourcc f) {
|
||||
cruft::operator<< (std::ostream &os, fourcc f) {
|
||||
os << f.data[0] << f.data[1] << f.data[2] << f.data[3];
|
||||
return os;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include <iosfwd>
|
||||
#include <cstdint>
|
||||
|
||||
namespace util {
|
||||
namespace cruft {
|
||||
struct fourcc {
|
||||
uint8_t data[4];
|
||||
|
||||
@ -23,7 +23,7 @@ namespace util {
|
||||
operator uint32_t (void) const;
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream&, util::fourcc);
|
||||
std::ostream& operator<< (std::ostream&, cruft::fourcc);
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace util::functor {
|
||||
namespace cruft::functor {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// returns the value provided at construction time regardless of the
|
||||
/// arguments supplied in the call operator.
|
||||
|
@ -13,13 +13,13 @@
|
||||
#include "../coord/iostream.hpp"
|
||||
#include "../debug.hpp"
|
||||
|
||||
using util::geom::aabb;
|
||||
using cruft::geom::aabb;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
std::array<
|
||||
util::point3f,8
|
||||
cruft::point3f,8
|
||||
>
|
||||
aabb<3,float>::vertices (void) const noexcept
|
||||
{
|
||||
@ -37,7 +37,7 @@ aabb<3,float>::vertices (void) const noexcept
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util::debug {
|
||||
namespace cruft::debug {
|
||||
template <size_t S, typename T>
|
||||
struct validator<aabb<S,T>> {
|
||||
static bool is_valid (const aabb<S,T> &b)
|
||||
@ -51,7 +51,7 @@ namespace util::debug {
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t S, typename T>
|
||||
std::ostream&
|
||||
util::geom::operator<< (std::ostream &os, util::geom::aabb<S,T> b)
|
||||
cruft::geom::operator<< (std::ostream &os, cruft::geom::aabb<S,T> b)
|
||||
{
|
||||
return os << "[ " << b.lo << ", " << b.hi << " ]";
|
||||
}
|
||||
@ -59,9 +59,9 @@ util::geom::operator<< (std::ostream &os, util::geom::aabb<S,T> b)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#define INSTANTIATE_S_T(S,T) \
|
||||
namespace util::geom { template struct aabb<S,T>; } \
|
||||
template bool util::debug::is_valid (const aabb<S,T>&); \
|
||||
template std::ostream& util::geom::operator<< (std::ostream&, aabb<S,T>);
|
||||
namespace cruft::geom { template struct aabb<S,T>; } \
|
||||
template bool cruft::debug::is_valid (const aabb<S,T>&); \
|
||||
template std::ostream& cruft::geom::operator<< (std::ostream&, aabb<S,T>);
|
||||
|
||||
#define INSTANTIATE(T) \
|
||||
INSTANTIATE_S_T(2,T) \
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// represents an axis-aligned bounding-box through two opposing corners.
|
||||
///
|
||||
@ -37,7 +37,7 @@ namespace util::geom {
|
||||
extent<S,T>
|
||||
magnitude (void) const
|
||||
{
|
||||
return (hi - lo).template as<util::extent> ();
|
||||
return (hi - lo).template as<cruft::extent> ();
|
||||
}
|
||||
|
||||
|
||||
@ -90,8 +90,8 @@ namespace util::geom {
|
||||
auto operator| [[nodiscard]] (point<S,T> p) const noexcept
|
||||
{
|
||||
return aabb (
|
||||
util::min (lo, p),
|
||||
util::max (hi, p)
|
||||
cruft::min (lo, p),
|
||||
cruft::max (hi, p)
|
||||
);
|
||||
}
|
||||
|
||||
@ -109,12 +109,12 @@ namespace util::geom {
|
||||
};
|
||||
}
|
||||
|
||||
std::array<util::point<S,T>,util::pow(2,S)>
|
||||
std::array<cruft::point<S,T>,cruft::pow(2,S)>
|
||||
vertices (void) const noexcept;
|
||||
|
||||
|
||||
::util::point<S,T> lo;
|
||||
::util::point<S,T> hi;
|
||||
::cruft::point<S,T> lo;
|
||||
::cruft::point<S,T> hi;
|
||||
};
|
||||
|
||||
|
||||
@ -143,7 +143,7 @@ namespace util::geom {
|
||||
|
||||
#include <random>
|
||||
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
template <size_t S, typename T, typename G>
|
||||
struct sampler<S,T,aabb,G> {
|
||||
static point<S,T>
|
||||
@ -154,7 +154,7 @@ namespace util::geom {
|
||||
point<S,T> p;
|
||||
std::generate (p.begin (), p.end (), [&] (void) { return d (g); });
|
||||
|
||||
return p * (b.hi - b.lo) + b.lo.template as<util::vector> ();
|
||||
return p * (b.hi - b.lo) + b.lo.template as<cruft::vector> ();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -8,13 +8,13 @@
|
||||
|
||||
#include "cylinder.hpp"
|
||||
|
||||
using util::geom::cylinder;
|
||||
using cruft::geom::cylinder;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
bool
|
||||
cylinder<S,T>::includes (util::point<S,T> p_) const
|
||||
cylinder<S,T>::includes (cruft::point<S,T> p_) const
|
||||
{
|
||||
auto p10 = p1 - p0;
|
||||
auto p_0 = p_ - p0;
|
||||
@ -32,5 +32,5 @@ cylinder<S,T>::includes (util::point<S,T> p_) const
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template struct util::geom::cylinder<2,float>;
|
||||
template struct util::geom::cylinder<3,float>;
|
||||
template struct cruft::geom::cylinder<2,float>;
|
||||
template struct cruft::geom::cylinder<3,float>;
|
||||
|
@ -12,14 +12,14 @@
|
||||
#include "../point.hpp"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
template <size_t S, typename T>
|
||||
struct cylinder {
|
||||
util::point<S,T> p0, p1;
|
||||
cruft::point<S,T> p0, p1;
|
||||
T radius;
|
||||
|
||||
float distance (util::point<S,T>) const;
|
||||
bool includes (util::point<S,T>) const;
|
||||
float distance (cruft::point<S,T>) const;
|
||||
bool includes (cruft::point<S,T>) const;
|
||||
};
|
||||
|
||||
using cylinder3f = cylinder<3,float>;
|
||||
|
@ -18,16 +18,16 @@
|
||||
#include "../matrix.hpp"
|
||||
#include "../coord/iostream.hpp"
|
||||
|
||||
using util::geom::ellipse;
|
||||
using cruft::geom::ellipse;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
bool
|
||||
util::geom::intersects (ellipse3f e, util::point3f p)
|
||||
cruft::geom::intersects (ellipse3f e, cruft::point3f p)
|
||||
{
|
||||
auto transform = util::quaternionf::from_to (e.up, {0,1,0}).as_matrix () *
|
||||
util::translation (0-e.origin);
|
||||
auto transform = cruft::quaternionf::from_to (e.up, {0,1,0}).as_matrix () *
|
||||
cruft::translation (0-e.origin);
|
||||
|
||||
return all (abs (transform * p) <= e.radius);
|
||||
|
||||
@ -41,13 +41,13 @@ util::geom::intersects (ellipse3f e, util::point3f p)
|
||||
// a sphere
|
||||
template <>
|
||||
float
|
||||
util::geom::distance (ray3f r, ellipse3f e)
|
||||
cruft::geom::distance (ray3f r, ellipse3f e)
|
||||
{
|
||||
// find a transform that puts the ellipse at origin and scales it to a
|
||||
// unit sphere.
|
||||
auto const from_scaled = util::translation (e.origin.template as<vector> ()) *
|
||||
util::quaternionf::from_to ({0,1,0}, e.up) *
|
||||
util::scale (e.radius);
|
||||
auto const from_scaled = cruft::translation (e.origin.template as<vector> ()) *
|
||||
cruft::quaternionf::from_to ({0,1,0}, e.up) *
|
||||
cruft::scale (e.radius);
|
||||
auto const to_scaled = inverse (from_scaled);
|
||||
|
||||
// transform the ray into this new space and query against a unit sphere
|
||||
@ -62,17 +62,17 @@ util::geom::distance (ray3f r, ellipse3f e)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
util::point3f
|
||||
util::geom::project (util::geom::ray3f lhs,
|
||||
util::geom::ellipse3f rhs)
|
||||
cruft::point3f
|
||||
cruft::geom::project (cruft::geom::ray3f lhs,
|
||||
cruft::geom::ellipse3f rhs)
|
||||
{
|
||||
return lhs.origin + lhs.direction * distance (lhs, rhs);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
util::geom::ellipse3f
|
||||
util::geom::cover (util::view<const point3f*> src)
|
||||
cruft::geom::ellipse3f
|
||||
cruft::geom::cover (cruft::view<const point3f*> src)
|
||||
{
|
||||
// find our major axis points and vector
|
||||
const auto [a,b] = furthest (src);
|
||||
@ -81,11 +81,11 @@ util::geom::cover (util::view<const point3f*> src)
|
||||
auto const dir = normalised (diff);
|
||||
|
||||
// find a transform such that we recentre about the origin
|
||||
auto const transform = quaternionf::from_to (dir, util::vector3f{1,0,0}).as_matrix () *
|
||||
auto const transform = quaternionf::from_to (dir, cruft::vector3f{1,0,0}).as_matrix () *
|
||||
translation (0 -a -diff*0.5f);
|
||||
|
||||
// find the maximum absolute value in each axis
|
||||
util::point3f hi {0};
|
||||
cruft::point3f hi {0};
|
||||
|
||||
for (auto const& p: src)
|
||||
hi = max (abs (transform * p), hi);
|
||||
@ -93,14 +93,14 @@ util::geom::cover (util::view<const point3f*> src)
|
||||
return ellipse3f {
|
||||
.origin = a + diff * 0.5f,
|
||||
.radius = hi.as<vector> (),
|
||||
.up = rotate ({0,1,0}, util::quaternionf::from_to ({1,0,0}, dir))
|
||||
.up = rotate ({0,1,0}, cruft::quaternionf::from_to ({1,0,0}, dir))
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
static util::geom::aabb<S,T>
|
||||
static cruft::geom::aabb<S,T>
|
||||
bounds (ellipse<S,T> e)
|
||||
{
|
||||
return {
|
||||
@ -112,8 +112,8 @@ bounds (ellipse<S,T> e)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t S, typename T, template <size_t,typename> class K>
|
||||
util::geom::aabb<S,T>
|
||||
util::geom::bounds (K<S,T> k)
|
||||
cruft::geom::aabb<S,T>
|
||||
cruft::geom::bounds (K<S,T> k)
|
||||
{
|
||||
return ::bounds (k);
|
||||
}
|
||||
@ -122,7 +122,7 @@ util::geom::bounds (K<S,T> k)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
std::ostream&
|
||||
util::geom::operator<< (std::ostream &os, ellipse<S,T> val)
|
||||
cruft::geom::operator<< (std::ostream &os, ellipse<S,T> val)
|
||||
{
|
||||
return os << "{ origin: " << val.origin
|
||||
<< ", radius: " << val.radius
|
||||
@ -133,11 +133,11 @@ util::geom::operator<< (std::ostream &os, ellipse<S,T> val)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INSTANTIATE_S_T(S,T) \
|
||||
template util::geom::aabb<S,T> util::geom::bounds (ellipse<S,T>); \
|
||||
template std::ostream& util::geom::operator<< (std::ostream&, ellipse<S,T>);
|
||||
template cruft::geom::aabb<S,T> cruft::geom::bounds (ellipse<S,T>); \
|
||||
template std::ostream& cruft::geom::operator<< (std::ostream&, ellipse<S,T>);
|
||||
|
||||
//template util::point<S,T> util::geom::project(ray<S,T>, ellipse<S,T>);
|
||||
//template bool util::geom::intersects (ellipse<S,T>, util::point<S,T>);
|
||||
//template cruft::point<S,T> cruft::geom::project(ray<S,T>, ellipse<S,T>);
|
||||
//template bool cruft::geom::intersects (ellipse<S,T>, cruft::point<S,T>);
|
||||
|
||||
INSTANTIATE_S_T(2,float)
|
||||
INSTANTIATE_S_T(3,float)
|
||||
|
@ -20,18 +20,18 @@
|
||||
#include <iosfwd>
|
||||
|
||||
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename ValueT>
|
||||
struct ellipse {
|
||||
// the centre point of the ellipsoid
|
||||
util::point<S,ValueT> origin;
|
||||
cruft::point<S,ValueT> origin;
|
||||
|
||||
// the distance from the centre along each axis to the shape's edge
|
||||
util::vector<S,ValueT> radius;
|
||||
cruft::vector<S,ValueT> radius;
|
||||
|
||||
// the orientation of up for the shape
|
||||
util::vector<S,ValueT> up;
|
||||
cruft::vector<S,ValueT> up;
|
||||
};
|
||||
|
||||
using ellipse2f = ellipse<2,float>;
|
||||
@ -99,7 +99,7 @@ namespace util::geom {
|
||||
// this isn't guaranteed to be optimal in any specific sense. but it
|
||||
// ought not be outrageously inefficient...
|
||||
ellipse3f
|
||||
cover (util::view<const point3f*>);
|
||||
cover (cruft::view<const point3f*>);
|
||||
|
||||
|
||||
/// returns a point that is uniformly distributed about the ellipse
|
||||
@ -112,7 +112,7 @@ namespace util::geom {
|
||||
///
|
||||
/// the concept was taken from: https://math.stackexchange.com/a/2514182
|
||||
template <typename RandomT>
|
||||
util::point3f
|
||||
cruft::point3f
|
||||
sample_surface (ellipse3f self, RandomT &generator)
|
||||
{
|
||||
const auto [a, b, c] = self.radius;
|
||||
@ -128,7 +128,7 @@ namespace util::geom {
|
||||
// find the distance to the surface along the direction vector
|
||||
auto const d = std::sqrt (x * x / a2 + y * y / b2 + z * z / c2);
|
||||
|
||||
return self.origin + util::vector3f {x,y,z} / d;
|
||||
return self.origin + cruft::vector3f {x,y,z} / d;
|
||||
}
|
||||
|
||||
|
||||
@ -144,21 +144,21 @@ namespace util::geom {
|
||||
#include <cmath>
|
||||
#include <random>
|
||||
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
template <typename T, template <size_t,typename> class K, typename G>
|
||||
struct sampler<2,T,K,G>
|
||||
{
|
||||
static util::point<2,T> fn (K<2,T> k, G &g)
|
||||
static cruft::point<2,T> fn (K<2,T> k, G &g)
|
||||
{
|
||||
std::uniform_real_distribution<T> dist;
|
||||
|
||||
float phi = dist (g) * 2 * pi<T>;
|
||||
float rho = std::sqrt (dist (g));
|
||||
|
||||
return util::point<2,T> {
|
||||
return cruft::point<2,T> {
|
||||
std::cos (phi),
|
||||
std::sin (phi)
|
||||
} * rho * k.radius + k.origin.template as<util::vector> ();
|
||||
} * rho * k.radius + k.origin.template as<cruft::vector> ();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include "frustum.hpp"
|
||||
|
||||
using util::geom::frustum;
|
||||
using cruft::geom::frustum;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -57,4 +57,4 @@ frustum<T>::frustum (const matrix4<T> &transform)
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template struct util::geom::frustum<float>;
|
||||
template struct cruft::geom::frustum<float>;
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
/// a viewing frustrum comprised of 4 axis planes, a near plane, and a far
|
||||
/// plane. it may describe something other than a perspective projection
|
||||
/// (eg, an orthographic projection)
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
template <size_t S, typename T> struct ray;
|
||||
template <size_t S, typename T> struct plane;
|
||||
template <size_t S, typename T> struct aabb;
|
||||
|
@ -17,39 +17,39 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
std::ostream&
|
||||
util::geom::operator<< (std::ostream &os, util::geom::sphere<S,T> s)
|
||||
cruft::geom::operator<< (std::ostream &os, cruft::geom::sphere<S,T> s)
|
||||
{
|
||||
return os << "sphere(" << s.centre << ',' << s.radius << ')';
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template std::ostream& util::geom::operator<< (std::ostream&, util::geom::sphere<2,float>);
|
||||
template std::ostream& util::geom::operator<< (std::ostream&, util::geom::sphere<3,float>);
|
||||
template std::ostream& cruft::geom::operator<< (std::ostream&, cruft::geom::sphere<2,float>);
|
||||
template std::ostream& cruft::geom::operator<< (std::ostream&, cruft::geom::sphere<3,float>);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
std::ostream&
|
||||
util::geom::operator<< (std::ostream &os, plane<S,T> val)
|
||||
cruft::geom::operator<< (std::ostream &os, plane<S,T> val)
|
||||
{
|
||||
return os << val.coefficients;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template std::ostream& util::geom::operator<< (std::ostream&, plane<2,float>);
|
||||
template std::ostream& util::geom::operator<< (std::ostream&, plane<3,float>);
|
||||
template std::ostream& cruft::geom::operator<< (std::ostream&, plane<2,float>);
|
||||
template std::ostream& cruft::geom::operator<< (std::ostream&, plane<3,float>);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
std::ostream&
|
||||
util::geom::operator<< (std::ostream &os, frustum<T> val)
|
||||
cruft::geom::operator<< (std::ostream &os, frustum<T> val)
|
||||
{
|
||||
return os << "[ " << util::make_infix (val.planes) << " ]";
|
||||
return os << "[ " << cruft::make_infix (val.planes) << " ]";
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template std::ostream& util::geom::operator<< (std::ostream&, frustum<float>);
|
||||
template std::ostream& cruft::geom::operator<< (std::ostream&, frustum<float>);
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
template <size_t S, typename T>
|
||||
std::ostream&
|
||||
operator<< (std::ostream&, aabb<S,T>);
|
||||
|
@ -11,26 +11,26 @@
|
||||
#include "../point.hpp"
|
||||
#include "../vector.hpp"
|
||||
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
// an line of infinite extent that passes though 'base'.
|
||||
//
|
||||
// direction should be normalised
|
||||
template <size_t S, typename T>
|
||||
struct line {
|
||||
line () = default;
|
||||
line (util::point<S,T> a, util::point<S,T> b):
|
||||
line (cruft::point<S,T> a, cruft::point<S,T> b):
|
||||
line (a, normalised (b - a))
|
||||
{ ; }
|
||||
|
||||
line (util::point<S,T> _base, util::vector<S,T> _direction):
|
||||
line (cruft::point<S,T> _base, cruft::vector<S,T> _direction):
|
||||
base (_base),
|
||||
direction (_direction)
|
||||
{
|
||||
CHECK (is_normalised (direction));
|
||||
}
|
||||
|
||||
util::point<S,T> base;
|
||||
util::vector<S,T> direction;
|
||||
cruft::point<S,T> base;
|
||||
cruft::vector<S,T> direction;
|
||||
};
|
||||
|
||||
using line2f = line<2,float>;
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
template <
|
||||
size_t S,
|
||||
typename T,
|
||||
@ -43,8 +43,8 @@ namespace util::geom {
|
||||
template <size_t,typename> class A,
|
||||
template <size_t,typename> class B,
|
||||
typename = std::enable_if_t<
|
||||
!std::is_same_v<util::point<S,T>, A> &&
|
||||
!std::is_same_v<util::point<S,T>, B>
|
||||
!std::is_same_v<cruft::point<S,T>, A> &&
|
||||
!std::is_same_v<cruft::point<S,T>, B>
|
||||
>
|
||||
>
|
||||
T
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include "../debug.hpp"
|
||||
|
||||
using util::geom::plane;
|
||||
using cruft::geom::plane;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -26,5 +26,5 @@ plane<S,T>::plane (point<S,T> base, vector<S,T> normal)
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template struct util::geom::plane<2,float>;
|
||||
template struct util::geom::plane<3,float>;
|
||||
template struct cruft::geom::plane<2,float>;
|
||||
template struct cruft::geom::plane<3,float>;
|
||||
|
@ -12,18 +12,18 @@
|
||||
#include "../vector.hpp"
|
||||
#include "../matrix.hpp"
|
||||
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
/// represents an S dimensional plane in parametric form: ax + by + cz + d = 0
|
||||
template <size_t S, typename T>
|
||||
struct plane {
|
||||
plane () = default;
|
||||
plane (util::point<S,T> base, util::vector<S,T> normal);
|
||||
plane (cruft::point<S,T> base, cruft::vector<S,T> normal);
|
||||
|
||||
explicit plane (util::vector<S+1,T> _coefficients):
|
||||
explicit plane (cruft::vector<S+1,T> _coefficients):
|
||||
coefficients (_coefficients)
|
||||
{ ; }
|
||||
|
||||
util::vector<S+1,T> coefficients;
|
||||
cruft::vector<S+1,T> coefficients;
|
||||
};
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ namespace util::geom {
|
||||
typedef plane<3,float> plane3f;
|
||||
|
||||
inline plane3f
|
||||
make_plane (util::point3f a, util::point3f b, util::point3f c)
|
||||
make_plane (cruft::point3f a, cruft::point3f b, cruft::point3f c)
|
||||
{
|
||||
return plane3f (a, normalised (cross (b - a, c - a)));
|
||||
}
|
||||
@ -40,7 +40,7 @@ namespace util::geom {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// returns the normal for a plane
|
||||
template <size_t S, typename T>
|
||||
util::vector<S,T>
|
||||
cruft::vector<S,T>
|
||||
normal (plane<S,T> p)
|
||||
{
|
||||
return p.coefficients.template redim<S> ();
|
||||
@ -106,7 +106,7 @@ namespace util::geom {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
auto
|
||||
furthest (plane<S,T> p, const std::vector<util::point<S,T>> &cloud)
|
||||
furthest (plane<S,T> p, const std::vector<cruft::point<S,T>> &cloud)
|
||||
{
|
||||
T maxd = -INFINITY;
|
||||
auto best = cloud.begin ();
|
||||
@ -123,5 +123,5 @@ namespace util::geom {
|
||||
|
||||
template <size_t S, typename T>
|
||||
auto
|
||||
furthest (plane<S,T>, std::vector<util::point<S,T>> &&) = delete;
|
||||
furthest (plane<S,T>, std::vector<cruft::point<S,T>> &&) = delete;
|
||||
}
|
||||
|
18
geom/ray.cpp
18
geom/ray.cpp
@ -13,7 +13,7 @@
|
||||
#include "../coord/iostream.hpp"
|
||||
#include "../debug.hpp"
|
||||
|
||||
using util::geom::ray;
|
||||
using cruft::geom::ray;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -29,7 +29,7 @@ ray<S,T>::closest (point<S,T> q) const
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t S, typename T>
|
||||
util::point<S,T>
|
||||
cruft::point<S,T>
|
||||
ray<S,T>::at (T t) const
|
||||
{
|
||||
return origin + direction * t;
|
||||
@ -39,7 +39,7 @@ ray<S,T>::at (T t) const
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
std::ostream&
|
||||
util::geom::operator<< (std::ostream &os, ray<S,T> r)
|
||||
cruft::geom::operator<< (std::ostream &os, ray<S,T> r)
|
||||
{
|
||||
return os << "ray(" << r.origin << ',' << r.direction << ')';
|
||||
}
|
||||
@ -47,12 +47,12 @@ util::geom::operator<< (std::ostream &os, ray<S,T> r)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
struct util::debug::validator<ray<S,T>> {
|
||||
struct cruft::debug::validator<ray<S,T>> {
|
||||
static bool
|
||||
is_valid (ray<S,T> const& val)
|
||||
{
|
||||
return util::debug::is_valid (val.origin) &&
|
||||
util::debug::is_valid (val.direction) &&
|
||||
return cruft::debug::is_valid (val.origin) &&
|
||||
cruft::debug::is_valid (val.direction) &&
|
||||
is_normalised (val.direction);
|
||||
}
|
||||
};
|
||||
@ -60,9 +60,9 @@ struct util::debug::validator<ray<S,T>> {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INSTANTIATE_S_T(S,T) \
|
||||
template std::ostream& util::geom::operator<< (std::ostream&, ray<S,T>); \
|
||||
template struct util::debug::validator<ray<S,T>>; \
|
||||
template struct util::geom::ray<S,T>;
|
||||
template std::ostream& cruft::geom::operator<< (std::ostream&, ray<S,T>); \
|
||||
template struct cruft::debug::validator<ray<S,T>>; \
|
||||
template struct cruft::geom::ray<S,T>;
|
||||
|
||||
|
||||
INSTANTIATE_S_T(2,float)
|
||||
|
@ -18,13 +18,13 @@
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
template <size_t S, typename T>
|
||||
struct ray {
|
||||
// queries
|
||||
T closest (point<S,T>) const;
|
||||
|
||||
util::point<S,T> at (T) const;
|
||||
cruft::point<S,T> at (T) const;
|
||||
|
||||
// data members
|
||||
point<S,T> origin;
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include <random>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
/// a function object that selects a uniformly random point inside a shape
|
||||
/// using a provided random generator. the point will lie within the shape,
|
||||
/// inclusive of boundaries.
|
||||
@ -68,8 +68,8 @@ namespace util::geom {
|
||||
}
|
||||
|
||||
|
||||
std::vector<util::point2f>
|
||||
poisson_sample (util::extent2i, float distance, int samples);
|
||||
std::vector<cruft::point2f>
|
||||
poisson_sample (cruft::extent2i, float distance, int samples);
|
||||
|
||||
|
||||
namespace surface {
|
||||
@ -83,17 +83,17 @@ namespace util::geom {
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
template <size_t S, typename T>
|
||||
class sampler<util::extent<S,T>> {
|
||||
class sampler<cruft::extent<S,T>> {
|
||||
public:
|
||||
sampler (util::extent<S,T> _target):
|
||||
sampler (cruft::extent<S,T> _target):
|
||||
target (_target)
|
||||
{ ; }
|
||||
|
||||
template <typename GeneratorT>
|
||||
util::point<S,T>
|
||||
cruft::point<S,T>
|
||||
operator() (GeneratorT &&gen) const noexcept
|
||||
{
|
||||
util::point<S,T> p;
|
||||
cruft::point<S,T> p;
|
||||
|
||||
for (size_t i = 0; i < S; ++i) {
|
||||
if constexpr (std::is_floating_point_v<T>) {
|
||||
@ -108,7 +108,7 @@ namespace util::geom {
|
||||
}
|
||||
|
||||
private:
|
||||
util::extent<S,T> target;
|
||||
cruft::extent<S,T> target;
|
||||
};
|
||||
|
||||
/// approximate a poisson disc sampling through mitchell's best candidate.
|
||||
@ -161,10 +161,10 @@ namespace util::geom {
|
||||
// find the minimum distance from this candidate to the
|
||||
// selected points
|
||||
for (auto q: selected)
|
||||
d2 = util::min (d2, util::distance2 (p, q));
|
||||
d2 = cruft::min (d2, cruft::distance2 (p, q));
|
||||
|
||||
// record if it's the furthest away
|
||||
if (d2 > best_distance2 && d2 > util::pow (minimum_distance (p), 2)) {
|
||||
if (d2 > best_distance2 && d2 > cruft::pow (minimum_distance (p), 2)) {
|
||||
best_distance2 = d2;
|
||||
best_index = i;
|
||||
}
|
||||
|
@ -11,11 +11,11 @@
|
||||
#include "../point.hpp"
|
||||
|
||||
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
template <size_t S, typename T>
|
||||
struct segment {
|
||||
util::point<S,T> a;
|
||||
util::point<S,T> b;
|
||||
cruft::point<S,T> a;
|
||||
cruft::point<S,T> b;
|
||||
};
|
||||
|
||||
|
||||
|
@ -8,5 +8,5 @@
|
||||
|
||||
#include "sphere.hpp"
|
||||
|
||||
using util::geom::sphere;
|
||||
using cruft::geom::sphere;
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
template <size_t S, typename T>
|
||||
struct sphere {
|
||||
point<S,T> centre;
|
||||
|
16
geom/tri.hpp
16
geom/tri.hpp
@ -15,7 +15,7 @@
|
||||
#include <cstddef>
|
||||
#include <random>
|
||||
|
||||
namespace util::geom {
|
||||
namespace cruft::geom {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
struct tri {
|
||||
@ -24,7 +24,7 @@ namespace util::geom {
|
||||
a (_a), b (_b), c (_c)
|
||||
{ ; }
|
||||
|
||||
util::point<S,T> a, b, c;
|
||||
cruft::point<S,T> a, b, c;
|
||||
};
|
||||
|
||||
template <size_t S, typename T>
|
||||
@ -44,7 +44,7 @@ namespace util::geom {
|
||||
{ ; }
|
||||
|
||||
template <typename GeneratorT>
|
||||
util::point<S,T>
|
||||
cruft::point<S,T>
|
||||
operator() (GeneratorT &&gen) const noexcept
|
||||
{
|
||||
std::uniform_real_distribution<float> dist (0, 1);
|
||||
@ -52,8 +52,8 @@ namespace util::geom {
|
||||
}
|
||||
|
||||
private:
|
||||
util::point<S,T> base;
|
||||
util::vector<S,T> v0, v1;
|
||||
cruft::point<S,T> base;
|
||||
cruft::vector<S,T> v0, v1;
|
||||
};
|
||||
};
|
||||
|
||||
@ -65,9 +65,9 @@ namespace util::geom {
|
||||
area (tri<DimensionV,ValueT> obj)
|
||||
{
|
||||
// heron's formula
|
||||
const auto ab = util::distance (obj.a, obj.b);
|
||||
const auto bc = util::distance (obj.b, obj.c);
|
||||
const auto ca = util::distance (obj.c, obj.a);
|
||||
const auto ab = cruft::distance (obj.a, obj.b);
|
||||
const auto bc = cruft::distance (obj.b, obj.c);
|
||||
const auto ca = cruft::distance (obj.c, obj.a);
|
||||
|
||||
const auto s = (ab + bc + ca) / 2;
|
||||
|
||||
|
2
hash.hpp
2
hash.hpp
@ -14,7 +14,7 @@
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace util::hash {
|
||||
namespace cruft::hash {
|
||||
constexpr std::uint32_t
|
||||
mix (std::uint32_t a, std::uint32_t b)
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
static constexpr unsigned MODULUS = 65521;
|
||||
|
||||
using util::hash::adler32;
|
||||
using cruft::hash::adler32;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user