2222
2323inline namespace Math
2424{
25-
2625 // -=(Undocumented)=-
2726 template <typename Base>
2827 static constexpr Bool Intersects (ConstRef<Math::Circle<Base>> Circle, ConstRef<Math::Circle<Base>> Other, Ptr<Math::Manifold<Base>> Manifold)
@@ -39,7 +38,7 @@ inline namespace Math
3938 Core::Clamp (Center.GetX (), Rectangle.GetLeft (), Rectangle.GetRight ()),
4039 Core::Clamp (Center.GetY (), Rectangle.GetTop (), Rectangle.GetBottom ()));
4140
42- const Vector2<Base> Delta = Center - Closest ;
41+ const Vector2<Base> Delta = Closest - Center ;
4342 const Base SqDistance = Delta.GetLengthSquared ();
4443 const Base SqRadius = Circle.GetRadius () * Circle.GetRadius ();
4544
@@ -99,7 +98,13 @@ inline namespace Math
9998 template <typename Base>
10099 static constexpr Bool Intersects (ConstRef<Math::Rect<Base>> Rectangle, ConstRef<Math::Circle<Base>> Circle, Ptr<Math::Manifold<Base>> Manifold)
101100 {
102- return Intersects<Base>(Circle, Rectangle, Manifold);
101+ const Bool Result = Intersects<Base>(Circle, Rectangle, Manifold);
102+
103+ if (Result && Manifold)
104+ {
105+ Manifold->SetNormal (-Manifold->GetNormal ());
106+ }
107+ return Result;
103108 }
104109
105110 // -=(Undocumented)=-
@@ -192,7 +197,7 @@ inline namespace Math
192197 Normal = Vector2<Base>::Normalize (Rectangle.GetCenter () - Contact);
193198 }
194199
195- Manifold->SetPenetration (Delta. GetLength () * ( T1 - T0));
200+ Manifold->SetPenetration (( T1 - T0) * Delta. Dot (Normal ));
196201 Manifold->SetNormal (Normal);
197202 Manifold->AddPoint (Contact);
198203 }
@@ -212,13 +217,25 @@ inline namespace Math
212217 template <typename Base>
213218 static constexpr Bool Intersects (ConstRef<Math::Edge<Base>> Edge, ConstRef<Math::Circle<Base>> Circle, Ptr<Math::Manifold<Base>> Manifold)
214219 {
215- return Intersects<Base>(Circle, Edge, Manifold);
220+ const Bool Result = Intersects<Base>(Circle, Edge, Manifold);
221+
222+ if (Result && Manifold)
223+ {
224+ Manifold->SetNormal (-Manifold->GetNormal ());
225+ }
226+ return Result;
216227 }
217228
218229 // -=(Undocumented)=-
219230 template <typename Base>
220231 static constexpr Bool Intersects (ConstRef<Math::Edge<Base>> Edge, ConstRef<Math::Rect<Base>> Rectangle, Ptr<Math::Manifold<Base>> Manifold)
221232 {
222- return Intersects<Base>(Rectangle, Edge, Manifold);
233+ const Bool Result = Intersects<Base>(Rectangle, Edge, Manifold);
234+
235+ if (Result && Manifold)
236+ {
237+ Manifold->SetNormal (-Manifold->GetNormal ());
238+ }
239+ return Result;
223240 }
224241}
0 commit comments