gg/ox/polygon.go
2024-05-28 13:24:12 +05:00

58 lines
1,000 B
Go

package ox
import (
"surdeus.su/core/gg"
"surdeus.su/core/gg/mx"
)
// Grouped triangles type.
type Polygon struct {
ObjectImpl
Transform
mx.Triangles
}
func (p Polygon) ContainedPoints(pts Points) (Points) {
return p.MakeTriangles().ContainedPoints(pts)
}
func (p Polygon) MakeTriangles() Triangles {
m := p.Transform.GetMatrice()
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) GetVertices() mx.Vectors {
return p.MakeTriangles().GetVertices()
}
func (p Polygon) GetEdges() mx.Lines {
return p.MakeTriangles().GetEdges()
}
// Polygon that can be drawn.
type DrawablePolygon struct {
Polygon
ShaderOptions
Visibility
Colority
}
func (p *DrawablePolygon) Draw(c *Context) gg.Drawing {
ret := gg.Drawing{
EVertices: (&DrawableTriangles{
Colority: p.Colority,
Triangles: p.MakeTriangles(),
}).MakeEVertices(c),
}
return ret
}