Shape.cpp
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  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 
23 
24 namespace playrho {
25 namespace d2 {
26 namespace {
27 
28 struct DefaultShapeConf
29 {
30 };
31 
32 ChildCounter GetChildCount(const DefaultShapeConf&) noexcept
33 {
34  return 0;
35 }
36 
37 DistanceProxy GetChild(const DefaultShapeConf&, ChildCounter)
38 {
39  throw InvalidArgument("index out of range");
40 }
41 
42 MassData GetMassData(const DefaultShapeConf&) noexcept
43 {
44  return MassData{};
45 }
46 
47 Real GetFriction(const DefaultShapeConf&) noexcept
48 {
49  return Real{0};
50 }
51 
52 Real GetRestitution(const DefaultShapeConf&) noexcept
53 {
54  return Real{0};
55 }
56 
57 void Transform(DefaultShapeConf&, const Mat22&) noexcept
58 {
59  // Intentionally empty.
60 }
61 
62 NonNegative<AreaDensity> GetDensity(const DefaultShapeConf&) noexcept
63 {
64  return NonNegative<AreaDensity>{0_kgpm2};
65 }
66 
67 NonNegative<Length> GetVertexRadius(const DefaultShapeConf&, ChildCounter)
68 {
69  throw InvalidArgument("index out of range");
70 }
71 
72 constexpr bool operator== (const DefaultShapeConf&, const DefaultShapeConf&) noexcept
73 {
74  return true;
75 }
76 
77 } // annonymous namespace
78 
79 Shape::Shape(): m_self{std::make_shared<Model<DefaultShapeConf>>(DefaultShapeConf{})}
80 {
81  // Intentionally empty.
82 }
83 
84 bool TestPoint(const Shape& shape, Length2 point) noexcept
85 {
86  const auto childCount = GetChildCount(shape);
87  for (auto i = decltype(childCount){0}; i < childCount; ++i)
88  {
89  if (playrho::d2::TestPoint(GetChild(shape, i), point))
90  {
91  return true;
92  }
93  }
94  return false;
95 }
96 
97 } // namespace d2
98 } // namespace playrho