-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix coordinate mapping in ScreenToGLCoords and GLToScreenCoords
Fixes #64.
- Loading branch information
1 parent
0626298
commit 400add2
Showing
4 changed files
with
132 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2018 The go-gl Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file.package mgl64_test | ||
|
||
package mgl32 | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestScreenToGLCoords(t *testing.T) { | ||
// use a small screen size in order to minimize errors due to fp rounding. | ||
const ( | ||
sw = 100 | ||
sh = 100 | ||
) | ||
x, y := ScreenToGLCoords(0, sh-1, sw, sh) | ||
if x != -1 { | ||
t.Errorf("x = %f, expected -1.0", x) | ||
} | ||
if y != -1 { | ||
t.Errorf("y = %f, expected -1.0", y) | ||
} | ||
|
||
x, y = ScreenToGLCoords(sw-1, 0, sw, sh) | ||
if x != 1 { | ||
t.Errorf("x = %f, expected 1.0", x) | ||
} | ||
if y != 1 { | ||
t.Errorf("y = %f, expected 1.0", y) | ||
} | ||
} | ||
|
||
func TestGLToScreenCoords(t *testing.T) { | ||
const ( | ||
sw = 100 | ||
sh = 100 | ||
) | ||
x, y := GLToScreenCoords(-1, -1, sw, sh) | ||
if x != 0 { | ||
t.Errorf("x = %d, expected 0", x) | ||
} | ||
if y != sh-1 { | ||
t.Errorf("y = %d, expected %d", y, sh-1) | ||
} | ||
|
||
x, y = GLToScreenCoords(1, 1, sw, sh) | ||
if x != sw-1 { | ||
t.Errorf("x = %d, expected %d", x, sw-1) | ||
} | ||
if y != 0 { | ||
t.Errorf("y = %d, expected 0", y) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// This file is generated from mgl32/shapes_test.go; DO NOT EDIT | ||
|
||
// Copyright 2018 The go-gl Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file.package mgl64_test | ||
|
||
package mgl64 | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestScreenToGLCoords(t *testing.T) { | ||
// use a small screen size in order to minimize errors due to fp rounding. | ||
const ( | ||
sw = 100 | ||
sh = 100 | ||
) | ||
x, y := ScreenToGLCoords(0, sh-1, sw, sh) | ||
if x != -1 { | ||
t.Errorf("x = %f, expected -1.0", x) | ||
} | ||
if y != -1 { | ||
t.Errorf("y = %f, expected -1.0", y) | ||
} | ||
|
||
x, y = ScreenToGLCoords(sw-1, 0, sw, sh) | ||
if x != 1 { | ||
t.Errorf("x = %f, expected 1.0", x) | ||
} | ||
if y != 1 { | ||
t.Errorf("y = %f, expected 1.0", y) | ||
} | ||
} | ||
|
||
func TestGLToScreenCoords(t *testing.T) { | ||
const ( | ||
sw = 100 | ||
sh = 100 | ||
) | ||
x, y := GLToScreenCoords(-1, -1, sw, sh) | ||
if x != 0 { | ||
t.Errorf("x = %d, expected 0", x) | ||
} | ||
if y != sh-1 { | ||
t.Errorf("y = %d, expected %d", y, sh-1) | ||
} | ||
|
||
x, y = GLToScreenCoords(1, 1, sw, sh) | ||
if x != sw-1 { | ||
t.Errorf("x = %d, expected %d", x, sw-1) | ||
} | ||
if y != 0 { | ||
t.Errorf("y = %d, expected 0", y) | ||
} | ||
} |