1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3  *
4  * Copyright (c) 2018 Kohei Yoshida
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following
13  * conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  ************************************************************************/
28 
29 #ifndef INCLUDED_MDDS_TEST_GLOBAL_RTREE_HPP
30 #define INCLUDED_MDDS_TEST_GLOBAL_RTREE_HPP
31 
32 #define MDDS_RTREE_DEBUG 1
33 #include <mdds/rtree.hpp>
34 #include <fstream>
35 
36 struct tiny_trait_1d
37 {
38     constexpr static size_t dimensions = 1;
39     constexpr static size_t min_node_size = 2;
40     constexpr static size_t max_node_size = 5;
41     constexpr static size_t max_tree_depth = 100;
42 
43     constexpr static bool enable_forced_reinsertion = false;
44     constexpr static size_t reinsertion_size = 2;
45 };
46 
47 struct tiny_trait_2d
48 {
49     constexpr static size_t dimensions = 2;
50     constexpr static size_t min_node_size = 2;
51     constexpr static size_t max_node_size = 5;
52     constexpr static size_t max_tree_depth = 100;
53 
54     constexpr static bool enable_forced_reinsertion = false;
55     constexpr static size_t reinsertion_size = 2;
56 };
57 
58 struct tiny_trait_2d_forced_reinsertion
59 {
60     constexpr static size_t dimensions = 2;
61     constexpr static size_t min_node_size = 2;
62     constexpr static size_t max_node_size = 5;
63     constexpr static size_t max_tree_depth = 100;
64 
65     constexpr static bool enable_forced_reinsertion = true;
66     constexpr static size_t reinsertion_size = 2;
67 };
68 
69 class only_movable
70 {
71     double m_value;
72 public:
only_movable()73     only_movable() : m_value(0.0) {}
only_movable(double v)74     only_movable(double v) : m_value(v) {}
75     only_movable(const only_movable&) = delete;
only_movable(only_movable && other)76     only_movable(only_movable&& other) : m_value(other.m_value)
77     {
78         other.m_value = 0.0;
79     }
80 
get() const81     double get() const { return m_value; }
82 };
83 
84 class only_copyable
85 {
86     double m_value;
87 public:
only_copyable()88     only_copyable() : m_value(0.0) {}
only_copyable(double v)89     only_copyable(double v) : m_value(v) {}
only_copyable(const only_copyable & other)90     only_copyable(const only_copyable& other) : m_value(other.m_value) {}
91 
92     only_copyable(only_copyable&&) = delete;
93 
set(double v)94     void set(double v) { m_value = v; }
get() const95     double get() const { return m_value; }
96 };
97 
98 template<typename T>
export_tree(const T & tree,const std::string & basename)99 void export_tree(const T& tree, const std::string& basename)
100 {
101     {
102         std::ofstream fout(basename + ".obj");
103         fout << tree.export_tree(T::export_tree_type::extent_as_obj);
104     }
105 
106     {
107         std::ofstream fout(basename + ".svg");
108         fout << tree.export_tree(T::export_tree_type::extent_as_svg);
109     }
110 }
111 
112 #endif
113 
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
115 
116