diff --git a/aquatic_room354.go b/aquatic_room354.go index e8667f1..cfc8e83 100644 --- a/aquatic_room354.go +++ b/aquatic_room354.go @@ -110,6 +110,7 @@ func (s *fishTank) roomBlocked354(u, v float64) bool { } x := s.tankW[0] + u*(s.tankW[2]-s.tankW[0]) y := s.tankW[1] + v*(s.tankW[3]-s.tankW[1]) - b, _ := s.room354.at(x, y) + x,y=s.level364.mapPoint(x,y,false) + b, _ := s.room354.at(x, y) return b } diff --git a/common.go b/common.go index e5d8965..3dff505 100644 --- a/common.go +++ b/common.go @@ -11,7 +11,7 @@ import ( "time" ) -const version = "0.98.363-experimental1" +const version = "0.98.364-experimental1" const appDisplayName = "Projection Mapper - Built by Instinct" diff --git a/fishtank.go b/fishtank.go index 8e1f44e..c2d947d 100644 --- a/fishtank.go +++ b/fishtank.go @@ -337,6 +337,9 @@ type ftFlake struct{ x, y, vx, vy, life float64 } type ftBubble struct{ x, y, r, ph, vy float64 } type fishTank struct { + level364 tankLevel364 + levelObstacles364 []tankObstacle364 + levelScratch364 []float32 room354 *aquaticRoomField354 live hxLiveQ set fishTankSettings @@ -379,6 +382,8 @@ func (s *fishTank) reset(e *physEngine) { } s.room354=e.aquaticRoom354 s.tankW, _ = fishTankLayout(g.src, aspect, s.set) + s.level364=tankSupportLevel364(g.src,aspect,s.set,s.tankW) + s.levelObstacles364=tankObstacles364(g.src) if s.tankW == [4]float64{} { s.tw = 0 s.th = 0 @@ -484,8 +489,9 @@ func (s *fishTank) step(e *physEngine, dt float64) { func (s *fishTank) input() { q := &s.live for _, tp := range q.taps { - x := (tp[0] - s.tankW[0]) / (s.tankW[2] - s.tankW[0]) - y := (tp[1] - s.tankW[1]) / (s.tankW[3] - s.tankW[1]) + px,py:=s.level364.mapPoint(tp[0],tp[1],true) + x := (px - s.tankW[0]) / (s.tankW[2] - s.tankW[0]) + y := (py - s.tankW[1]) / (s.tankW[3] - s.tankW[1]) if x < 0 || x > 1 || y < -0.3 || y > 1 { continue } @@ -966,6 +972,7 @@ func (s *fishTank) shade(e *physEngine) { }) s.drawFrame(out, lightCol, gain) s.drawGlow(out, lightCol, gain) + s.levelField364(out) for i := 0; i < fw*fh; i++ { // clamp o := i * 4 out[o], out[o+1], out[o+2] = hxClamp01f(out[o]), hxClamp01f(out[o+1]), hxClamp01f(out[o+2]) diff --git a/fishtank_ui_win.go b/fishtank_ui_win.go index 38d752c..1c00a8a 100644 --- a/fishtank_ui_win.go +++ b/fishtank_ui_win.go @@ -155,7 +155,7 @@ func (a *app) fishTankLayout(add func(widget) int, rx, rw, y, bh, pad int) { mode, width, place, amount, size, night, status := fishTankUI.mode, fishTankUI.width, fishTankUI.place, fishTankUI.amount, fishTankUI.size, fishTankUI.night, fishTankUI.status fishTankUI.mu.Unlock() label := func(text string, top, h int, on bool) { - add(widget{kind: kLabel, text: text, l: rx + sc(16), t: top, r: rx + rw - sc(16), b: top + h, small: true, on: on}) + add(widget{kind: kLabel, text: text, l: rx + sc(16), t: top, r: rx + rw - sc(16), b: top + h, small: true, on: on, wrap:true}) } tankName := "Freshwater Planted Aquascape" if mode == fishTankSalt { @@ -165,13 +165,13 @@ func (a *app) fishTankLayout(add func(widget) int, rx, rw, y, bh, pad int) { Title: "Fish Tank", Subtitle: "Realistic 3D-lit aquarium with sub-frame swimming, Beer-Lambert depth absorption, overhead caustics, and swaying plants.", SubtitleH: 42, - Sensing: "Current Outline Occlusion + Furniture Placement + Source-Bound Depth Lighting", + Sensing: "Outline Support-Edge Alignment + Current Occlusion + Source-Bound Depth Lighting", Selected: tankName, Status: status, }) rows := 6 - h2 := sc(44) + rows*(bh+sc(8)) + sc(64) + 3*(bh+sc(8)) + bh + sc(16) + h2 := sc(44) + rows*(bh+sc(8)) + sc(144) + 3*(bh+sc(8)) + bh + sc(16) add(widget{kind: kCard, text: "Tank settings (preview updates live; nothing is saved until you add a scene)", l: rx, t: y, r: rx + rw, b: y + h2}) by := y + sc(44) half := (rw - 2*sc(16) - sc(8)) / 2 @@ -187,7 +187,7 @@ func (a *app) fishTankLayout(add func(widget) int, rx, rw, y, bh, pad int) { } add(widget{kind: kBtn, id: idFtWater, text: water, l: x0, t: by, r: rx + rw - sc(16), b: by + bh, style: stPrimary, enabled: true}) by += bh + sc(8) - pair(idFtSmaller, fmt.Sprintf("- Smaller tank (now %d%% of the wall width)", int(width*100+0.5)), idFtLarger, "Larger tank +", width > fishTankMinWidth+1e-9, width < fishTankMaxWidth-1e-9) + pair(idFtSmaller, fmt.Sprintf("- Tank width: %d%%", int(width*100+0.5)), idFtLarger, "Larger tank +", width > fishTankMinWidth+1e-9, width < fishTankMaxWidth-1e-9) add(widget{kind: kBtn, id: idFtPlace, text: "Stand the tank " + fishTankPlaceNames[place] + " (click to change)", l: x0, t: by, r: rx + rw - sc(16), b: by + bh, enabled: true}) by += bh + sc(8) pair(idFtFewer, fmt.Sprintf("- Fewer fish (now %.0f%%)", amount*100), idFtMore, "More fish +", amount > 0.26, amount < 2.99) @@ -198,12 +198,12 @@ func (a *app) fishTankLayout(add func(widget) int, rx, rw, y, bh, pad int) { } add(widget{kind: kBtn, id: idFtLight, text: light, l: x0, t: by, r: rx + rw - sc(16), b: by + bh, enabled: true}) by += bh + sc(8) - txt := "Tank width is a share of the wall; height keeps a real 2:1 tank shape. Automatic and left/right placement stand it on the widest supported outline, including couches. Seating-only never substitutes a table or other object. Current foreground outlines stay dark and fish avoid their silhouettes. Verified source-bound room depth can shade the water; fish z remains virtual tank depth, not metric room placement." + txt := "A clear straight support edge aligns the tank to that outline, not measured gravity; uncertain edges keep photo-axis alignment. Tank width is a share of the wall; height keeps a 2:1 shape. Automatic and left/right placement stand it on the widest supported outline, including couches. Seating-only never substitutes a table or other object. Current foreground outlines stay dark and fish avoid their silhouettes. Verified source-bound room depth can shade the water; fish z remains virtual tank depth, not metric room placement." if status != "" { txt += " • " + status } - label(txt, by, sc(56), false) - by += sc(64) + label(txt, by, sc(136), false) + by += sc(144) opts := fxStdBarOpts{Enabled: func(id int) bool { if id == idFtStop { return a.fishTankPreviewOn() diff --git a/fxphys.go b/fxphys.go index 795a7f6..c163c44 100644 --- a/fxphys.go +++ b/fxphys.go @@ -334,6 +334,7 @@ func (e *physEngine) render() { } func (e *physEngine) sample(sx, sy float64) (rgb, float32) { + if tank,ok:=e.sim.(*fishTank);ok&&tank.blockedExact364(sx,sy){return rgb{},0} if e.aquaticRoom354!=nil{if b,_:=e.aquaticRoom354.at(sx,sy);b{return rgb{},0}} g := e.g fx := (sx-g.dx0)/(g.dx1-g.dx0)*float64(e.fw) - 0.5 @@ -702,7 +703,7 @@ func (r *Renderer) physFieldFor(sc *Scene, pl *plan, as Assign, plans []*plan, t if shared { dom := [4]float64{0, 0, 1, 1} if kind.id == fishTankID { // the tank and its glow margin only (fishtank.go) - _, dom = fishTankLayout(h.outlines, physSceneAspect(r.P), fishTankSettingsOf(cfg)) + tank,stage:=fishTankLayout(h.outlines,physSceneAspect(r.P),fishTankSettingsOf(cfg));lv:=tankSupportLevel364(h.outlines,physSceneAspect(r.P),fishTankSettingsOf(cfg),tank);dom=lv.domain(stage) } g = physBuildGrid(h.outlines, dom, physSceneAspect(r.P), physSimW, cfg.boxes, physMainWall(r.P), "", litHull(r.P)) } else { diff --git a/room_filters_test.go b/room_filters_test.go index 51b08f1..b904a01 100644 --- a/room_filters_test.go +++ b/room_filters_test.go @@ -84,9 +84,9 @@ func TestRoomFilters30DistinctAndDepthAware(t *testing.T) { } func TestFishTankRealisticFallbackAndSubframe(t *testing.T) { - kind, ok := findPhysKindForTest(fishTankID) + kind, ok := physKindOf(fishTankID) if !ok { - t.Fatal("fishTankID not registered in physKinds") + t.Fatal("fishTankID not available from production dispatcher") } outlines := []physOutline{ { diff --git a/tank_level364.go b/tank_level364.go new file mode 100644 index 0000000..eceb3c3 --- /dev/null +++ b/tank_level364.go @@ -0,0 +1,197 @@ +package main + +import "math" + +// An authored support edge is a visual alignment reference, not measured gravity. +// Coordinates, calibration and source outlines never change. +type tankLevel364 struct { + Applied bool + Angle, Aspect, CX, CY, BaseY float64 + Support string +} + +func (v tankLevel364) mapPoint(x, y float64, inverse bool) (float64, float64) { + if !v.Applied { + return x, y + } + a := v.Angle + oy, iy := v.CY, v.BaseY + if inverse { + a = -a + oy, iy = v.BaseY, v.CY + } + c, s := math.Cos(a), math.Sin(a) + px, py := (x-v.CX)*v.Aspect, y-iy + return v.CX + (px*c-py*s)/v.Aspect, oy + px*s + py*c +} +func tankSupportLevel364(outlines []physOutline, aspect float64, set fishTankSettings, tank [4]float64) tankLevel364 { + v := tankLevel364{Aspect: aspect, CX: (tank[0] + tank[2]) / 2, CY: tank[3], BaseY: tank[3]} + if set.place == 1 || tank == [4]float64{} || aspect <= 0 || !skFinite(aspect) { + return v + } + best := -1. + var support *physOutline + for i := range outlines { + o := &outlines[i] + if !fishTankSupportCls[o.cls] || len(o.poly) < 3 || (set.place == 4 && o.cls != "couch" && o.cls != "sofa" && o.cls != "seat" && o.cls != "chair") { + continue + } + valid := true + for _, p := range o.poly { + if !skFinite(p[0]+p[1]) || p[0] < 0 || p[0] > 1 || p[1] < 0 || p[1] > 1 { + valid = false + } + } + if !valid { + continue + } + b := physPolyBox(o.poly) + if b[1] < .30 || b[2]-b[0] < .08 { + continue + } + if b[2]-b[0] > best { + best = b[2] - b[0] + support = o + } + } + if support == nil { + return v + } + bb := physPolyBox(support.poly) + longest := 0. + angle := 0. + var qualified []float64 + var edgeA, edgeB [2]float64 + for i, a := range support.poly { + b := support.poly[(i+1)%len(support.poly)] + if b[0] < a[0] { + a, b = b, a + } + dx := b[0] - a[0] + if dx < best*.6 || math.Max(a[1], b[1]) > bb[1]+(bb[3]-bb[1])*.3 { + continue + } + ang := math.Atan2(b[1]-a[1], dx*aspect) + if math.Abs(ang) > 12*math.Pi/180 { + return v + } + qualified = append(qualified, ang) + if dx > longest { + longest, angle, edgeA, edgeB = dx, ang, a, b + } + } + for _, a := range qualified { + if math.Abs(a-angle) > 2*math.Pi/180 { + return v + } + } + if longest == 0 { + return v + } + // Both tank base corners must sit over the retained straight support edge. + if v.CX-(tank[2]-tank[0])/2 < edgeA[0]-.002 || v.CX+(tank[2]-tank[0])/2 > edgeB[0]+.002 { + return v + } + v.CY = edgeA[1] + (v.CX-edgeA[0])*(edgeB[1]-edgeA[1])/(edgeB[0]-edgeA[0]) + v.Angle = angle + v.Applied = math.Abs(angle) > .001 + v.Support = support.id + // Never silently crop the glass to make a correction fit the photo. + for _, p := range [][2]float64{{tank[0], tank[1]}, {tank[2], tank[1]}, {tank[2], tank[3]}, {tank[0], tank[3]}} { + x, y := v.mapPoint(p[0], p[1], false) + if x < .005 || x > .995 || y < .005 || y > .995 { + v.Applied = false + return v + } + } + return v +} +func (v tankLevel364) domain(dom [4]float64) [4]float64 { + if !v.Applied { + return dom + } + out := [4]float64{1, 1, 0, 0} + for _, p := range [][2]float64{{dom[0], dom[1]}, {dom[2], dom[1]}, {dom[2], dom[3]}, {dom[0], dom[3]}} { + x, y := v.mapPoint(p[0], p[1], false) + out[0] = math.Min(out[0], x) + out[1] = math.Min(out[1], y) + out[2] = math.Max(out[2], x) + out[3] = math.Max(out[3], y) + } + // Include the unrotated staging domain too. It is never projected directly. + for i := 0; i < 2; i++ { + out[i] = math.Max(0, math.Min(out[i], dom[i])) + out[i+2] = math.Min(1, math.Max(out[i+2], dom[i+2])) + } + return out +} +func (s *fishTank) levelField364(out []float32) { + if !s.level364.Applied { + return + } + if len(s.levelScratch364) != len(out) { + s.levelScratch364 = make([]float32, len(out)) + } + copy(s.levelScratch364, out) + clear(out) + d := s.dom + dw, dh := d[2]-d[0], d[3]-d[1] + if dw <= 0 || dh <= 0 { + return + } + for y := 0; y < s.fh; y++ { + for x := 0; x < s.fw; x++ { + sx, sy := s.level364.mapPoint(d[0]+(float64(x)+.5)/float64(s.fw)*dw, d[1]+(float64(y)+.5)/float64(s.fh)*dh, true) + fx, fy := (sx-d[0])/dw*float64(s.fw)-.5, (sy-d[1])/dh*float64(s.fh)-.5 + x0, y0 := int(math.Floor(fx)), int(math.Floor(fy)) + tx, ty := float32(fx-float64(x0)), float32(fy-float64(y0)) + for k := 0; k < 4; k++ { + xx, yy := x0+(k&1), y0+(k>>1) + if xx < 0 || yy < 0 || xx >= s.fw || yy >= s.fh { + continue + } + wx, wy := 1-tx, 1-ty + if k&1 != 0 { + wx = tx + } + if k>>1 != 0 { + wy = ty + } + a, b := (y*s.fw+x)*4, (yy*s.fw+xx)*4 + for c := 0; c < 4; c++ { + out[a+c] += s.levelScratch364[b+c] * wx * wy + } + } + } + } + for i := range out { + out[i] = hxClamp01f(out[i]) + } +} + +// The rotated field's bilinear edge may touch an occluder between cached mask +// cells. Keep exact authored contours dark at final sampling too. +type tankObstacle364 struct { + o physOutline + box [4]float64 +} + +func tankObstacles364(outlines []physOutline) []tankObstacle364 { + var out []tankObstacle364 + for _, o := range modelRingOutlines(outlines) { + out = append(out, tankObstacle364{o, physPolyBox(o.poly)}) + } + return out +} +func (s *fishTank) blockedExact364(x, y float64) bool { + if !s.level364.Applied || s.room354 == nil { + return false + } + for _, ob := range s.levelObstacles364 { + o, b := ob.o, ob.box + if x >= b[0] && x <= b[2] && y >= b[1] && y <= b[3] && modelOutlineContains(o, x, y) { + return true + } + } + return false +} diff --git a/tank_level364_test.go b/tank_level364_test.go new file mode 100644 index 0000000..1d0559c --- /dev/null +++ b/tank_level364_test.go @@ -0,0 +1,248 @@ +package main + +import ( + "crypto/sha256" + "encoding/hex" + "image" + "image/color" + "image/png" + "math" + "os" + "os/exec" + "reflect" + "testing" + "time" +) + +func tankOutline364() []physOutline { + return []physOutline{{id: "sofa", cls: "sofa", poly: [][2]float64{{.15, .70}, {.85, .61}, {.85, .91}, {.15, .91}}}} +} +func Test364SupportEdgeAlignmentAndInverse(t *testing.T) { + os := tankOutline364() + saved := append([][2]float64(nil), os[0].poly...) + set := fishTankSettings{width: .5, place: 0} + tank, dom := fishTankLayout(os, 16./9, set) + v := tankSupportLevel364(os, 16./9, set, tank) + if !v.Applied || v.Support != "sofa" { + t.Fatal(v) + } + a, b := v.mapPoint(tank[0], tank[3], false) + c, d := v.mapPoint(tank[2], tank[3], false) + if math.Abs((d-b)/(c-a)-(-.09/.7)) > 1e-8 { + t.Fatal("wrong support slope", a, b, c, d) + } + for _, p := range [][2]float64{{.2, .4}, {.5, .7}, {.8, .9}} { + x, y := v.mapPoint(p[0], p[1], false) + x, y = v.mapPoint(x, y, true) + if math.Hypot(x-p[0], y-p[1]) > 1e-12 { + t.Fatal("round trip") + } + } + if !reflect.DeepEqual(saved, os[0].poly) { + t.Fatal("outline mutated") + } + expanded := v.domain(dom) + if expanded[0] > dom[0] || expanded[1] > dom[1] || expanded[2] < dom[2] || expanded[3] < dom[3] { + t.Fatal("staging domain clipped", dom, expanded) + } +} +func Test364MissingAmbiguousOrUntrustedEdgeNeutral(t *testing.T) { + set := fishTankSettings{width: .5} + for _, o := range [][]physOutline{nil, {{cls: "sofa", poly: [][2]float64{{.1, .6}, {.9, .3}, {.9, .9}, {.1, .9}}}}, {{cls: "sofa", poly: [][2]float64{{.1, .6}, {.4, .5}, {.55, .6}, {.9, .55}, {.9, .9}, {.1, .9}}}}} { + tank, _ := fishTankLayout(o, 16./9, set) + v := tankSupportLevel364(o, 16./9, set, tank) + if v.Applied { + t.Fatal("invented alignment", v) + } + } + set.place = 1 + tank, _ := fishTankLayout(tankOutline364(), 16./9, set) + if tankSupportLevel364(tankOutline364(), 16./9, set, tank).Applied { + t.Fatal("center mode changed") + } +} +func Test364FieldWarpBlackNeutralAndRoomOcclusion(t *testing.T) { + s := &fishTank{fw: 100, fh: 80, dom: [4]float64{0, 0, 1, 1}, level364: tankLevel364{Applied: true, Angle: -.1, Aspect: 1.5, CX: .5, CY: .7, BaseY: .7}} + out := make([]float32, 100*80*4) + s.levelField364(out) + for _, v := range out { + if v != 0 { + t.Fatal("black lifted") + } + } + for y := 20; y < 60; y++ { + for x := 20; x < 80; x++ { + out[(y*100+x)*4] = .5 + out[(y*100+x)*4+3] = 1 + } + } + s.levelField364(out) + n := 0 + for _, v := range out { + if !skFinite(float64(v)) || v < 0 || v > 1 { + t.Fatal("invalid warped pixel") + } + if v > 0 { + n++ + } + } + if n < 100 { + t.Fatal("lost tank") + } + s.tankW = [4]float64{.2, .2, .8, .7} + u, v := .5, .6 + x, y := s.level364.mapPoint(.2+u*.6, .2+v*.5, false) + s.room354 = buildAquaticRoomField354([]physOutline{{poly: [][2]float64{{x - .02, y - .02}, {x + .02, y - .02}, {x + .02, y + .02}, {x - .02, y + .02}}}}, [4]float64{0, 0, 1, 1}, 100, 100, nil) + if !s.roomBlocked354(u, v) { + t.Fatal("collision did not map to authored photo") + } +} + +func Test364ActualTankRendererAndMasks(t *testing.T) { + p := roomTestProject(480, 270) + wall := [][2]float64{{.02, .02}, {.98, .02}, {.98, .98}, {.02, .98}} + support := tankOutline364()[0].poly + p.Surfaces = []Surface{{ID: "wall", Cls: "wall", Poly: wall, Quad: polyBox(wall)}, {ID: "sofa", Cls: "sofa", Poly: support, Quad: polyBox(support)}} + r := newRenderer(p, "") + defer r.closeVideoResources() + r.exportVirtual = true + r.directorIsolatedHub = &physHub{owner: r, eng: map[string]*physEngine{}} + as := Assign{Type: "fx", ID: fishTankID, Scale: 1, Speed: 1, Inten: 1, Phys: &PhysParams{Shared: true, Species: fishTankFresh, Amount: 1, HX: []float64{.5, 0, 0}}} + sc := Scene{ID: "level364", Duration: 3600, Assign: map[string]Assign{"wall": as}} + f := newFrame(480, 270) + for i := 0; i < 8; i++ { + r.RenderScene(&sc, float64(i)*.1, f, 1, time.Time{}) + } + var sim *fishTank + for _, e := range r.directorIsolatedHub.eng { + sim, _ = e.sim.(*fishTank) + } + if sim == nil || !sim.level364.Applied { + t.Fatal("actual renderer missed alignment", sim) + } + lit := 0 + for y := 0; y < f.H; y++ { + for x := 0; x < f.W; x++ { + o := (y*f.W + x) * 4 + if f.Pix[o]|f.Pix[o+1]|f.Pix[o+2] == 0 { + continue + } + lit++ + if !pointInPolyXY((float64(x)+.5)/480, (float64(y)+.5)/270, wall) { + t.Fatal("outside receiving mask") + } + if pointInPolyXY((float64(x)+.5)/480, (float64(y)+.5)/270, support) { + t.Fatal("foreground outline lit", x, y) + } + } + } + if lit < 1000 { + t.Fatal("blank", lit) + } + if dir := os.Getenv("PM364_PIXELS"); dir != "" { + os.MkdirAll(dir, 0700) + im := image.NewRGBA(image.Rect(0, 0, f.W, f.H)) + for y := 0; y < f.H; y++ { + for x := 0; x < f.W; x++ { + o := (y*f.W + x) * 4 + im.SetRGBA(x, y, color.RGBA{f.Pix[o+2], f.Pix[o+1], f.Pix[o], 255}) + } + } + file, e := os.Create(dir + "/tank-outline-alignment.png") + if e != nil { + t.Fatal(e) + } + png.Encode(file, im) + file.Close() + } +} + +func Test364TouchUsesRenderedPositionAndNeutralIsExact(t *testing.T) { + s := &fishTank{tankW: [4]float64{.2, .2, .8, .7}, level364: tankLevel364{Applied: true, Angle: -.1, Aspect: 16. / 9, CX: .5, CY: .75, BaseY: .7}, rnd: physRand{s: 3}, wave: make([]float64, 24), waveV: make([]float64, 24)} + x, y := s.level364.mapPoint(.35, .23, false) + s.live.taps = append(s.live.taps, [2]float64{x, y}) + s.input() + if len(s.flakes) != 14 || math.Abs(s.flakes[0].x-.25) > .05 { + t.Fatal("feeding missed transformed location", len(s.flakes)) + } + off := &fishTank{fw: 4, fh: 4} + out := make([]float32, 64) + for i := range out { + out[i] = float32(i) / 100 + } + before := append([]float32(nil), out...) + off.levelField364(out) + if !reflect.DeepEqual(out, before) { + t.Fatal("neutral field changed") + } + flat := tankOutline364() + flat[0].poly[0][1] = .61 + v := tankSupportLevel364(flat, 16./9, fishTankSettings{width: .5}, [4]float64{.25, .2, .75, .61}) + if v.Applied { + t.Fatal("flat support resampled") + } +} + +func Test364TankArtByteIdenticalTo363(t *testing.T) { + paths, e := os.ReadDir("assets/fishtank") + if e != nil { + t.Fatal(e) + } + for _, p := range paths { + if p.IsDir() { + continue + } + name := "assets/fishtank/" + p.Name() + b, e := os.ReadFile(name) + if e != nil { + t.Fatal(e) + } + old, e := exec.Command("git", "show", "458f1f11d9260feef8dbb7e8fb1780b6dfad9845:"+name).Output() + if e != nil { + t.Fatal(e) + } + a, c := sha256.Sum256(b), sha256.Sum256(old) + if a != c { + t.Fatal("tank art changed", name, hex.EncodeToString(a[:])) + } + } +} + +func Test364RendererSlopeMatchesQualifiedSupport(t *testing.T) { + for _, direction := range []float64{-1, 1} { + o := tankOutline364() + if direction > 0 { + o[0].poly[0][1], o[0].poly[1][1] = .61, .70 + } + set := fishTankSettings{width: .5, mode: fishTankFresh, amount: 1, size: 1} + tank, stage := fishTankLayout(o, 16./9, set) + v := tankSupportLevel364(o, 16./9, set, tank) + g := physBuildGrid(o, v.domain(stage), 16./9, 160, false, nil, "", nil) + cfg := physCfg{seed: 7, species: fishTankFresh, amount: 1, size: 1, hx: []float64{.5, 0, 0}} + e := newPhysEngine(fishTankKind, cfg, g) + sim := e.sim.(*fishTank) + if !sim.level364.Applied || sim.level364.Angle*direction <= 0 { + t.Fatal("direction", sim.level364) + } + start := time.Now() + for i := 0; i < 12; i++ { + e.dirty = true + e.render() + } + t.Logf("aligned field %dx%d average %s", e.fw, e.fh, time.Since(start)/12) + // Bright trim must follow transformed top corners in the actual shaded field. + hits := 0 + for _, u := range []float64{.15, .35, .65, .85} { + x := sim.tankW[0] + u*(sim.tankW[2]-sim.tankW[0]) + y := sim.tankW[1] + .025*(sim.tankW[3]-sim.tankW[1]) + x, y = sim.level364.mapPoint(x, y, false) + c, a := e.sample(x, y) + if a > 0 && float64(c.r+c.g+c.b) > .05 { + hits++ + } + } + if hits != 4 { + t.Fatal("transformed tank missing", hits) + } + } +}