reorganized the project

This commit is contained in:
grimsace
2026-03-12 12:22:09 -05:00
parent c0382d6657
commit 302a9aaf74
10 changed files with 2657 additions and 2782 deletions
+9 -76
View File
@@ -91,13 +91,13 @@ func getTurretSizePixels(settings *Settings, width, height int) float64 {
// GateInfo describes a single gate in a wall ring.
type GateInfo struct {
WallID int
Center image.Point // midpoint of the gap
Normal [2]float64 // outward normal (perpendicular to wall, pointing outward)
LeftTurret image.Point // turret on the left side of the road
RightTurret image.Point // turret on the right side of the road
InnerEnd image.Point // road endpoint just inside the wall
OuterEnd image.Point // road endpoint just outside the wall
WallID int
Center image.Point // midpoint of the gap
Normal [2]float64 // outward normal (perpendicular to wall, pointing outward)
LeftTurret image.Point // turret on the left side of the road
RightTurret image.Point // turret on the right side of the road
InnerEnd image.Point // road endpoint just inside the wall
OuterEnd image.Point // road endpoint just outside the wall
}
type FortificationLayout struct {
@@ -255,7 +255,7 @@ func computeGatesForLayout(
gateCenter := bpts[i].p
// Estimate wall tangent and normal at this point.
tx, ty, ok := fortEstimateWallTangent(gateCenter, layout.Mask)
tx, ty, ok := estimateWallTangent(gateCenter, layout.Mask)
if !ok {
continue
}
@@ -658,15 +658,6 @@ func drawSegmentSelective(x0, y0, x1, y1 int, plot func(x, y int)) {
}
}
func cloneMask(src *PixelMask) *PixelMask {
if src == nil {
return nil
}
dst := NewPixelMask(src.Width, src.Height)
copy(dst.Data, src.Data)
return dst
}
func drawWallMask(img *image.RGBA, wallMask *PixelMask) {
if img == nil || wallMask == nil {
return
@@ -792,7 +783,7 @@ func GenerateTurrets(
continue
}
for _, g := range gates {
tx, ty, ok := fortEstimateWallTangent(g, layout.Mask)
tx, ty, ok := estimateWallTangent(g, layout.Mask)
if !ok {
continue
}
@@ -855,18 +846,6 @@ func touchesWater(x, y int, waterMask *PixelMask) bool {
return false
}
func averagePoint(points []image.Point) image.Point {
if len(points) == 0 {
return image.Point{}
}
var sx, sy int
for _, p := range points {
sx += p.X
sy += p.Y
}
return image.Point{X: sx / len(points), Y: sy / len(points)}
}
func drawTurret(img *image.RGBA, mask *PixelMask, center image.Point, radius int, shape string, col color.RGBA) {
for dy := -radius; dy <= radius; dy++ {
for dx := -radius; dx <= radius; dx++ {
@@ -1029,49 +1008,3 @@ func roadGateCentersForRoad(r *Road, layout *FortificationLayout) []image.Point
}
return out
}
func fortEstimateWallTangent(mid image.Point, wallMask *PixelMask) (float64, float64, bool) {
if wallMask == nil {
return 0, 0, false
}
const r = 4
var pts [][2]float64
for dy := -r; dy <= r; dy++ {
y := mid.Y + dy
if y < 0 || y >= wallMask.Height {
continue
}
for dx := -r; dx <= r; dx++ {
x := mid.X + dx
if x < 0 || x >= wallMask.Width {
continue
}
if wallMask.GetXY(x, y) {
pts = append(pts, [2]float64{float64(x), float64(y)})
}
}
}
if len(pts) < 3 {
return 0, 0, false
}
var mx, my float64
for _, p := range pts {
mx += p[0]
my += p[1]
}
mx /= float64(len(pts))
my /= float64(len(pts))
var sxx, syy, sxy float64
for _, p := range pts {
dx := p[0] - mx
dy := p[1] - my
sxx += dx * dx
syy += dy * dy
sxy += dx * dy
}
if sxx+syy < 0.001 {
return 0, 0, false
}
theta := 0.5 * math.Atan2(2*sxy, sxx-syy)
return math.Cos(theta), math.Sin(theta), true
}