56 lines
990 B
Go
56 lines
990 B
Go
package ox
|
|
|
|
import (
|
|
"surdeus.su/core/gg"
|
|
"surdeus.su/core/gg/mx"
|
|
)
|
|
|
|
// Grouped triangles type.
|
|
type Polygon struct {
|
|
Transform
|
|
mx.Triangles
|
|
}
|
|
|
|
func (p Polygon) GetContainedPoints(
|
|
pts mx.Vectors,
|
|
) (mx.Vectors) {
|
|
return p.MakeTriangles().
|
|
GetContainedPoints(pts)
|
|
}
|
|
|
|
func (p Polygon) MakeTriangles() mx.Triangles {
|
|
m := p.Transform.GetMatrice()
|
|
ret := make(mx.Triangles, len(p.Triangles))
|
|
for i, t := range p.Triangles {
|
|
ret[i] = mx.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()
|
|
}
|
|
|
|
var _ = gg.Drawer(&DrawablePolygon{})
|
|
// Polygon that can be drawn.
|
|
type DrawablePolygon struct {
|
|
Polygon
|
|
Drawity
|
|
}
|
|
|
|
func (p *DrawablePolygon) Draw(c gg.Context) *gg.Drawing {
|
|
tri := &DrawableTriangles{}
|
|
tri.Triangles = p.MakeTriangles()
|
|
tri.Drawity = p.Drawity
|
|
return tri.Draw(c)
|
|
}
|
|
|