change multishape test transform behavior

multishape
Evan Hemsley 2020-01-05 13:35:49 -08:00
parent 38f5180a45
commit 17084154a2
2 changed files with 8 additions and 8 deletions

View File

@ -70,9 +70,9 @@ namespace MoonTools.Core.Bonk
/// <returns></returns> /// <returns></returns>
public static bool TestCollision(MultiShape multiShape, Transform2D multiShapeTransform, IShape2D shape, Transform2D shapeTransform) public static bool TestCollision(MultiShape multiShape, Transform2D multiShapeTransform, IShape2D shape, Transform2D shapeTransform)
{ {
foreach (var (otherShape, otherTransform) in multiShape.ShapeTransformPairs) foreach (var (otherShape, otherTransform) in multiShape.TransformedShapeTransforms(multiShapeTransform))
{ {
if (TestCollision(shape, shapeTransform, otherShape, multiShapeTransform.Compose(otherTransform))) { return true; } if (TestCollision(shape, shapeTransform, otherShape, otherTransform)) { return true; }
} }
return false; return false;
} }
@ -88,9 +88,9 @@ namespace MoonTools.Core.Bonk
/// <returns></returns> /// <returns></returns>
public static bool TestCollision(IShape2D shape, Transform2D shapeTransform, MultiShape multiShape, Transform2D multiShapeTransform) public static bool TestCollision(IShape2D shape, Transform2D shapeTransform, MultiShape multiShape, Transform2D multiShapeTransform)
{ {
foreach (var (otherShape, otherTransform) in multiShape.ShapeTransformPairs) foreach (var (otherShape, otherTransform) in multiShape.TransformedShapeTransforms(multiShapeTransform))
{ {
if (TestCollision(shape, shapeTransform, otherShape, multiShapeTransform.Compose(otherTransform))) { return true; } if (TestCollision(shape, shapeTransform, otherShape, otherTransform)) { return true; }
} }
return false; return false;
} }
@ -106,11 +106,11 @@ namespace MoonTools.Core.Bonk
/// <returns></returns> /// <returns></returns>
public static bool TestCollision(MultiShape multiShapeA, Transform2D transformA, MultiShape multiShapeB, Transform2D transformB) public static bool TestCollision(MultiShape multiShapeA, Transform2D transformA, MultiShape multiShapeB, Transform2D transformB)
{ {
foreach (var (shapeA, shapeTransformA) in multiShapeA.ShapeTransformPairs) foreach (var (shapeA, shapeTransformA) in multiShapeA.TransformedShapeTransforms(transformA))
{ {
foreach (var (shapeB, shapeTransformB) in multiShapeB.ShapeTransformPairs) foreach (var (shapeB, shapeTransformB) in multiShapeB.TransformedShapeTransforms(transformB))
{ {
if (TestCollision(shapeA, transformA.Compose(shapeTransformA), shapeB, transformB.Compose(shapeTransformB))) { return true; } if (TestCollision(shapeA, shapeTransformA, shapeB, shapeTransformB)) { return true; }
} }
} }
return false; return false;

View File

@ -418,7 +418,7 @@ namespace Tests
var transformA = new Transform2D(new Position2D(0, 0)); var transformA = new Transform2D(new Position2D(0, 0));
var rectangleB = new Rectangle(2, 2); var rectangleB = new Rectangle(2, 2);
var transformB = new Transform2D(new Vector2(1, 0)); var transformB = new Transform2D(new Vector2(1, 0), 0, new Vector2(-1, 1));
NarrowPhase.TestRectangleOverlap(rectangleA, transformA, rectangleB, transformB).Should().BeTrue(); NarrowPhase.TestRectangleOverlap(rectangleA, transformA, rectangleB, transformB).Should().BeTrue();
} }