| 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 f32scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/ |
| 6 | |
| 7 | import ( |
| 8 | "mathscip-go gomod github.com/golang/go/src go1.24.0 math/" |
| 9 | "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/" |
| 10 | ) |
| 11 | |
| 12 | var xyTestsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests. = []struct { |
| 13 | xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:x., yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:y. float32 |
| 14 | }{ |
| 15 | {0, 0}, |
| 16 | {1, 1}, |
| 17 | {2, 3}, |
| 18 | {6.5, 4.3}, |
| 19 | } |
| 20 | |
| 21 | var ascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/a. = Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#{ |
| 22 | {3, 4, 5}, |
| 23 | {6, 7, 8}, |
| 24 | } |
| 25 | |
| 26 | func TestInversescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/TestInverse().(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#) { |
| 27 | wantInv := Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#{ |
| 28 | {-2.33333, 1.33333, 1}, |
| 29 | {2, -1, -2}, |
| 30 | } |
| 31 | var gotInv Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine# |
| 32 | gotInv.Inversescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Inverse().(&ascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/a.) |
| 33 | if !gotInv.Eqscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Eq().(&wantInv, 0.01) { |
| 34 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("Inverse: got %s want %s", gotInv, wantInv) |
| 35 | } |
| 36 | |
| 37 | var wantId, gotId Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine# |
| 38 | wantId.Identityscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Identity().() |
| 39 | gotId.Mulscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Mul().(&ascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/a., &wantInv) |
| 40 | if !gotId.Eqscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Eq().(&wantId, 0.01) { |
| 41 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("Identity #0: got %s want %s", gotId, wantId) |
| 42 | } |
| 43 | gotId.Mulscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Mul().(&wantInv, &ascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/a.) |
| 44 | if !gotId.Eqscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Eq().(&wantId, 0.01) { |
| 45 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("Identity #1: got %s want %s", gotId, wantId) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | func TestAffineScalescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/TestAffineScale().(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#) { |
| 50 | for _, test := range xyTestsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests. { |
| 51 | want := ascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/a. |
| 52 | want.Mulscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Mul().(&want, &Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#{{test.xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:x., 0, 0}, {0, test.yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:y., 0}}) |
| 53 | got := ascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/a. |
| 54 | got.Scalescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Scale().(&got, test.xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:x., test.yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:y.) |
| 55 | |
| 56 | if !got.Eqscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Eq().(&want, 0.01) { |
| 57 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("(%.2f, %.2f): got %s want %s", test.xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:x., test.yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:y., got, want) |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | func TestAffineTranslatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/TestAffineTranslate().(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#) { |
| 63 | for _, test := range xyTestsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests. { |
| 64 | want := ascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/a. |
| 65 | want.Mulscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Mul().(&want, &Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#{{1, 0, test.xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:x.}, {0, 1, test.yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:y.}}) |
| 66 | got := ascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/a. |
| 67 | got.Translatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Translate().(&got, test.xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:x., test.yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:y.) |
| 68 | |
| 69 | if !got.Eqscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Eq().(&want, 0.01) { |
| 70 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("(%.2f, %.2f): got %s want %s", test.xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:x., test.yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/xyTests:y., got, want) |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | } |
| 75 | |
| 76 | func TestAffineRotatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/TestAffineRotate().(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#) { |
| 77 | want := Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#{ |
| 78 | {-4.000, 3.000, 5.000}, |
| 79 | {-7.000, 6.000, 8.000}, |
| 80 | } |
| 81 | got := ascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/a. |
| 82 | got.Rotatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Rotate().(&got, mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Piscip-go gomod github.com/golang/go/src go1.24.0 math/Pi./2) |
| 83 | if !got.Eqscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Eq().(&want, 0.01) { |
| 84 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("rotate π: got %s want %s", got, want) |
| 85 | } |
| 86 | |
| 87 | want = ascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/a. |
| 88 | got = ascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/a. |
| 89 | got.Rotatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Rotate().(&got, 2*mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Piscip-go gomod github.com/golang/go/src go1.24.0 math/Pi.) |
| 90 | if !got.Eqscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Eq().(&want, 0.01) { |
| 91 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("rotate 2π: got %s want %s", got, want) |
| 92 | } |
| 93 | |
| 94 | got = ascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/a. |
| 95 | got.Rotatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Rotate().(&got, mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Piscip-go gomod github.com/golang/go/src go1.24.0 math/Pi.) |
| 96 | got.Rotatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Rotate().(&got, mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Piscip-go gomod github.com/golang/go/src go1.24.0 math/Pi.) |
| 97 | if !got.Eqscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Eq().(&want, 0.01) { |
| 98 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("rotate π then π: got %s want %s", got, want) |
| 99 | } |
| 100 | |
| 101 | got = ascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/a. |
| 102 | got.Rotatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Rotate().(&got, mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Piscip-go gomod github.com/golang/go/src go1.24.0 math/Pi./3) |
| 103 | got.Rotatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Rotate().(&got, -mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Piscip-go gomod github.com/golang/go/src go1.24.0 math/Pi./3) |
| 104 | if !got.Eqscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Eq().(&want, 0.01) { |
| 105 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("rotate π/3 then -π/3: got %s want %s", got, want) |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | func TestAffineScaleTranslatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/TestAffineScaleTranslate().(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#) { |
| 110 | mulVec := func(m *Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#, v [2]float32) (mv [2]float32) { |
| 111 | mv[0] = m[0][0]*v[0] + m[0][1]*v[1] + m[0][2] |
| 112 | mv[1] = m[1][0]*v[0] + m[1][1]*v[1] + m[1][2] |
| 113 | return mv |
| 114 | } |
| 115 | v := [2]float32{1, 10} |
| 116 | |
| 117 | var sThenT Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine# |
| 118 | sThenT.Identityscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Identity().() |
| 119 | sThenT.Scalescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Scale().(&sThenT, 13, 17) |
| 120 | sThenT.Translatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Translate().(&sThenT, 101, 151) |
| 121 | wantSTT := [2]float32{ |
| 122 | 13 * (101 + 1), |
| 123 | 17 * (151 + 10), |
| 124 | } |
| 125 | if got := mulVec(&sThenT, v); got != wantSTT { |
| 126 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("S then T: got %v, want %v", got, wantSTT) |
| 127 | } |
| 128 | |
| 129 | var tThenS Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine# |
| 130 | tThenS.Identityscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Identity().() |
| 131 | tThenS.Translatescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Translate().(&tThenS, 101, 151) |
| 132 | tThenS.Scalescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#Scale().(&tThenS, 13, 17) |
| 133 | wantTTS := [2]float32{ |
| 134 | 101 + (13 * 1), |
| 135 | 151 + (17 * 10), |
| 136 | } |
| 137 | if got := mulVec(&tThenS, v); got != wantTTS { |
| 138 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("T then S: got %v, want %v", got, wantTTS) |
| 139 | } |
| 140 | } |