package ru.dbotthepony.kstarbound.defs.world

import ru.dbotthepony.kstarbound.json.builder.JsonFactory
import java.util.random.RandomGenerator
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.sin

@JsonFactory
data class TerrainSelectorParameters(
	val worldWidth: Int,
	val baseHeight: Double,
	val worldHeight: Int = 0,
	val seed: Long = 0L,
	val commonality: Double = 1.0
) {
	fun withSeed(seed: Long) = copy(seed = seed)
	fun withCommonality(commonality: Double) = copy(commonality = commonality)

	fun random(): RandomGenerator {
		return ru.dbotthepony.kstarbound.util.random.random(seed)
	}

	fun noiseAngle(x: Int): Pair<Double, Double> {
		val noiseAngle = (2.0 * PI * x) / worldWidth
		val noiseX = (cos(noiseAngle) * worldWidth) / (2.0 * PI)
		val noiseY = (sin(noiseAngle) * worldWidth) / (2.0 * PI)

		return noiseX to noiseY
	}
}
