gg/polygon.go

49 lines
750 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) ContainsPoint(pnt Point) bool {
2023-12-23 00:09:07 +03:00
return p.MakeTriangles().ContainsPoint(pnt)
}
2023-06-20 14:04:55 +03:00
// Polygon that can be drawn.
2023-06-15 20:18:58 +03:00
type DrawablePolygon struct {
Polygon
2023-06-20 14:04:55 +03:00
2023-06-15 20:18:58 +03:00
ShaderOptions
2023-06-20 14:04:55 +03:00
Visibility
Colority
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
}
func (p *DrawablePolygon) Draw(c *Context) {
2023-06-20 14:04:55 +03:00
(&DrawableTriangles{
Visibility: p.Visibility,
Colority: p.Colority,
ShaderOptions: p.ShaderOptions,
Triangles: p.MakeTriangles(),
}).Draw(c)
2023-06-10 17:43:04 +03:00
}