github.com/sandwich-go/boost@v1.3.29/geom/int8_test.go (about) 1 // Code generated by tools. DO NOT EDIT. 2 package geom 3 4 import ( 5 "fmt" 6 . "github.com/smartystreets/goconvey/convey" 7 "testing" 8 ) 9 10 func TestRectangleInt8_SnakeRange(t *testing.T) { 11 HelixRectRangeFromCenterAndMarginInt8(PtInt8(2, 2), 2, func(p PointInt8) bool { 12 t.Log(p.X, p.Y) 13 return true 14 }) 15 16 Convey("test intersection with line", t, func() { 17 x := PtInt8(1, 0) 18 y := PtInt8(1, 4) 19 z := x.Add(y) 20 So(z.X, ShouldEqual, 2) 21 So(z.Y, ShouldEqual, 4) 22 So(z.String(), ShouldEqual, "(2,4)") 23 So(z.Sub(x).Eq(y), ShouldBeTrue) 24 q := y.Mul(3) 25 So(q.X, ShouldEqual, y.X*3) 26 So(q.Y, ShouldEqual, y.Y*3) 27 So(q.Div(3).Eq(y), ShouldBeTrue) 28 var r1, r2, r3, r4 int8 = 1, 0, 5, 5 29 r := RectInt8(r1, r2, r3, r4) 30 So(x.In(r), ShouldBeTrue) 31 So(r.String(), ShouldEqual, fmt.Sprintf("(%d,%d)-(%d,%d)", r1, r2, r3, r4)) 32 var minX, maxX, minY, maxY int8 33 var reset = func() { minX, maxX, minY, maxY = 5, 0, 5, 0 } 34 var f = func(p PointInt8) bool { 35 if p.X < minX { 36 minX = p.X 37 } 38 if p.Y < minY { 39 minY = p.Y 40 } 41 if p.X > maxX { 42 maxX = p.X 43 } 44 if p.Y > maxY { 45 maxY = p.Y 46 } 47 return true 48 } 49 reset() 50 r.RangePoints(f) 51 So(minX, ShouldEqual, r1) 52 So(minY, ShouldEqual, r2) 53 So(maxX, ShouldEqual, r3) 54 So(maxY, ShouldEqual, r4) 55 reset() 56 r.RangePointsMinClosedMaxOpen(f) 57 So(minX, ShouldEqual, r1+1) 58 So(minY, ShouldEqual, r2+1) 59 So(maxX, ShouldEqual, r3) 60 So(maxY, ShouldEqual, r4) 61 reset() 62 r.RangePointsMinMaxClosed(f) 63 So(minX, ShouldEqual, r1+1) 64 So(minY, ShouldEqual, r2+1) 65 So(maxX, ShouldEqual, r3-1) 66 So(maxY, ShouldEqual, r4-1) 67 reset() 68 r.RangePointsMinOpenMaxClosed(f) 69 So(minX, ShouldEqual, r1) 70 So(minY, ShouldEqual, r2) 71 So(maxX, ShouldEqual, r3-1) 72 So(maxY, ShouldEqual, r4-1) 73 So(r.Dx(), ShouldEqual, r3-r1) 74 So(r.Dy(), ShouldEqual, r4-r2) 75 So(r.Size().Eq(PtInt8(r3-r1, r4-r2)), ShouldBeTrue) 76 rc := PtInt8(1, 1) 77 rr := r.Add(rc) 78 So(rr.Max.X, ShouldEqual, r.Max.X+rc.X) 79 So(rr.Max.Y, ShouldEqual, r.Max.Y+rc.Y) 80 So(rr.Min.X, ShouldEqual, r.Min.X+rc.X) 81 So(rr.Min.Y, ShouldEqual, r.Min.Y+rc.Y) 82 So(rr.Sub(rc).Eq(r), ShouldBeTrue) 83 ir := r.Inset(1) 84 So(ir.String(), ShouldEqual, fmt.Sprintf("(%d,%d)-(%d,%d)", r1+1, r2+1, r3-1, r4-1)) 85 So(r.Intersect(ir).Eq(ir), ShouldBeTrue) 86 So(r.Union(r.Inset(1)).Eq(r), ShouldBeTrue) 87 So(r.Empty(), ShouldBeFalse) 88 So(ZRInt8.Empty(), ShouldBeTrue) 89 So(r.Overlaps(ir), ShouldBeTrue) 90 So(r.Bounds().Eq(r), ShouldBeTrue) 91 So(ir.In(r), ShouldBeTrue) 92 So(ir.Expanded(rc).Eq(r), ShouldBeTrue) 93 So(ir.ExpandedByMargin(1).Eq(r), ShouldBeTrue) 94 95 rect := RectInt8(0, 0, 3, 3) 96 So(rect.IntersectionWithLine(PtInt8(1, 0), PtInt8(1, 4)), ShouldBeTrue) // should be true 97 So(rect.IntersectionWithLine(PtInt8(1, 0), PtInt8(1, 3)), ShouldBeTrue) // should be true 98 So(rect.IntersectionWithLine(PtInt8(1, 0), PtInt8(1, 2)), ShouldBeTrue) // should be true 99 So(rect.IntersectionWithLine(PtInt8(1, 0), PtInt8(1, 1)), ShouldBeTrue) // should be true 100 So(rect.IntersectionWithLine(PtInt8(2, 0), PtInt8(2, 2)), ShouldBeTrue) // should be true 101 So(rect.IntersectionWithLine(PtInt8(0, 2), PtInt8(1, 2)), ShouldBeTrue) // should be true 102 So(rect.IntersectionWithLine(PtInt8(0, 1), PtInt8(3, 1)), ShouldBeTrue) // should be true 103 So(rect.IntersectionWithLine(PtInt8(0, 0), PtInt8(0, 1)), ShouldBeFalse) // should be false 104 So(rect.IntersectionWithLine(PtInt8(0, 0), PtInt8(0, 2)), ShouldBeFalse) // should be false 105 So(rect.IntersectionWithLine(PtInt8(0, 0), PtInt8(0, 3)), ShouldBeFalse) // should be false 106 So(rect.IntersectionWithLine(PtInt8(0, 0), PtInt8(0, 4)), ShouldBeFalse) // should be false 107 So(rect.IntersectionWithLine(PtInt8(0, 0), PtInt8(1, 0)), ShouldBeFalse) // should be false 108 So(rect.IntersectionWithLine(PtInt8(0, 0), PtInt8(2, 0)), ShouldBeFalse) // should be false 109 So(rect.IntersectionWithLine(PtInt8(1, 4), PtInt8(2, 4)), ShouldBeFalse) // should be false 110 So(rect.IntersectionWithLine(PtInt8(0, 3), PtInt8(3, 3)), ShouldBeFalse) // should be false 111 So(rect.IntersectionWithLine(PtInt8(1, 3), PtInt8(2, 4)), ShouldBeFalse) // should be false 112 }) 113 }