reorganized the project
This commit is contained in:
@@ -15,10 +15,6 @@ const (
|
||||
buildingSizePercentStep = 0.5
|
||||
)
|
||||
|
||||
func averageImageDimension(width, height int) float64 {
|
||||
return (float64(width) + float64(height)) / 2.0
|
||||
}
|
||||
|
||||
func clampBuildingSizePercent(v float64) float64 {
|
||||
if v < minBuildingSizePercent {
|
||||
return minBuildingSizePercent
|
||||
@@ -353,65 +349,6 @@ func getProceduralBuildingPixels(center image.Point, size float64, settings *Set
|
||||
return finalPixels, true
|
||||
}
|
||||
|
||||
// scalePixels scales the building to the final size.
|
||||
func scalePixels(pixels []image.Point, finalSize float64) []image.Point {
|
||||
if len(pixels) == 0 {
|
||||
return pixels
|
||||
}
|
||||
|
||||
minX, minY := pixels[0].X, pixels[0].Y
|
||||
maxX, maxY := pixels[0].X, pixels[0].Y
|
||||
for _, p := range pixels {
|
||||
if p.X < minX {
|
||||
minX = p.X
|
||||
}
|
||||
if p.Y < minY {
|
||||
minY = p.Y
|
||||
}
|
||||
if p.X > maxX {
|
||||
maxX = p.X
|
||||
}
|
||||
if p.Y > maxY {
|
||||
maxY = p.Y
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the current dimensions
|
||||
currentWidth := float64(maxX - minX)
|
||||
currentHeight := float64(maxY - minY)
|
||||
|
||||
scale := finalSize / math.Max(currentWidth, currentHeight)
|
||||
|
||||
// Calculate the center of the bounding box
|
||||
centerX := float64(minX) + currentWidth/2
|
||||
centerY := float64(minY) + currentHeight/2
|
||||
|
||||
// Scale and translate the pixels
|
||||
var scaledPixels []image.Point
|
||||
pixelMap := make(map[image.Point]bool) // To avoid duplicate pixels
|
||||
for _, p := range pixels {
|
||||
// Translate to origin
|
||||
translatedX := float64(p.X) - centerX
|
||||
translatedY := float64(p.Y) - centerY
|
||||
|
||||
// Scale
|
||||
scaledX := translatedX * scale
|
||||
scaledY := translatedY * scale
|
||||
|
||||
// Translate back to the center
|
||||
finalX := int(math.Round(scaledX + centerX))
|
||||
finalY := int(math.Round(scaledY + centerY))
|
||||
|
||||
newPoint := image.Point{X: finalX, Y: finalY}
|
||||
if !pixelMap[newPoint] {
|
||||
scaledPixels = append(scaledPixels, newPoint)
|
||||
pixelMap[newPoint] = true
|
||||
}
|
||||
}
|
||||
|
||||
return scaledPixels
|
||||
}
|
||||
|
||||
// getComponentPixels generates the pixels for a single shape component without collision checks.
|
||||
func getComponentPixels(center image.Point, size float64, shape string, randSrc *rand.Rand) ([]image.Point, bool) {
|
||||
var pixels []image.Point
|
||||
@@ -564,16 +501,6 @@ func getBuildingPixels(center image.Point, size float64, shape string, waterMask
|
||||
return pixels, true
|
||||
}
|
||||
|
||||
// isPixelInSlice checks if a pixel is already in a slice of pixels.
|
||||
func isPixelInSlice(pixel image.Point, pixelSlice []image.Point) bool {
|
||||
for _, p := range pixelSlice {
|
||||
if p == pixel {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
u8BufferPool = sync.Pool{
|
||||
New: func() any { return make([]uint8, 0) },
|
||||
|
||||
Reference in New Issue
Block a user