[6.5.0][道路事件] 防止polygon数据不闭合导致程序崩溃

This commit is contained in:
renwj
2024-07-10 17:15:20 +08:00
parent 52f0c05caf
commit b4d8ad8fb3

View File

@@ -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<Lane>()
val factory = GeometryFactory()
val polygonList = ArrayList<Coordinate>(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