geom/pointf_test.go

32 lines
1.0 KiB
Go
Raw Permalink Normal View History

package geom
import (
"math"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPointFAngleTo(t *testing.T) {
for a := .0; a <= 2*math.Pi; a += math.Pi * 0.25 {
assert.InDelta(t, a, PtF(0, 0).AngleTo(PtF(100*math.Cos(a), 100*math.Sin(a))), 0.000001)
}
}
func TestPointInPolygon(t *testing.T) {
pol := PolygonF{[]PointF{PtF(0, 0), PtF(0, 3), PtF(1, 3), PtF(2, 1), PtF(3, 3), PtF(5, 3), PtF(5, 2), PtF(3, 1), PtF(5, 0)}}
assert.True(t, PtF(1, 2).InPolygon(pol))
assert.True(t, PtF(3, 2).InPolygon(pol))
assert.True(t, PtF(4, 2).InPolygon(pol))
// assert.True(t, PtF(0, 0).InPolygon(pol)) // Corner = out
// assert.True(t, PtF(0, 3).InPolygon(pol)) // Corner = out
// assert.True(t, PtF(5, 3).InPolygon(pol)) // Corner = in
// assert.True(t, PtF(5, 0).InPolygon(pol)) // Corner = out
assert.False(t, PtF(0, -1).InPolygon(pol))
assert.False(t, PtF(-1, 0).InPolygon(pol))
assert.False(t, PtF(2, 2).InPolygon(pol))
assert.False(t, PtF(2, 3).InPolygon(pol))
assert.False(t, PtF(4, 1).InPolygon(pol))
assert.False(t, PtF(5, 1).InPolygon(pol))
}