From 0f4425fbc270830b148d2df2ae4c3ee8bd64d9d3 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Mon, 6 Jul 2026 14:14:34 +0700 Subject: [PATCH] feat(misc): move wheel beta pointer right --- internal/modules/misc/handlers_test.go | 29 ++++++++++++++----- internal/modules/misc/wheelofnames_beta.go | 7 +++-- .../modules/misc/wheelofnames_beta_drawing.go | 22 +++++++------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/internal/modules/misc/handlers_test.go b/internal/modules/misc/handlers_test.go index fb7d088..ff6899e 100644 --- a/internal/modules/misc/handlers_test.go +++ b/internal/modules/misc/handlers_test.go @@ -361,21 +361,34 @@ func TestWheelOfNamesBeta_SpinProfileProgressIsMonotonic(t *testing.T) { func TestWheelOfNamesBeta_PointerPointsIntoWheel(t *testing.T) { img := renderWheelBetaFrame([]string{"Alice", "Bob"}, 0, finalWheelRotation(2, 0), false) cx := wheelBetaSize / 2 - tipY := wheelBetaSize/2 - wheelBetaRadius - if got := img.ColorIndexAt(cx, tipY); got != 1 { + cy := wheelBetaSize / 2 + tipX := cx + wheelBetaRadius + if got := img.ColorIndexAt(tipX, cy); got != 1 { t.Fatalf("pointer tip color = %d, want 1", got) } - if got := img.ColorIndexAt(cx+5, tipY-10); got != 1 { + if got := img.ColorIndexAt(tipX+10, cy+5); got != 1 { t.Fatalf("pointer shoulder color = %d, want 1", got) } - if got := img.ColorIndexAt(cx, tipY-12); got != wheelBetaSliceColorIndexes[0] { + if got := img.ColorIndexAt(tipX+12, cy); got != wheelBetaSliceColorIndexes[0] { t.Fatalf("pointer body color = %d, want current slice color %d", got, wheelBetaSliceColorIndexes[0]) } - if got := img.ColorIndexAt(cx+5, tipY); got == 1 { - t.Fatalf("pointer tip is too wide at color index %d", got) + if got := img.ColorIndexAt(tipX, cy+5); got == 1 { + t.Fatalf("pointer tip is too tall at color index %d", got) } - if got := img.ColorIndexAt(cx+12, tipY+20); got == 1 { - t.Fatalf("pointer widens below wheel edge at color index %d", got) + if got := img.ColorIndexAt(tipX-20, cy+12); got == 1 { + t.Fatalf("pointer widens inside wheel edge at color index %d", got) + } +} + +func TestWheelOfNamesBeta_FinalSliceRendersAtRightPointer(t *testing.T) { + options := []string{"Alice", "Bob", "Carol", "Dana"} + winner := 2 + img := renderWheelBetaFrame(options, winner, finalWheelRotation(len(options), winner), true) + x := wheelBetaSize/2 + wheelBetaRadius - 20 + y := wheelBetaSize / 2 + want := wheelBetaSliceColorIndexes[winner%len(wheelBetaSliceColorIndexes)] + if got := img.ColorIndexAt(x, y); got != want { + t.Fatalf("right pointer slice color = %d, want winner slice color %d", got, want) } } diff --git a/internal/modules/misc/wheelofnames_beta.go b/internal/modules/misc/wheelofnames_beta.go index 734fcb2..314870e 100644 --- a/internal/modules/misc/wheelofnames_beta.go +++ b/internal/modules/misc/wheelofnames_beta.go @@ -21,6 +21,7 @@ const ( wheelBetaHoldDelay = wheelBetaSpinDelay wheelBetaDuration = wheelBetaSpinDuration + wheelBetaHoldDuration wheelBetaCelebrateFrames = 8 + wheelBetaPointerAngle = 0.0 ) const ( @@ -133,7 +134,7 @@ func renderWheelBetaFrameWithCelebration(options []string, winner int, rotation drawWheelSliceLabels(img, options, rotation) drawCircle(img, cx, cy, 24, wheelBetaPaperColorIndex) drawCircle(img, cx, cy, 18, wheelBetaInkColorIndex) - drawPointer(img, cx, cy-wheelBetaRadius, pointerColor) + drawPointer(img, cx+wheelBetaRadius, cy, pointerColor) drawCenteredText(img, "WHEELOFNAMES BETA", cy+wheelBetaRadius+34, wheelBetaInkColorIndex) label := status if label == "" { @@ -154,12 +155,12 @@ func finalWheelRotation(optionCount, winner int) float64 { func finalWheelRotationWithOffset(optionCount, winner int, sliceOffset float64) float64 { segment := 2 * math.Pi / float64(optionCount) - return -math.Pi/2 - (float64(winner)+0.5+sliceOffset)*segment + return wheelBetaPointerAngle - (float64(winner)+0.5+sliceOffset)*segment } func currentWheelBetaIndex(optionCount int, rotation float64) int { segment := 2 * math.Pi / float64(optionCount) - return int(normalizeAngle(-math.Pi/2-rotation) / segment) + return int(normalizeAngle(wheelBetaPointerAngle-rotation) / segment) } func normalizeAngle(theta float64) float64 { diff --git a/internal/modules/misc/wheelofnames_beta_drawing.go b/internal/modules/misc/wheelofnames_beta_drawing.go index fbd64c3..93cd74e 100644 --- a/internal/modules/misc/wheelofnames_beta_drawing.go +++ b/internal/modules/misc/wheelofnames_beta_drawing.go @@ -130,22 +130,22 @@ func drawCircleOutline(img *image.Paletted, cx, cy, radius, thickness int, color } } -func drawPointer(img *image.Paletted, cx, tipY int, fillColorIndex byte) { - for y := 0; y < 34; y++ { - half := y / 2 - rowY := tipY - y - for x := cx - half; x <= cx+half; x++ { - setWheelBetaPixel(img, x, rowY, wheelBetaInkColorIndex) +func drawPointer(img *image.Paletted, tipX, cy int, fillColorIndex byte) { + for xOffset := 0; xOffset < 34; xOffset++ { + half := xOffset / 2 + x := tipX + xOffset + for y := cy - half; y <= cy+half; y++ { + setWheelBetaPixel(img, x, y, wheelBetaInkColorIndex) } } - for y := 3; y < 30; y++ { - half := y/2 - 2 + for xOffset := 3; xOffset < 30; xOffset++ { + half := xOffset/2 - 2 if half < 0 { continue } - rowY := tipY - y - for x := cx - half; x <= cx+half; x++ { - setWheelBetaPixel(img, x, rowY, fillColorIndex) + x := tipX + xOffset + for y := cy - half; y <= cy+half; y++ { + setWheelBetaPixel(img, x, y, fillColorIndex) } } }