Correction of finding the visual center of points

This commit is contained in:
dormantman 2019-12-03 14:39:25 +03:00
parent 4d54c84b51
commit e7de51373d

View File

@ -11,7 +11,7 @@ class CustomGeoSpatialFilteringFilterBackend(GeoSpatialFilteringFilterBackend):
@staticmethod
def calculate_center(first, second):
if second[1] < 0 <= first[1]:
if second[1] < 0 < first[1]:
reverse_first, reverse_second = 180 - abs(first[1]), 180 - abs(second[1])
diff = (reverse_first + reverse_second) / 2
@ -21,6 +21,16 @@ class CustomGeoSpatialFilteringFilterBackend(GeoSpatialFilteringFilterBackend):
else:
result_part = 180 - (180 - first[1] - diff)
elif second[1] < 0 > first[1]:
diff = abs(abs(second[1]) - abs(first[1]))
if diff > 90:
reverse_first, reverse_second = 180 - abs(first[1]), 180 - abs(second[1])
result_part = (reverse_first + reverse_second) / 2
else:
result_part = (first[1] + second[1]) / 2
else:
result_part = (first[1] + second[1]) / 2