package de.arxsilex.maptools.converter.core

import kotlin.math.PI
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class MapSelectionShapeTest {
    @Test
    fun `circle contains points by radius and excludes outer points`() {
        val circle = GeoCircleRegion(50.0, 8.0, 5.0)

        assertTrue(circle.contains(50.0, 8.0))
        assertTrue(circle.contains(50.03, 8.0))
        assertFalse(circle.contains(50.10, 8.0))
    }

    @Test
    fun `duplicate circles are counted once in union area`() {
        val circle = GeoCircleRegion(50.0, 8.0, 10.0)
        val union = listOf(circle, circle).unionAreaSquareKilometers()

        assertEquals(PI * 100.0, union, 0.8)
    }

    @Test
    fun `normalized circle converts back to geographic center`() {
        val source = GeoBounds(7.0, 49.0, 9.0, 51.0)
        val circle = CircleSelection(0.5f, 0.5f, 3.0).toGeoRegion(source) as GeoCircleRegion

        assertEquals(50.0, circle.centerLatitude, 0.000_001)
        assertEquals(8.0, circle.centerLongitude, 0.000_001)
        assertEquals(3.0, circle.radiusKilometers)
    }
}
