Hide matrix members

This commit is contained in:
Hajime Hoshi 2014-12-24 23:26:04 +09:00
parent 494d07387d
commit cb510fafa7
3 changed files with 10 additions and 18 deletions

View File

@ -28,7 +28,7 @@ const ColorMatrixDim = 5
// Before applying a matrix, a color is un-multiplied, and after applying the matrix, // Before applying a matrix, a color is un-multiplied, and after applying the matrix,
// the color is multiplied again. // the color is multiplied again.
type ColorMatrix struct { type ColorMatrix struct {
Elements [ColorMatrixDim - 1][ColorMatrixDim]float64 es [ColorMatrixDim - 1][ColorMatrixDim]float64
} }
// ColorMatrixI returns an identity color matrix. // ColorMatrixI returns an identity color matrix.
@ -49,7 +49,7 @@ func (c *ColorMatrix) dim() int {
// Element returns a value of a matrix at (i, j). // Element returns a value of a matrix at (i, j).
func (c *ColorMatrix) Element(i, j int) float64 { func (c *ColorMatrix) Element(i, j int) float64 {
return c.Elements[i][j] return c.es[i][j]
} }
// Concat multiplies a color matrix with the other color matrix. // Concat multiplies a color matrix with the other color matrix.
@ -65,7 +65,7 @@ func (c *ColorMatrix) IsIdentity() bool {
} }
func (c *ColorMatrix) setElement(i, j int, element float64) { func (c *ColorMatrix) setElement(i, j int, element float64) {
c.Elements[i][j] = element c.es[i][j] = element
} }
// Monochrome returns a color matrix to make an image monochrome. // Monochrome returns a color matrix to make an image monochrome.

View File

@ -23,7 +23,7 @@ const GeometryMatrixDim = 3
// A GeometryMatrix represents a matrix to transform geometry when rendering an image. // A GeometryMatrix represents a matrix to transform geometry when rendering an image.
type GeometryMatrix struct { type GeometryMatrix struct {
Elements [GeometryMatrixDim - 1][GeometryMatrixDim]float64 es [GeometryMatrixDim - 1][GeometryMatrixDim]float64
} }
// GeometryMatrixI returns an identity geometry matrix. // GeometryMatrixI returns an identity geometry matrix.
@ -42,7 +42,7 @@ func (g *GeometryMatrix) dim() int {
// Element returns a value of a matrix at (i, j). // Element returns a value of a matrix at (i, j).
func (g *GeometryMatrix) Element(i, j int) float64 { func (g *GeometryMatrix) Element(i, j int) float64 {
return g.Elements[i][j] return g.es[i][j]
} }
// Concat multiplies a geometry matrix with the other geometry matrix. // Concat multiplies a geometry matrix with the other geometry matrix.
@ -58,7 +58,7 @@ func (g *GeometryMatrix) IsIdentity() bool {
} }
func (g *GeometryMatrix) setElement(i, j int, element float64) { func (g *GeometryMatrix) setElement(i, j int, element float64) {
g.Elements[i][j] = element g.es[i][j] = element
} }
// ScaleGeometry returns a matrix that scales a geometry matrix by (x, y). // ScaleGeometry returns a matrix that scales a geometry matrix by (x, y).

View File

@ -29,16 +29,8 @@ func TestGeometryIdentity(t *testing.T) {
} }
func TestGeometryConcat(t *testing.T) { func TestGeometryConcat(t *testing.T) {
matrix1 := GeometryMatrix{} matrix1 := ScaleGeometry(2, 2)
matrix2 := GeometryMatrix{} matrix2 := TranslateGeometry(1, 1)
matrix1.Elements = [2][3]float64{
{2, 0, 0},
{0, 2, 0},
}
matrix2.Elements = [2][3]float64{
{1, 0, 1},
{0, 1, 1},
}
matrix3 := matrix1 matrix3 := matrix1
matrix3.Concat(matrix2) matrix3.Concat(matrix2)
@ -48,7 +40,7 @@ func TestGeometryConcat(t *testing.T) {
} }
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
for j := 0; j < 3; j++ { for j := 0; j < 3; j++ {
got := matrix3.Elements[i][j] got := matrix3.Element(i, j)
want := expected[i][j] want := expected[i][j]
if want != got { if want != got {
t.Errorf("matrix3.Element(%d, %d) = %f,"+ t.Errorf("matrix3.Element(%d, %d) = %f,"+
@ -66,7 +58,7 @@ func TestGeometryConcat(t *testing.T) {
} }
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
for j := 0; j < 3; j++ { for j := 0; j < 3; j++ {
got := matrix4.Elements[i][j] got := matrix4.Element(i, j)
want := expected[i][j] want := expected[i][j]
if want != got { if want != got {
t.Errorf("matrix4.Element(%d, %d) = %f, want %f", t.Errorf("matrix4.Element(%d, %d) = %f, want %f",