Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions objects/numbersmoother.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var (
// because arrays can't be constant
posRounded = []string{"posX", "posY", "posZ"}
rotRounded = []string{"rotX", "rotY", "rotZ"}
colorRounded = []string{"b", "g", "r"}
colorRounded = []string{"b", "g", "r", "a"}
)

func roundFloat(val float64, precision uint) float64 {
Expand All @@ -26,7 +26,7 @@ func Smooth(objraw interface{}) interface{} {
for _, key := range posRounded {
if val, ok := obj[key]; ok {
if fl, ok := val.(float64); ok {
obj[key] = roundFloat(fl, 2)
obj[key] = roundFloat(fl, 3)
}
}
}
Expand Down
41 changes: 40 additions & 1 deletion objects/numbersmoother_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestPosition(t *testing.T) {
want := map[string]interface{}{
"posX": 42.41,
"posY": 1.5,
"posZ": -11.36,
"posZ": -11.355,
}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("want != got:\n%v\n", diff)
Expand All @@ -39,3 +39,42 @@ func TestDegree(t *testing.T) {
t.Errorf("want != got:\n%v\n", diff)
}
}

func TestColor(t *testing.T) {
j := map[string]interface{}{
"r": 0.42513,
"g": 0.333333333,
"b": 0.914525304,
"a": 0.5,
}
got := Smooth(j)
want := map[string]interface{}{
"r": 0.42513,
"g": 0.33333,
"b": 0.91453,
"a": 0.5,
}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("want != got:\n%v\n", diff)
}
}

func TestColorTransparent(t *testing.T) {
j := map[string]interface{}{
"r": 1.0,
"g": 1.0,
"b": 1.0,
"a": 0,
}
got := Smooth(j)
want := map[string]interface{}{
"r": 1.0,
"g": 1.0,
"b": 1.0,
"a": 0,
}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("want != got:\n%v\n", diff)
}
}