change TrianglesPicture to return (pic Vec, ok bool)
This commit is contained in:
parent
77c39d03c7
commit
c1c1bae358
22
data.go
22
data.go
|
@ -11,9 +11,10 @@ import (
|
|||
// TrianglesData specifies a list of Triangles vertices with three common properties: Position,
|
||||
// Color and Texture.
|
||||
type TrianglesData []struct {
|
||||
Position Vec
|
||||
Color NRGBA
|
||||
Picture Vec
|
||||
Position Vec
|
||||
Color NRGBA
|
||||
Picture Vec
|
||||
HasPicture bool
|
||||
}
|
||||
|
||||
// MakeTrianglesData creates TrianglesData of length len initialized with default property values.
|
||||
|
@ -40,10 +41,11 @@ func (td *TrianglesData) SetLen(len int) {
|
|||
needAppend := len - td.Len()
|
||||
for i := 0; i < needAppend; i++ {
|
||||
*td = append(*td, struct {
|
||||
Position Vec
|
||||
Color NRGBA
|
||||
Picture Vec
|
||||
}{V(0, 0), NRGBA{1, 1, 1, 1}, V(-1, -1)})
|
||||
Position Vec
|
||||
Color NRGBA
|
||||
Picture Vec
|
||||
HasPicture bool
|
||||
}{V(0, 0), NRGBA{1, 1, 1, 1}, V(0, 0), false})
|
||||
}
|
||||
}
|
||||
if len < td.Len() {
|
||||
|
@ -77,7 +79,7 @@ func (td *TrianglesData) updateData(t Triangles) {
|
|||
}
|
||||
if t, ok := t.(TrianglesPicture); ok {
|
||||
for i := range *td {
|
||||
(*td)[i].Picture = t.Picture(i)
|
||||
(*td)[i].Picture, (*td)[i].HasPicture = t.Picture(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,8 +113,8 @@ func (td *TrianglesData) Color(i int) NRGBA {
|
|||
}
|
||||
|
||||
// Picture returns the picture property of i-th vertex.
|
||||
func (td *TrianglesData) Picture(i int) Vec {
|
||||
return (*td)[i].Picture
|
||||
func (td *TrianglesData) Picture(i int) (pic Vec, ok bool) {
|
||||
return (*td)[i].Picture, (*td)[i].HasPicture
|
||||
}
|
||||
|
||||
// PictureData specifies an in-memory rectangular area of NRGBA pixels and implements Picture and
|
||||
|
|
|
@ -97,7 +97,7 @@ type TrianglesColor interface {
|
|||
// Note that this represents picture coordinates, not an actual picture.
|
||||
type TrianglesPicture interface {
|
||||
Triangles
|
||||
Picture(i int) Vec
|
||||
Picture(i int) (pic Vec, ok bool)
|
||||
}
|
||||
|
||||
// Picture represents a rectangular area of raster data, such as a color. It has Bounds which
|
||||
|
|
Loading…
Reference in New Issue