gg/polygon.go

46 lines
721 B
Go
Raw Normal View History

2023-10-23 15:45:18 +03:00
package gg
2023-06-03 22:41:00 +03:00
2023-06-20 14:04:55 +03:00
import (
)
// Grouped triangles type.
2023-06-15 20:18:58 +03:00
type Polygon struct {
Object
2023-06-15 20:18:58 +03:00
Transform
2023-06-20 14:04:55 +03:00
Triangles
2023-06-10 17:43:04 +03:00
}
func (p Polygon) ContainedPoints(pts Points) (Points) {
return p.MakeTriangles().ContainedPoints(pts)
2023-06-10 17:43:04 +03:00
}
func (p Polygon) MakeTriangles() Triangles {
m := p.Matrix()
2023-06-20 14:04:55 +03:00
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),
}
2023-06-10 17:43:04 +03:00
}
2023-06-20 14:04:55 +03:00
2023-06-03 22:41:00 +03:00
return ret
}
// Polygon that can be drawn.
type DrawablePolygon struct {
Polygon
ShaderOptions
Visibility
Colority
}
func (p *DrawablePolygon) Draw(c *Context) []EVertex {
return (&DrawableTriangles{
2023-06-20 14:04:55 +03:00
Colority: p.Colority,
Triangles: p.MakeTriangles(),
}).MakeEVertices(c)
2023-06-10 17:43:04 +03:00
}