From b4d8ad8fb36afbdc1c59112032cf4332a3186472 Mon Sep 17 00:00:00 2001 From: renwj Date: Wed, 10 Jul 2024 17:15:20 +0800 Subject: [PATCH] =?UTF-8?q?[6.5.0][=E9=81=93=E8=B7=AF=E4=BA=8B=E4=BB=B6]?= =?UTF-8?q?=20=E9=98=B2=E6=AD=A2polygon=E6=95=B0=E6=8D=AE=E4=B8=8D?= =?UTF-8?q?=E9=97=AD=E5=90=88=E5=AF=BC=E8=87=B4=E7=A8=8B=E5=BA=8F=E5=B4=A9?= =?UTF-8?q?=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eagle/function/biz/v2x/v2n/utils/V2NUtils.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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