diff --git a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/utils/V2NUtils.kt b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/utils/V2NUtils.kt index 2e52ad28ec..af239a5731 100644 --- a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/utils/V2NUtils.kt +++ b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/utils/V2NUtils.kt @@ -8,6 +8,8 @@ import com.zhidaoauto.map.data.road.CenterLine import org.locationtech.jts.geom.Coordinate import org.locationtech.jts.geom.GeometryFactory import org.locationtech.jts.geom.LineString +import org.locationtech.jts.geom.LineString.MINIMUM_VALID_SIZE +import org.locationtech.jts.geom.Polygon import org.locationtech.jts.linearref.LengthIndexedLine import java.util.concurrent.CountDownLatch @@ -27,8 +29,20 @@ object V2NUtils { } val occupy = ArrayList() val factory = GeometryFactory() + val polygonList = ArrayList(polygon.map { Coordinate(it.first, it.second) }) + var p1: Polygon? = null + while (p1 == null) { + if (polygonList.size < MINIMUM_VALID_SIZE) { + polygonList.add(polygonList[0]) + continue + } + try { + p1 = factory.createPolygon(polygonList.toTypedArray()) + } catch (ignore: IllegalArgumentException) { + polygonList.add(polygonList[0]) + } + } for (lane in lanes) { - val p1 = factory.createPolygon(polygon.map { Coordinate(it.first, it.second) }.toTypedArray()) val p2 = factory.createLineString(lane.points.map { Coordinate(it.first, it.second) }.toTypedArray()).buffer((lane.width.toDouble() * 0.7 * (1e-5)) / 2.0) if (p1.intersects(p2)) { occupy += lane