-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathsprite_transform_direction_test.go
More file actions
74 lines (64 loc) · 1.98 KB
/
Copy pathsprite_transform_direction_test.go
File metadata and controls
74 lines (64 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright (c) 2021 The XGo Authors (xgo.dev). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package spx
import (
"math"
"testing"
coreproject "github.com/goplus/spx/v2/internal/core/project"
)
func newTestTransformSprite(x, y float64) *SpriteImpl {
sprite := &SpriteImpl{
g: &Game{},
name: "TestSprite",
}
sprite.components.initComponents(sprite, &coreproject.SpriteConfig{
X: x,
Y: y,
RotationStyle: "normal",
FAnimations: map[SpriteAnimationName]*coreproject.AniConfig{},
AnimBindings: map[string]string{},
})
return sprite
}
func TestSpriteDirectionToPosNormalizesAngle(t *testing.T) {
sprite := newTestTransformSprite(0, 0)
tests := []struct {
name string
x float64
y float64
want Direction
}{
{name: "right", x: 10, y: 0, want: 90},
{name: "up", x: 0, y: 10, want: 0},
{name: "left", x: -10, y: 0, want: -90},
{name: "down", x: 0, y: -10, want: 180},
{name: "bottom left stays normalized", x: -10, y: -10, want: -135},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := sprite.DirectionTo__4(tt.x, tt.y); math.Abs(got-tt.want) > 1e-9 {
t.Fatalf("DirectionTo__4(%v, %v) = %v, want %v", tt.x, tt.y, got, tt.want)
}
})
}
}
func TestSpriteTurnToXYposFacesCoordinateTarget(t *testing.T) {
sprite := newTestTransformSprite(0, 0)
sprite.TurnToXYpos(-10, -10, nil)
if got := sprite.Heading(); got != -135 {
t.Fatalf("Heading() = %v, want -135", got)
}
}