package de.arxsilex.maptools.converter.core

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

class MapAreaSelectionTest {
    @Test
    fun `computes envelope and union area without counting overlaps twice`() {
        val selection = MapAreaSelection(
            listOf(
                NormalizedMapArea(0f, 0f, 0.5f, 0.5f),
                NormalizedMapArea(0.25f, 0.25f, 0.75f, 0.75f),
            ),
        )

        assertEquals(NormalizedMapArea(0f, 0f, 0.75f, 0.75f), selection.envelope)
        assertEquals(0.4375f, selection.areaFraction)
    }

    @Test
    fun `maps all normalized rectangles to geographic bounds`() {
        val source = GeoBounds(10.0, 40.0, 20.0, 50.0)
        val result = source.subsets(
            MapAreaSelection(
                listOf(
                    NormalizedMapArea(0f, 0f, 0.5f, 0.5f),
                    NormalizedMapArea(0.5f, 0.5f, 1f, 1f),
                ),
            ),
        )

        assertEquals(
            listOf(GeoBounds(10.0, 45.0, 15.0, 50.0), GeoBounds(15.0, 40.0, 20.0, 45.0)),
            result,
        )
    }
}
