package de.arxsilex.maptools.converter.core

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class GeoSelectionMetricsTest {
    @Test
    fun `calculates plausible rectangle dimensions and center`() {
        val metrics = GeoBounds(8.0, 50.0, 8.1, 50.1).rectangleMetrics()

        assertEquals(50.05, metrics.centerLatitude, 0.000_001)
        assertEquals(8.05, metrics.centerLongitude, 0.000_001)
        assertTrue(metrics.widthKilometers in 7.0..7.3)
        assertTrue(metrics.heightKilometers in 11.0..11.2)
        assertTrue(metrics.areaSquareKilometers in 79.0..80.5)
    }

    @Test
    fun `overlapping rectangles are counted only once in geographic union`() {
        val full = GeoBounds(8.0, 50.0, 8.2, 50.2)
        val overlapping = listOf(
            full.subset(NormalizedMapArea(0f, 0f, 0.75f, 1f)),
            full.subset(NormalizedMapArea(0.25f, 0f, 1f, 1f)),
        )

        assertEquals(
            full.rectangleMetrics().areaSquareKilometers,
            overlapping.unionAreaSquareKilometers(),
            0.000_001,
        )
    }
}
