Debian Codegraph @

exp/sprite/clock/tween_test.go

raw symbols SCIP
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package clockscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/
6
7 import "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/"
8
9 func TestLinearscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/TestLinear().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
10 t0 := Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#(0)
11 t1 := Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#(6 * 60)
12 now := Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#(3 * 60)
13
14 if c := Linearscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Linear().(t0, t1, now); c != 0.5 {
15 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("c=%.2f, want 0.5", c)
16 }
17 }
18
19 func TestCubicBezierscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/TestCubicBezier().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
20 t0 := Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#(0)
21 t1 := Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#(1e6)
22
23 tests := []struct {
24 x0, y0, x1, y1 float32
25 x, y float32
26 }{
27 {0.00, 0.1, 0.4, 1.00, 0.0, 0.00},
28 {0.00, 0.1, 0.4, 1.00, 0.1, 0.26},
29 {0.00, 0.1, 0.4, 1.00, 0.5, 0.79},
30 {0.00, 0.1, 0.4, 1.00, 0.9, 0.99},
31 {0.00, 0.1, 0.4, 1.00, 1.0, 1.00},
32 {0.36, 0.2, 0.3, 0.85, 0.0, 0.0},
33 {0.36, 0.2, 0.3, 0.85, 0.3059, 0.3952},
34 {0.36, 0.2, 0.3, 0.85, 0.4493, 0.6408},
35 {0.36, 0.2, 0.3, 0.85, 0.8116, 0.9410},
36 {0.00, 0.0, 1.0, 1.00, 0.1, 0.1},
37 {0.00, 0.0, 1.0, 1.00, 0.5, 0.5},
38 {0.00, 0.0, 1.0, 1.00, 0.9, 0.9},
39 {0.42, 0.0, 1.0, 1.00, 0.0, 0.0},
40 }
41
42 for _, test := range tests {
43 cb := CubicBezierscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/CubicBezier().(test.x0, test.y0, test.x1, test.y1)
44 now := t0 + Timescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/sprite/clock`/Time#(float32(t1-t0)*test.x)
45 y := cb(t0, t1, now)
46
47 const epsilon = 0.01
48 diff := y - test.y
49 if diff < -epsilon || +epsilon < diff {
50 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("CubicBezier(%.2f,%.2f,%.2f,%.2f): for x=%.2f got y=%.2f, want %.2f", test.x0, test.y0, test.x1, test.y1, test.x, y, test.y)
51 }
52 }
53 }