TriangulationFigures.hpp
Go to the documentation of this file.
1 //
3 // Thor C++ Library
4 // Copyright (c) 2011-2016 Jan Haller
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would be
17 // appreciated but is not required.
18 //
19 // 2. Altered source versions must be plainly marked as such, and must not be
20 // misrepresented as being the original software.
21 //
22 // 3. This notice may not be removed or altered from any source distribution.
23 //
25 
28 
29 #ifndef THOR_TRIANGULATIONFIGURES_HPP
30 #define THOR_TRIANGULATIONFIGURES_HPP
31 
32 #include <Thor/Config.hpp>
33 
34 #include <SFML/System/Vector2.hpp>
35 #include <SFML/System/NonCopyable.hpp>
36 
37 #include <array>
38 #include <cassert>
39 
40 
41 namespace thor
42 {
43 
46 
50 template <typename V>
51 class Edge
52 {
53  // ---------------------------------------------------------------------------------------------------------------------------
54  // Public member functions
55  public:
58  Edge(V& corner0, V& corner1);
59 
63  V& operator[] (std::size_t cornerIndex);
64 
68  const V& operator[] (std::size_t cornerIndex) const;
69 
70 
71  // ---------------------------------------------------------------------------------------------------------------------------
72  // Protected variables
73  protected:
74  std::array<V*, 2> mCorners;
75 };
76 
77 
82 template <typename V>
83 class Triangle
84 {
85  // ---------------------------------------------------------------------------------------------------------------------------
86  // Public member functions
87  public:
91  Triangle(V& corner0, V& corner1, V& corner2);
92 
96  V& operator[] (std::size_t cornerIndex);
97 
101  const V& operator[] (std::size_t cornerIndex) const;
102 
103 
104  // ---------------------------------------------------------------------------------------------------------------------------
105  // Private variables
106  private:
107  std::array<V*, 3> mCorners;
108 };
109 
110 
119 template <typename V>
121 {
122  static sf::Vector2f getPosition(const V& vertex)
123  {
124  return vertex.getPosition();
125  }
126 };
127 
128 // Triangulation traits: Specialization for sf::Vector2f
129 template <>
130 struct TriangulationTraits<sf::Vector2f>
131 {
132  static sf::Vector2f getPosition(sf::Vector2f vertex)
133  {
134  return vertex;
135  }
136 };
137 
139 
140 } // namespace thor
141 
142 #include <Thor/Math/Detail/TriangulationFigures.inl>
143 #endif // THOR_TRIANGULATIONFIGURES_HPP
V & operator[](std::size_t cornerIndex)
Accesses a corner of the edge.
Definition: AnimationMap.hpp:42
Configuration header of the library.
V & operator[](std::size_t cornerIndex)
Accesses a corner of the triangle.
Triangle(V &corner0, V &corner1, V &corner2)
Triangle constructor.
Edge that contains two vertices (its endpoints or corners)
Definition: TriangulationFigures.hpp:51
Edge(V &corner0, V &corner1)
Edge constructor
Traits template to implement the Vertex concept.
Definition: TriangulationFigures.hpp:120
Definition: BigSprite.hpp:41
Triangle class consisting of 3 vertices (its corners).
Definition: TriangulationFigures.hpp:83