DiskShapeConf.hpp
Go to the documentation of this file.
1 /*
2  * Original work Copyright (c) 2006-2009 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_DISKSHAPECONF_HPP
21 #define PLAYRHO_COLLISION_SHAPES_DISKSHAPECONF_HPP
22 
23 #include <PlayRho/Common/Math.hpp>
27 
28 namespace playrho {
29 namespace d2 {
30 
41 struct DiskShapeConf: ShapeBuilder<DiskShapeConf>
42 {
45  {
47  }
48 
49  PLAYRHO_CONSTEXPR DiskShapeConf() = default;
50 
53  {
54  // Intentionally empty.
55  }
56 
59  {
60  location = value;
61  return *this;
62  }
63 
66  {
67  vertexRadius = r;
68  return *this;
69  }
70 
73  PLAYRHO_CONSTEXPR inline DiskShapeConf& Transform(const Mat22& m) noexcept
74  {
75  location = m * location;
76  return *this;
77  }
78 
80  NonNegative<Length> GetRadius() const noexcept
81  {
82  return vertexRadius;
83  }
84 
86  Length2 GetLocation() const noexcept
87  {
88  return location;
89  }
90 
103 
106 };
107 
108 // Free functions...
109 
111 inline bool operator== (const DiskShapeConf& lhs, const DiskShapeConf& rhs) noexcept
112 {
113  return lhs.vertexRadius == rhs.vertexRadius && lhs.friction == rhs.friction
114  && lhs.restitution == rhs.restitution && lhs.density == rhs.density
115  && lhs.location == rhs.location;
116 }
117 
119 inline bool operator!= (const DiskShapeConf& lhs, const DiskShapeConf& rhs) noexcept
120 {
121  return !(lhs == rhs);
122 }
123 
126 {
127  return 1;
128 }
129 
132 {
133  if (index != 0)
134  {
135  throw InvalidArgument("only index of 0 is supported");
136  }
137  return DistanceProxy{arg.vertexRadius, 1, &arg.location, nullptr};
138 }
139 
142 {
143  return arg.vertexRadius;
144 }
145 
148  ChildCounter) noexcept
149 {
150  return GetVertexRadius(arg);
151 }
152 
154 inline MassData GetMassData(const DiskShapeConf& arg) noexcept
155 {
156  return playrho::d2::GetMassData(arg.vertexRadius, arg.density, arg.location);
157 }
158 
162 inline void Transform(DiskShapeConf& arg, const Mat22& m) noexcept
163 {
164  arg.Transform(m);
165 }
166 
167 } // namespace d2
168 } // namespace playrho
169 
170 #endif // PLAYRHO_COLLISION_SHAPES_DISKSHAPECONF_HPP