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 {
|
2024-01-08 06:09:36 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-01-08 02:53:00 +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
|
|
|
}
|
|
|
|
|
2024-01-08 02:53:00 +03:00
|
|
|
func (p Polygon) MakeTriangles() Triangles {
|
2023-12-26 23:31:04 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-01-11 06:39:57 +03:00
|
|
|
func (p *DrawablePolygon) Draw(c *Context) []EVertex {
|
|
|
|
return (&DrawableTriangles{
|
2023-06-20 14:04:55 +03:00
|
|
|
Colority: p.Colority,
|
|
|
|
Triangles: p.MakeTriangles(),
|
2024-01-11 06:39:57 +03:00
|
|
|
}).MakeEVertices(c)
|
2023-06-10 17:43:04 +03:00
|
|
|
}
|
|
|
|
|