mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Migrated "polygon" code to shapely
This commit is contained in:
parent
7c52ca15f3
commit
feed55186f
@ -2,8 +2,10 @@ import pickle
|
||||
from typing import Collection, Optional, Tuple
|
||||
import logging
|
||||
|
||||
from shapely import geometry
|
||||
|
||||
Zone = Collection[Tuple[float, float]]
|
||||
Landmap = Tuple[Collection[Zone], Collection[Zone], Collection[Zone]]
|
||||
Landmap = Tuple[Collection[geometry.Polygon], Collection[geometry.Polygon], Collection[geometry.Polygon]]
|
||||
|
||||
|
||||
def load_landmap(filename: str) -> Optional[Landmap]:
|
||||
@ -15,22 +17,9 @@ def load_landmap(filename: str) -> Optional[Landmap]:
|
||||
return None
|
||||
|
||||
|
||||
def poly_contains(x, y, poly):
|
||||
n = len(poly)
|
||||
inside = False
|
||||
xints = 0.0
|
||||
p1x, p1y = poly[0]
|
||||
for i in range(n+1):
|
||||
p2x, p2y = poly[i % n]
|
||||
if y > min(p1y, p2y):
|
||||
if y <= max(p1y, p2y):
|
||||
if x <= max(p1x, p2x):
|
||||
if p1y != p2y:
|
||||
xints = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
|
||||
if p1x == p2x or x <= xints:
|
||||
inside = not inside
|
||||
p1x, p1y = p2x, p2y
|
||||
return inside
|
||||
def poly_contains(x, y, poly:geometry.Polygon):
|
||||
return poly.contains(geometry.Point(x, y))
|
||||
|
||||
|
||||
def poly_centroid(poly) -> Tuple[float, float]:
|
||||
x_list = [vertex[0] for vertex in poly]
|
||||
|
||||
3
mypy.ini
3
mypy.ini
@ -10,3 +10,6 @@ ignore_missing_imports = True
|
||||
|
||||
[mypy-winreg.*]
|
||||
ignore_missing_imports = True
|
||||
|
||||
[mypy-shapely.*]
|
||||
ignore_missing_imports = True
|
||||
@ -20,8 +20,9 @@ class DisplayRule:
|
||||
def value(self, value: bool) -> None:
|
||||
from qt_ui.widgets.map.QLiberationMap import QLiberationMap
|
||||
self._value = value
|
||||
QLiberationMap.instance.reload_scene()
|
||||
QLiberationMap.instance.update()
|
||||
if QLiberationMap.instance is not None:
|
||||
QLiberationMap.instance.reload_scene()
|
||||
QLiberationMap.instance.update()
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
return self.value
|
||||
|
||||
@ -744,7 +744,7 @@ class QLiberationMap(QGraphicsView):
|
||||
|
||||
for sea_zone in self.game.theater.landmap[2]:
|
||||
print(sea_zone)
|
||||
poly = QPolygonF([QPointF(*self._transform_point(Point(point[0], point[1]))) for point in sea_zone])
|
||||
poly = QPolygonF([QPointF(*self._transform_point(Point(point[0], point[1]))) for point in sea_zone.exterior.coords])
|
||||
if self.reference_point_setup_mode:
|
||||
color = "sea_blue_transparent"
|
||||
else:
|
||||
@ -752,14 +752,14 @@ class QLiberationMap(QGraphicsView):
|
||||
scene.addPolygon(poly, CONST.COLORS[color], CONST.COLORS[color])
|
||||
|
||||
for inclusion_zone in self.game.theater.landmap[0]:
|
||||
poly = QPolygonF([QPointF(*self._transform_point(Point(point[0], point[1]))) for point in inclusion_zone])
|
||||
poly = QPolygonF([QPointF(*self._transform_point(Point(point[0], point[1]))) for point in inclusion_zone.exterior.coords])
|
||||
if self.reference_point_setup_mode:
|
||||
scene.addPolygon(poly, CONST.COLORS["grey_transparent"], CONST.COLORS["dark_grey_transparent"])
|
||||
else:
|
||||
scene.addPolygon(poly, CONST.COLORS["grey"], CONST.COLORS["dark_grey"])
|
||||
|
||||
for exclusion_zone in self.game.theater.landmap[1]:
|
||||
poly = QPolygonF([QPointF(*self._transform_point(Point(point[0], point[1]))) for point in exclusion_zone])
|
||||
poly = QPolygonF([QPointF(*self._transform_point(Point(point[0], point[1]))) for point in exclusion_zone.exterior.coords])
|
||||
if self.reference_point_setup_mode:
|
||||
scene.addPolygon(poly, CONST.COLORS["grey_transparent"], CONST.COLORS["dark_dark_grey_transparent"])
|
||||
else:
|
||||
|
||||
@ -8,3 +8,4 @@ tabulate~=0.8.7
|
||||
mypy==0.782
|
||||
mypy-extensions==0.4.3
|
||||
jinja2>=2.11.2
|
||||
shapely==1.7.1
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,6 +1,7 @@
|
||||
import pickle
|
||||
|
||||
from dcs.mission import Mission
|
||||
from shapely import geometry
|
||||
|
||||
for terrain in ["cau", "nev", "syria", "channel", "normandy", "gulf"]:
|
||||
print("Terrain " + terrain)
|
||||
@ -15,16 +16,16 @@ for terrain in ["cau", "nev", "syria", "channel", "normandy", "gulf"]:
|
||||
|
||||
if terrain == "cau" and inclusion_zones:
|
||||
# legacy
|
||||
exclusion_zones.append(zone)
|
||||
exclusion_zones.append(geometry.Polygon(zone))
|
||||
else:
|
||||
if plane_group.units[0].type == "F-15C":
|
||||
exclusion_zones.append(zone)
|
||||
exclusion_zones.append(geometry.Polygon(zone))
|
||||
else:
|
||||
inclusion_zones.append(zone)
|
||||
inclusion_zones.append(geometry.Polygon(zone))
|
||||
|
||||
for ship_group in m.country("USA").ship_group:
|
||||
zone = [(x.position.x, x.position.y) for x in ship_group.points]
|
||||
seas_zones.append(zone)
|
||||
seas_zones.append(geometry.Polygon(zone))
|
||||
|
||||
with open("../{}landmap.p".format(terrain), "wb") as f:
|
||||
print(len(inclusion_zones), len(exclusion_zones), len(seas_zones))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user