Epsilon bounds comparison for float imprecision

Former-commit-id: aa9d91da07
pull/1161/head
Piero Toffanin 2019-09-14 09:54:23 -04:00
rodzic f88b7f47a3
commit 728b35c96a
1 zmienionych plików z 16 dodań i 2 usunięć

Wyświetl plik

@ -57,7 +57,7 @@ def euclidean_merge_dems(input_dems, output_dem, creation_options={}):
xs = []
ys = []
for src_d, src_e in sources:
if src_d.bounds != src_e.bounds:
if not same_bounds(src_d, src_e):
raise ValueError("DEM and euclidean file must have the same bounds")
left, bottom, right, top = src_d.bounds
@ -158,4 +158,18 @@ def euclidean_merge_dems(input_dems, output_dem, creation_options={}):
dstrast.write(dstarr, window=dst_window)
return output_dem
return output_dem
def same_bounds(rast_a, rast_b, EPS = 1E-5):
"""
Compares two raster bounds and returns true if they are equal
(up to a float precision threshold)
"""
a = rast_a.bounds
b = rast_b.bounds
return (abs(a.bottom - b.bottom) < EPS) and \
(abs(a.top - b.top) < EPS) and \
(abs(a.left - b.left) < EPS) and \
(abs(a.right - b.right) < EPS)