gg/ox/polygon.go

59 lines
1,000 B
Go
Raw Normal View History

2024-05-28 11:24:12 +03:00
package ox
2023-06-03 22:41:00 +03:00
2023-06-20 14:04:55 +03:00
import (
2024-05-28 11:24:12 +03:00
"surdeus.su/core/gg"
"surdeus.su/core/gg/mx"
2023-06-20 14:04:55 +03:00
)
// Grouped triangles type.
2023-06-15 20:18:58 +03:00
type Polygon struct {
2024-05-28 11:24:12 +03:00
ObjectImpl
2023-06-15 20:18:58 +03:00
Transform
2024-05-28 11:24:12 +03:00
mx.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 {
2024-05-28 11:24:12 +03:00
m := p.Transform.GetMatrice()
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-05-28 11:24:12 +03:00
func (p Polygon) GetVertices() mx.Vectors {
return p.MakeTriangles().GetVertices()
}
2024-05-28 11:24:12 +03:00
func (p Polygon) GetEdges() mx.Lines {
return p.MakeTriangles().GetEdges()
}
// Polygon that can be drawn.
type DrawablePolygon struct {
Polygon
ShaderOptions
Visibility
Colority
}
2024-05-28 11:24:12 +03:00
func (p *DrawablePolygon) Draw(c *Context) gg.Drawing {
ret := gg.Drawing{
EVertices: (&DrawableTriangles{
Colority: p.Colority,
Triangles: p.MakeTriangles(),
}).MakeEVertices(c),
}
return ret
2023-06-10 17:43:04 +03:00
}