package cn.sagacloud.server.algorithm.test

import cn.sagacloud.server.algorithm.models.jsonAnalyzer.Point
import cn.sagacloud.server.algorithm.services.CommonService
import org.junit.Test

class GeomTest{

    @Test
    fun testIsPointInPolygon(){
        val point = Point(1.0, 0.999999999, .0)

        val polygon = arrayListOf(
                Point(.0, .0, .0),
                Point(.0, 1.0, .0),
                Point(1.0, 3.0, .0),
                Point(2.0, 1.0, .0),
                Point(2.0, .0, .0),
                Point(1.0, 1.0, .0)
        )
        print(CommonService.isPointInPolygonCheckWithJdkGeneralPath(point, polygon))
    }


    @Test
    fun testIsPolygonOverlap(){
        val polygon1 = arrayListOf(
                Point(.5, .0, .0),
                Point(.5, .4, .0),
                Point(1.5, .4, .0),
                Point(1.5, .0, .0)
        )

        val polygon2 = arrayListOf(
                Point(.5, .0, .0),
                Point(.5, .5, .0),
                Point(1.5, .5, .0),
                Point(1.5, .0, .0)
        )

        val polygon3 = arrayListOf(
                Point(.5, .0, .0),
                Point(.5, .6, .0),
                Point(1.5, .6, .0),
                Point(1.5, .0, .0)
        )

        val polygon4 = arrayListOf(
                Point(.0, .0, .0),
                Point(.0, 1.0, .0),
                Point(1.0, 2.0, .0),
                Point(2.0, 1.0, .0),
                Point(2.0, .0, .0),
                Point(1.0, 1.0, .0)
        )

        val polygon5 = arrayListOf(
                Point(.0, .0, .0),
                Point(.0, 1.0, .0),
                Point(1.0, 2.0, .0),
                Point(2.0, 1.0, .0),
                Point(2.0, .0, .0),
                Point(1.0, 1.0, .0)
        )
        val polygon6 = arrayListOf(
                Point(.0, 1.0, .0),
                Point(1.0, 2.0, .0),
                Point(2.0, 1.0, .0),
                Point(2.0, .0, .0),
                Point(1.0, 1.0, .0)
        )
        val polygon7 = arrayListOf(
                Point(.5, 1.0, .0),
                Point(.5, 1.5, .0),
                Point(1.5, 1.5, .0),
                Point(1.5, 1.0, .0)
        )
        println(CommonService.isPolygonOverlap(polygon1, polygon5))
        println(CommonService.isPolygonOverlap(polygon1, polygon2))
        println(CommonService.isPolygonOverlap(polygon2, polygon5))
        println(CommonService.isPolygonOverlap(polygon3, polygon5))
        println(CommonService.isPolygonOverlap(polygon4, polygon5))
        println(CommonService.isPolygonOverlap(polygon5, polygon5))
        println(CommonService.isPolygonOverlap(polygon6, polygon5))
        println(CommonService.isPolygonOverlap(polygon7, polygon5))
    }
}
