diff --git a/graphics.go b/graphics.go index bfcc5aad19814af16db70b78fdb2618c815a60db..9e7de07c2d3ea87533671d13fbf9fd1ae0e25111 100644 --- a/graphics.go +++ b/graphics.go @@ -5,6 +5,15 @@ import ( "image/color" ) +// TrianglesContainer is an extension of Triangles that can accumulate Triangles inside of it using +// the Append method. +type TrianglesContainer interface { + Triangles + + // Append adds supplied Triangles to the end of the TrianglesContainer. + Append(Triangles) +} + // TrianglesData specifies a list of Triangles vertices with three common properties: Position, // Color and Texture. type TrianglesData []struct { @@ -72,6 +81,13 @@ func (td *TrianglesData) Update(t Triangles) { } } +// Append adds supplied Triangles to the end of the TrianglesData. +func (td *TrianglesData) Append(t Triangles) { + newTd := make(TrianglesData, t.Len()) + newTd.Update(t) + *td = append(*td, newTd...) +} + // Position returns the position property of i-th vertex. func (td *TrianglesData) Position(i int) Vec { return (*td)[i].Position @@ -105,6 +121,11 @@ func (td *TrianglesColorData) Update(t Triangles) { (*TrianglesData)(td).Update(t) } +// Append adds supplied Triangles to the end of the TrianglesColorData. +func (td *TrianglesColorData) Append(t Triangles) { + (*TrianglesData)(td).Append(t) +} + // Position returns the position property of i-th vertex. func (td *TrianglesColorData) Position(i int) Vec { return (*TrianglesData)(td).Position(i) @@ -133,6 +154,11 @@ func (td *TrianglesTextureData) Update(t Triangles) { (*TrianglesData)(td).Update(t) } +// Append adds supplied Triangles to the end of the TrianglesTextureData. +func (td *TrianglesTextureData) Append(t Triangles) { + (*TrianglesData)(td).Append(t) +} + // Position returns the position property of i-th vertex. func (td *TrianglesTextureData) Position(i int) Vec { return (*TrianglesData)(td).Position(i)