Skip to content

Commit

Permalink
[uss_qualifier] DSS0030 slight overlap subscription interactions (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastick authored Dec 1, 2023
1 parent 7f1217e commit 0f4b4d4
Show file tree
Hide file tree
Showing 8 changed files with 504 additions and 31 deletions.
36 changes: 36 additions & 0 deletions monitoring/monitorlib/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from implicitdict import ImplicitDict
import numpy as np
import s2sphere
from s2sphere import LatLng
from scipy.interpolate import RectBivariateSpline as Spline
import shapely.geometry
from uas_standards.astm.f3548.v21 import api as f3548v21
Expand Down Expand Up @@ -501,3 +502,38 @@ def egm96_geoid_offset(p: s2sphere.LatLng) -> float:
# listed -90 to 90. Since latitude data are symmetric, we can simply
# convert "-90 to 90" to "90 to -90" by inverting the requested latitude.
return _egm96.ev(-lat, lng)


def generate_slight_overlap_area(in_points: List[LatLng]) -> List[LatLng]:
"""
Takes a list of LatLng points and returns a list of LatLng points that represents
a polygon only slightly overlapping with the input, and that is roughly half the diameter of the input.
The returned polygon is built from the first point of the input, from which a square
is drawn in the direction opposite of the center of the input polygon.
"""
overlap_corner = in_points[0] # the spot that will have a tiny overlap

# Compute the center of mass of the input polygon
center = LatLng.from_degrees(
sum([point.lat().degrees for point in in_points]) / len(in_points),
sum([point.lng().degrees for point in in_points]) / len(in_points),
)

delta_lat = center.lat().degrees - overlap_corner.lat().degrees
delta_lng = center.lng().degrees - overlap_corner.lng().degrees

same_lat_point = LatLng.from_degrees(
overlap_corner.lat().degrees, overlap_corner.lng().degrees - delta_lng
)
same_lng_point = LatLng.from_degrees(
overlap_corner.lat().degrees - delta_lat, overlap_corner.lng().degrees
)

opposite_corner = LatLng.from_degrees(
overlap_corner.lat().degrees - delta_lat,
overlap_corner.lng().degrees - delta_lng,
)

return [overlap_corner, same_lat_point, opposite_corner, same_lng_point]
36 changes: 36 additions & 0 deletions monitoring/monitorlib/geo_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from typing import List, Tuple

from s2sphere import LatLng

from monitoring.monitorlib.geo import generate_slight_overlap_area


def _points(in_points: List[Tuple[float, float]]) -> List[LatLng]:
return [LatLng.from_degrees(*p) for p in in_points]


def test_generate_slight_overlap_area():
# Square around 0,0 of edge length 2 -> first corner at 1,1 -> expect a square with overlapping corner at 1,1
assert generate_slight_overlap_area(
_points([(1, 1), (1, -1), (-1, -1), (-1, 1)])
) == _points([(1, 1), (1, 2), (2, 2), (2, 1)])

# Square with diagonal from 0,0 to 1,1 -> first corner at 1,1 -> expect a square with overlapping corner at 1,1
assert generate_slight_overlap_area(
_points([(1, 1), (0, 1), (0, 0), (1, 0)])
) == _points([(1, 1), (1, 1.5), (1.5, 1.5), (1.5, 1)])

# Square with diagonal from 0,0 to -1,-1 -> first corner at -1,-1 -> expect a square with overlapping corner at -1,-1
assert generate_slight_overlap_area(
_points([(-1, -1), (0, -1), (0, 0), (-1, 0)])
) == _points([(-1, -1), (-1, -1.5), (-1.5, -1.5), (-1.5, -1)])

# Square with diagonal from 0,0 to -1,1 -> first corner at -1,1 -> expect a square with overlapping corner at -1,0
assert generate_slight_overlap_area(
_points([(-1, 1), (-1, 0), (0, 0), (0, 1)])
) == _points([(-1, 1), (-1, 1.5), (-1.5, 1.5), (-1.5, 1)])

# Square with diagonal from 0,0 to 1,-1 -> first corner at 1,-1 -> expect a square with overlapping corner at 1,-1
assert generate_slight_overlap_area(
_points([(1, -1), (1, 0), (0, 0), (0, -1)])
) == _points([(1, -1), (1, -1.5), (1.5, -1.5), (1.5, -1)])
2 changes: 1 addition & 1 deletion monitoring/prober/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def wrapper_default_scope(*args, **kwargs):
resource_type_code_descriptions: Dict[ResourceType, str] = {}


# Next code: 373
# Next code: 374
def register_resource_type(code: int, description: str) -> ResourceType:
"""Register that the specified code refers to the described resource.
Expand Down
Loading

0 comments on commit 0f4b4d4

Please sign in to comment.