EdgeShapeConf.hpp
Go to the documentation of this file.
1 /*
2  * Original work Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
3  * Modified work Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/PlayRho
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  * 1. The origin of this software must not be misrepresented; you must not
12  * claim that you wrote the original software. If you use this software
13  * in a product, an acknowledgment in the product documentation would be
14  * appreciated but is not required.
15  * 2. Altered source versions must be plainly marked as such, and must not be
16  * misrepresented as being the original software.
17  * 3. This notice may not be removed or altered from any source distribution.
18  */
19 
20 #ifndef PLAYRHO_COLLISION_SHAPES_EDGESHAPECONF_HPP
21 #define PLAYRHO_COLLISION_SHAPES_EDGESHAPECONF_HPP
22 
23 #include <PlayRho/Common/Math.hpp>
27 
28 namespace playrho {
29 namespace d2 {
30 
41 class EdgeShapeConf: public ShapeBuilder<EdgeShapeConf>
42 {
43 public:
46  {
48  }
49 
51  static inline EdgeShapeConf GetDefaultConf() noexcept
52  {
53  return EdgeShapeConf{};
54  }
55 
56  EdgeShapeConf() = default;
57 
59  EdgeShapeConf(Length2 vA, Length2 vB, const EdgeShapeConf& conf = GetDefaultConf()) noexcept;
60 
62  EdgeShapeConf& Set(Length2 vA, Length2 vB) noexcept;
63 
66 
69  EdgeShapeConf& Transform(const Mat22& m) noexcept;
70 
72  Length2 GetVertexA() const noexcept
73  {
74  return m_vertices[0];
75  }
76 
78  Length2 GetVertexB() const noexcept
79  {
80  return m_vertices[1];
81  }
82 
84  DistanceProxy GetChild() const noexcept
85  {
86  return DistanceProxy{vertexRadius, 2, m_vertices, m_normals};
87  }
88 
101 
102 private:
103  Length2 m_vertices[2] = {Length2{}, Length2{}};
104  UnitVec m_normals[2] = {UnitVec{}, UnitVec{}};
105 };
106 
108 {
109  vertexRadius = value;
110  return *this;
111 }
112 
113 // Free functions...
114 
116 inline bool operator== (const EdgeShapeConf& lhs, const EdgeShapeConf& rhs) noexcept
117 {
118  return lhs.vertexRadius == rhs.vertexRadius && lhs.friction == rhs.friction
119  && lhs.restitution == rhs.restitution && lhs.density == rhs.density
120  && lhs.GetVertexA() == rhs.GetVertexA() && lhs.GetVertexB() == rhs.GetVertexB();
121 }
122 
124 inline bool operator!= (const EdgeShapeConf& lhs, const EdgeShapeConf& rhs) noexcept
125 {
126  return !(lhs == rhs);
127 }
128 
132 {
133  return 1;
134 }
135 
138 {
139  if (index != 0)
140  {
141  throw InvalidArgument("only index of 0 is supported");
142  }
143  return arg.GetChild();
144 }
145 
148 {
149  return arg.vertexRadius;
150 }
151 
154 {
155  return GetVertexRadius(arg);
156 }
157 
159 inline MassData GetMassData(const EdgeShapeConf& arg) noexcept
160 {
161  return playrho::d2::GetMassData(arg.vertexRadius, arg.density,
162  arg.GetVertexA(), arg.GetVertexB());
163 }
164 
167 inline void Transform(EdgeShapeConf& arg, const Mat22& m) noexcept
168 {
169  arg.Transform(m);
170 }
171 
172 } // namespace d2
173 } // namespace playrho
174 
175 #endif // PLAYRHO_COLLISION_SHAPES_EDGESHAPECONF_HPP