gg/polygon.go

52 lines
869 B
Go

package gg
import (
)
// Grouped triangles type.
type Polygon struct {
Object
Transform
Triangles
}
func (p Polygon) ContainedPoints(pts Points) (Points) {
return p.MakeTriangles().ContainedPoints(pts)
}
func (p Polygon) MakeTriangles() Triangles {
m := p.Matrix()
ret := make(Triangles, len(p.Triangles))
for i, t := range p.Triangles {
ret[i] = Triangle{
t[0].Apply(m),
t[1].Apply(m),
t[2].Apply(m),
}
}
return ret
}
func (p Polygon) Vertices() Vertices {
return p.MakeTriangles().Vertices()
}
func (p Polygon) Edges() Edges {
return p.MakeTriangles().Edges()
}
// Polygon that can be drawn.
type DrawablePolygon struct {
Polygon
ShaderOptions
Visibility
Colority
}
func (p *DrawablePolygon) Draw(c *Context) []EVertex {
return (&DrawableTriangles{
Colority: p.Colority,
Triangles: p.MakeTriangles(),
}).MakeEVertices(c)
}