geom/pointf_test.go
Sander Schobers 26bac636bc Initial version of the geom package
- Includes PointF, RectangleF and PolygonF. Additional it includes the 32 bit floating point PointF32 and wrappers to image.Point and image.Rectangle.
2017-11-01 06:51:41 +01:00

32 lines
1.0 KiB
Go

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))
}