Polygon boundary detection now rounds properly

This commit is contained in:
Sasha Koshka 2024-06-24 19:04:08 -04:00
parent 868b6fdfe9
commit 07865dc85f

View File

@ -1,6 +1,7 @@
package xcanvas package xcanvas
import "sort" import "sort"
import "math"
import "image" import "image"
import "github.com/jezek/xgbutil/xgraphics" import "github.com/jezek/xgbutil/xgraphics"
@ -181,11 +182,11 @@ func (this *pen) fillPolygon (c xgraphics.BGRA, points ...image.Point) {
(fPointY < fy && fPrevY >= fy) || (fPointY < fy && fPrevY >= fy) ||
(fPrevY < fy && fPointY >= fy) (fPrevY < fy && fPointY >= fy)
if addboundary { if addboundary {
context.boundaries[boundaryCount] = int ( context.boundaries[boundaryCount] = int(math.Round (
fPointX + fPointX +
(fy - fPointY) / (fy - fPointY) /
(fPrevY - fPointY) * (fPrevY - fPointY) *
(fPrevX - fPointX)) (fPrevX - fPointX)))
boundaryCount ++ boundaryCount ++
} }
prevPoint = point prevPoint = point