diff --git a/govector_test.go b/govector_test.go index 08bd84d..b7b9008 100644 --- a/govector_test.go +++ b/govector_test.go @@ -413,9 +413,9 @@ func TestPolyPolyIntersect(t *testing.T) { p2.Points = append(p2.Points, Vector2d{10, 10}) p2.Points = append(p2.Points, Vector2d{10, 0}) - i, m, _ := PolyPolyIntersection(p1, Vector2d{0, 0}, p2) - if !i || !m { - t.Errorf("should not have intersected") + i, _, _ := PolyPolyIntersection(p1, Vector2d{0, 0}, p2) + if !i { + t.Errorf("should have intersected") } } @@ -433,8 +433,8 @@ func TestPolyPolyIntersectNegativeTranslationScale(t *testing.T) { p2.Points = append(p2.Points, Vector2d{10, 10}) p2.Points = append(p2.Points, Vector2d{10, 0}) - i, m, _ := PolyPolyIntersection(p1, Vector2d{0, 0}, p2) - if !i || !m { + i, _, _ := PolyPolyIntersection(p1, Vector2d{0, 0}, p2) + if !i { t.Errorf("should not have intersected") } } @@ -454,8 +454,11 @@ func TestPolyPolyIntersectMoving(t *testing.T) { p2.Points = append(p2.Points, Vector2d{10, 0}) i, m, _ := PolyPolyIntersection(p1, Vector2d{10, 10}, p2) - if i || !m { - t.Errorf("should not have intersected") + if i { + t.Errorf("should not have started intersected") + } + if !m { + t.Errorf("should have intersected after movement") } } @@ -479,6 +482,29 @@ func TestPolyPolyIntersectFail(t *testing.T) { } } +func TestPolyPolyNoOverlapMoveOnto(t *testing.T) { + p1 := Polygon2d{} + p1.Points = append(p1.Points, Vector2d{0, 0}) + p1.Points = append(p1.Points, Vector2d{0, 10}) + p1.Points = append(p1.Points, Vector2d{10, 10}) + p1.Points = append(p1.Points, Vector2d{10, 0}) + + p2 := Polygon2d{} + p2.Origin = Point2d{15, 15} + p2.Points = append(p2.Points, Vector2d{0, 0}) + p2.Points = append(p2.Points, Vector2d{0, 10}) + p2.Points = append(p2.Points, Vector2d{10, 10}) + p2.Points = append(p2.Points, Vector2d{10, 0}) + + i, m, _ := PolyPolyIntersection(p1, Vector2d{-10, -10}, p2) + if i { + t.Errorf("should not have started intersecting") + } + if m { + t.Errorf("should not have intersected") + } +} + func TestOrientedSquare(t *testing.T) { p := OrientedSquare(Point2d{10, 10}, Vector2d{0.5, 0.5}, 5) expected := []Vector2d{