From b4c035e2ff6053e37734a7f19fb7825a19160f3a Mon Sep 17 00:00:00 2001 From: faiface <faiface@ksp.sk> Date: Wed, 11 Jan 2017 13:16:27 +0100 Subject: [PATCH] add TrianglesContainer interface --- graphics.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/graphics.go b/graphics.go index bfcc5aa..9e7de07 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) -- GitLab