Math/TriangulationFigures.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011-2015 Jan Haller
00005 // 
00006 // This software is provided 'as-is', without any express or implied
00007 // warranty. In no event will the authors be held liable for any damages
00008 // arising from the use of this software.
00009 // 
00010 // Permission is granted to anyone to use this software for any purpose,
00011 // including commercial applications, and to alter it and redistribute it
00012 // freely, subject to the following restrictions:
00013 // 
00014 // 1. The origin of this software must not be misrepresented; you must not
00015 //    claim that you wrote the original software. If you use this software
00016 //    in a product, an acknowledgment in the product documentation would be
00017 //    appreciated but is not required.
00018 // 
00019 // 2. Altered source versions must be plainly marked as such, and must not be
00020 //    misrepresented as being the original software.
00021 // 
00022 // 3. This notice may not be removed or altered from any source distribution.
00023 //
00025 
00028 
00029 #ifndef THOR_TRIANGULATIONFIGURES_HPP
00030 #define THOR_TRIANGULATIONFIGURES_HPP
00031 
00032 #include <Thor/Config.hpp>
00033 
00034 #include <SFML/System/Vector2.hpp>
00035 #include <SFML/System/NonCopyable.hpp>
00036 
00037 #include <array>
00038 #include <cassert>
00039 
00040 
00041 namespace thor
00042 {
00043 
00046 
00050 template <typename V>
00051 class Edge
00052 {
00053     // ---------------------------------------------------------------------------------------------------------------------------
00054     // Public member functions
00055     public:
00058                                     Edge(V& corner0, V& corner1);
00059 
00063         V&                          operator[] (std::size_t cornerIndex);
00064 
00068         const V&                    operator[] (std::size_t cornerIndex) const;
00069 
00070 
00071     // ---------------------------------------------------------------------------------------------------------------------------
00072     // Protected variables
00073     protected:
00074         std::array<V*, 2>           mCorners;
00075 };
00076 
00077 
00082 template <typename V>
00083 class Triangle
00084 {
00085     // ---------------------------------------------------------------------------------------------------------------------------
00086     // Public member functions
00087     public:
00091                                     Triangle(V& corner0, V& corner1, V& corner2);
00092 
00096         V&                          operator[] (std::size_t cornerIndex);
00097 
00101         const V&                    operator[] (std::size_t cornerIndex) const;
00102 
00103 
00104     // ---------------------------------------------------------------------------------------------------------------------------
00105     // Private variables
00106     private:
00107         std::array<V*, 3>           mCorners;
00108 };
00109 
00110 
00119 template <typename V>
00120 struct TriangulationTraits
00121 {
00122     static sf::Vector2f getPosition(const V& vertex)
00123     {
00124         return vertex.getPosition();
00125     }
00126 };
00127 
00128 // Triangulation traits: Specialization for sf::Vector2f
00129 template <>
00130 struct TriangulationTraits<sf::Vector2f>
00131 {
00132     static sf::Vector2f getPosition(sf::Vector2f vertex)
00133     {
00134         return vertex;
00135     }
00136 };
00137 
00139 
00140 } // namespace thor
00141 
00142 #include <Thor/Math/Detail/TriangulationFigures.inl>
00143 #endif // THOR_TRIANGULATIONFIGURES_HPP