Close shape if not closed in ComplexPolygon GetShape()

This commit is contained in:
DataHoarder 2023-12-02 02:33:50 +01:00
parent 485b49f4cf
commit 05c31ff74c
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk

View file

@ -32,9 +32,10 @@ func (p ComplexPolygon) GetShape() (r Shape) {
panic(err)
}
for _, contour := range p.Pol {
start := math.NewVector2(contour[0].X, contour[0].Y)
r = append(r, records.LineRecord{
To: math.NewVector2(contour[1].X, contour[1].Y),
Start: math.NewVector2(contour[0].X, contour[0].Y),
Start: start,
})
for _, point := range contour[2:] {
r = append(r, records.LineRecord{
@ -42,6 +43,13 @@ func (p ComplexPolygon) GetShape() (r Shape) {
Start: r[len(r)-1].GetEnd(),
})
}
if !r[len(r)-1].GetEnd().Equals(start) { //not closed
r = append(r, records.LineRecord{
To: start,
Start: r[len(r)-1].GetEnd(),
})
}
}
return r
}