added a test for moving polygon, removed prints

This commit is contained in:
Fraser Graham 2013-11-26 08:41:42 -08:00
parent 5a41b2eea9
commit 9f5fcf5543
2 changed files with 18 additions and 2 deletions

View File

@ -1,7 +1,6 @@
package govector package govector
import ( import (
"fmt"
"math" "math"
) )
@ -158,7 +157,6 @@ func PolyPolyIntersection(p1 Polygon2d, v1 Vector2d, p2 Polygon2d) (bool, bool,
if interval_distance < minimum_interval_distance { if interval_distance < minimum_interval_distance {
minimum_interval_distance = interval_distance minimum_interval_distance = interval_distance
translation = axis translation = axis
fmt.Printf(" AXIS: %v %v\n", axis, interval_distance)
if p1.Origin.Sub(p2.Origin).Dot(axis) < 0 { if p1.Origin.Sub(p2.Origin).Dot(axis) < 0 {
translation = translation.Scale(-1) translation = translation.Scale(-1)
} }

View File

@ -319,6 +319,24 @@ func TestPolyPolyIntersect(t *testing.T) {
fmt.Printf("%v %v %v\n", i, m, p) fmt.Printf("%v %v %v\n", i, m, p)
} }
func TestPolyPolyIntersectMoving(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, p := PolyPolyIntersection(p1, Vector2d{10, 10}, p2)
fmt.Printf("%v %v %v\n", i, m, p)
}
func TestPolyPolyIntersectFail(t *testing.T) { func TestPolyPolyIntersectFail(t *testing.T) {
p1 := Polygon2d{} p1 := Polygon2d{}
p1.Points = append(p1.Points, Vector2d{0, 0}) p1.Points = append(p1.Points, Vector2d{0, 0})