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
|
|
|
}
|
|
|
|
|
2024-06-01 16:07:28 +03:00
|
|
|
func (p Polygon) GetContainedPoints(
|
|
|
|
pts mx.Vectors,
|
|
|
|
) (mx.Vectors) {
|
|
|
|
return p.MakeTriangles().
|
|
|
|
GetContainedPoints(pts)
|
2023-06-10 17:43:04 +03:00
|
|
|
}
|
|
|
|
|
2024-06-01 16:07:28 +03:00
|
|
|
func (p Polygon) MakeTriangles() mx.Triangles {
|
2024-05-28 11:24:12 +03:00
|
|
|
m := p.Transform.GetMatrice()
|
2024-06-01 16:07:28 +03:00
|
|
|
ret := make(mx.Triangles, len(p.Triangles))
|
2023-06-20 14:04:55 +03:00
|
|
|
for i, t := range p.Triangles {
|
2024-06-01 16:07:28 +03:00
|
|
|
ret[i] = mx.Triangle{
|
2023-06-20 14:04:55 +03:00
|
|
|
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-01-22 10:23:47 +03:00
|
|
|
}
|
2024-05-28 11:24:12 +03:00
|
|
|
|
|
|
|
func (p Polygon) GetEdges() mx.Lines {
|
|
|
|
return p.MakeTriangles().GetEdges()
|
2024-01-22 10:23:47 +03:00
|
|
|
}
|
|
|
|
|
2024-06-01 16:07:28 +03:00
|
|
|
var _ = gg.Drawer(&DrawablePolygon{})
|
2024-01-16 01:08:21 +03:00
|
|
|
// Polygon that can be drawn.
|
|
|
|
type DrawablePolygon struct {
|
|
|
|
Polygon
|
2024-06-01 16:07:28 +03:00
|
|
|
|
|
|
|
Drawity
|
2024-01-16 01:08:21 +03:00
|
|
|
}
|
|
|
|
|
2024-06-01 16:07:28 +03:00
|
|
|
func (p *DrawablePolygon) Draw(c gg.Context) *gg.Drawing {
|
|
|
|
tri := &DrawableTriangles{}
|
|
|
|
tri.Triangles = p.MakeTriangles()
|
|
|
|
tri.Drawity = p.Drawity
|
|
|
|
return tri.Draw(c)
|
2023-06-10 17:43:04 +03:00
|
|
|
}
|
|
|
|
|