mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-14 18:37:58 +00:00
Replace custom Almost with stdlib math.isclose
This commit is contained in:
@@ -11,17 +11,6 @@ import json
|
|||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
|
|
||||||
class Almost:
|
|
||||||
""" Compares a float value with a certain jitter.
|
|
||||||
"""
|
|
||||||
def __init__(self, value, offset=0.00001):
|
|
||||||
self.value = value
|
|
||||||
self.offset = offset
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
return abs(other - self.value) < self.offset
|
|
||||||
|
|
||||||
|
|
||||||
OSM_TYPE = {'N' : 'node', 'W' : 'way', 'R' : 'relation',
|
OSM_TYPE = {'N' : 'node', 'W' : 'way', 'R' : 'relation',
|
||||||
'n' : 'node', 'w' : 'way', 'r' : 'relation',
|
'n' : 'node', 'w' : 'way', 'r' : 'relation',
|
||||||
'node' : 'n', 'way' : 'w', 'relation' : 'r'}
|
'node' : 'n', 'way' : 'w', 'relation' : 'r'}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import re
|
|||||||
import json
|
import json
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
from check_functions import Almost, OsmType, Field, check_for_attributes
|
from check_functions import OsmType, Field, check_for_attributes
|
||||||
|
|
||||||
|
|
||||||
class GenericResponse:
|
class GenericResponse:
|
||||||
|
|||||||
@@ -7,14 +7,13 @@
|
|||||||
"""
|
"""
|
||||||
Functions to facilitate accessing and comparing the content of DB tables.
|
Functions to facilitate accessing and comparing the content of DB tables.
|
||||||
"""
|
"""
|
||||||
|
import math
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import psycopg
|
import psycopg
|
||||||
from psycopg import sql as pysql
|
from psycopg import sql as pysql
|
||||||
|
|
||||||
from steps.check_functions import Almost
|
|
||||||
|
|
||||||
ID_REGEX = re.compile(r"(?P<typ>[NRW])(?P<oid>\d+)(:(?P<cls>\w+))?")
|
ID_REGEX = re.compile(r"(?P<typ>[NRW])(?P<oid>\d+)(:(?P<cls>\w+))?")
|
||||||
|
|
||||||
class NominatimID:
|
class NominatimID:
|
||||||
@@ -166,7 +165,7 @@ class DBRow:
|
|||||||
else:
|
else:
|
||||||
x, y = self.context.osm.grid_node(int(expected))
|
x, y = self.context.osm.grid_node(int(expected))
|
||||||
|
|
||||||
return Almost(float(x)) == self.db_row['cx'] and Almost(float(y)) == self.db_row['cy']
|
return math.isclose(float(x), self.db_row['cx']) and math.isclose(float(y), self.db_row['cy'])
|
||||||
|
|
||||||
def _has_geometry(self, expected):
|
def _has_geometry(self, expected):
|
||||||
geom = self.context.osm.parse_geometry(expected)
|
geom = self.context.osm.parse_geometry(expected)
|
||||||
|
|||||||
Reference in New Issue
Block a user