Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump core lib to 4.0 rc5 #275

Merged
merged 6 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ avoid adding features or APIs which do not map onto the

## [3.6.2] - 2020-06-02

- Improve error reporting on `hex2int` (https:/uber/h3-py/pull/127)
- Improve error reporting on `str_to_int` (https:/uber/h3-py/pull/127)
- Build Linux wheels for Python 2.7

## [3.6.1] - 2020-05-29
Expand Down
4 changes: 2 additions & 2 deletions docs/api_comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ needs, based on speed and convenience.

```{tip}
Note that the APIs are all 100% compatible, and it is easy to convert
between them with functions like `int_to_string` (links!) and `string_to_int`.
between them with functions like `int_to_str` (links!) and `str_to_int`.

For example, one common pattern is to use `h3.api.numpy_int` for any
computationally-heavy work, and convert the output to `str` and `list`/`set`
Expand Down Expand Up @@ -236,7 +236,7 @@ def compute(h3_lib, N=100):

def compute_and_convert(h3_lib, N=100):
out = compute(h3_lib, N)
out = [h3.int_to_string(h) for h in out]
out = [h3.int_to_str(h) for h in out]

return out
```
Expand Down
4 changes: 2 additions & 2 deletions docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ but we'll try to group functions in a reasonably logical manner.
.. autosummary::
latlng_to_cell
cell_to_latlng
int_to_string
string_to_int
int_to_str
str_to_int
get_res0_cells
get_pentagons
get_num_cells
Expand Down
4 changes: 2 additions & 2 deletions src/h3/_cy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@

from .util import (
c_version,
hex2int,
int2hex,
str_to_int,
int_to_str,
)

from .memory import (
Expand Down
6 changes: 3 additions & 3 deletions src/h3/_cy/edges.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ cpdef double edge_length(H3int e, unit='km') except -1:
double length

if unit == 'rads':
err = h3lib.exactEdgeLengthRads(e, &length)
err = h3lib.edgeLengthRads(e, &length)
elif unit == 'km':
err = h3lib.exactEdgeLengthKm(e, &length)
err = h3lib.edgeLengthKm(e, &length)
elif unit == 'm':
err = h3lib.exactEdgeLengthM(e, &length)
err = h3lib.edgeLengthM(e, &length)
else:
raise ValueError('Unknown unit: {}'.format(unit))

Expand Down
4 changes: 2 additions & 2 deletions src/h3/_cy/error_system.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ from .h3lib cimport (
E_DUPLICATE_INPUT,
E_NOT_NEIGHBORS,
E_RES_MISMATCH,
E_MEMORY,
E_MEMORY_ALLOC,
E_MEMORY_BOUNDS,
E_OPTION_INVALID,
)
Expand Down Expand Up @@ -189,7 +189,7 @@ error_mapping = {
E_DUPLICATE_INPUT: H3DuplicateInputError,
E_NOT_NEIGHBORS: H3NotNeighborsError,
E_RES_MISMATCH: H3ResMismatchError,
E_MEMORY: H3MemoryAllocError,
E_MEMORY_ALLOC: H3MemoryAllocError,
E_MEMORY_BOUNDS: H3MemoryBoundsError,
E_OPTION_INVALID: H3OptionInvalidError,
}
Expand Down
6 changes: 3 additions & 3 deletions src/h3/_cy/geo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ cpdef double great_circle_distance(
b = deg2coord(lat2, lng2)

if unit == 'rads':
d = h3lib.distanceRads(&a, &b)
d = h3lib.greatCircleDistanceRads(&a, &b)
elif unit == 'km':
d = h3lib.distanceKm(&a, &b)
d = h3lib.greatCircleDistanceKm(&a, &b)
elif unit == 'm':
d = h3lib.distanceM(&a, &b)
d = h3lib.greatCircleDistanceM(&a, &b)
else:
raise ValueError('Unknown unit: {}'.format(unit))

Expand Down
14 changes: 7 additions & 7 deletions src/h3/_cy/h3lib.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cdef extern from 'h3api.h':
E_DUPLICATE_INPUT = 10
E_NOT_NEIGHBORS = 11
E_RES_MISMATCH = 12
E_MEMORY = 13
E_MEMORY_ALLOC = 13
E_MEMORY_BOUNDS = 14
E_OPTION_INVALID = 15

Expand Down Expand Up @@ -143,16 +143,16 @@ cdef extern from 'h3api.h':
H3Error getHexagonEdgeLengthAvgKm(int res, double *out) nogil
H3Error getHexagonEdgeLengthAvgM(int res, double *out) nogil

H3Error exactEdgeLengthRads(H3int edge, double *out) nogil
H3Error exactEdgeLengthKm(H3int edge, double *out) nogil
H3Error exactEdgeLengthM(H3int edge, double *out) nogil
H3Error edgeLengthRads(H3int edge, double *out) nogil
H3Error edgeLengthKm(H3int edge, double *out) nogil
H3Error edgeLengthM(H3int edge, double *out) nogil

H3Error cellToBoundary(H3int h3, CellBoundary *gp) nogil
H3Error directedEdgeToBoundary(H3int edge, CellBoundary *gb) nogil

double distanceRads(const LatLng *a, const LatLng *b) nogil
double distanceKm(const LatLng *a, const LatLng *b) nogil
double distanceM(const LatLng *a, const LatLng *b) nogil
double greatCircleDistanceRads(const LatLng *a, const LatLng *b) nogil
double greatCircleDistanceKm(const LatLng *a, const LatLng *b) nogil
double greatCircleDistanceM(const LatLng *a, const LatLng *b) nogil

H3Error cellsToLinkedMultiPolygon(const H3int *h3Set, const int numHexes, LinkedGeoPolygon *out)
void destroyLinkedMultiPolygon(LinkedGeoPolygon *polygon)
Expand Down
4 changes: 2 additions & 2 deletions src/h3/_cy/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ from .h3lib cimport H3int, H3str, LatLng
cdef LatLng deg2coord(double lat, double lng) nogil
cdef (double, double) coord2deg(LatLng c) nogil

cpdef H3int hex2int(H3str h) except? 0
cpdef H3str int2hex(H3int x)
cpdef H3int str_to_int(H3str h) except? 0
cpdef H3str int_to_str(H3int x)

cdef check_cell(H3int h)
cdef check_edge(H3int e)
Expand Down
6 changes: 3 additions & 3 deletions src/h3/_cy/util.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ cpdef basestring c_version():
return '{}.{}.{}'.format(*v)


cpdef H3int hex2int(H3str h) except? 0:
cpdef H3int str_to_int(H3str h) except? 0:
return int(h, 16)


cpdef H3str int2hex(H3int x):
cpdef H3str int_to_str(H3int x):
""" Convert H3 integer to hex string representation

Need to be careful in Python 2 because `hex(x)` may return a string
Expand All @@ -61,7 +61,7 @@ cdef check_cell(H3int h):
we want the error message to be informative to the user
in either case.

We use the builtin `hex` function instead of `int2hex` to
We use the builtin `hex` function instead of `int_to_str` to
prepend `0x` to indicate that this **integer** representation
is incorrect, but in a format that is easily compared to
`str` inputs.
Expand Down
28 changes: 12 additions & 16 deletions src/h3/api/_api_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def versions():
return v

@staticmethod
def string_to_int(h):
def str_to_int(h):
"""
Converts a hexadecimal string to an H3 64-bit integer index.

Expand All @@ -92,10 +92,10 @@ def string_to_int(h):
int
Unsigned 64-bit integer
"""
return _cy.hex2int(h)
return _cy.str_to_int(h)

@staticmethod
def int_to_string(x):
def int_to_str(x):
"""
Converts an H3 64-bit integer index to a hexadecimal string.

Expand All @@ -109,7 +109,7 @@ def int_to_string(x):
str
Hexadecimal string like ``'89754e64993ffff'``
"""
return _cy.int2hex(x)
return _cy.int_to_str(x)

@staticmethod
def get_num_cells(resolution):
Expand Down Expand Up @@ -887,35 +887,31 @@ def edge_length(self, e, unit='km'):
return _cy.edge_length(e, unit=unit)

@staticmethod
def great_circle_distance(point1, point2, unit='km'):
def great_circle_distance(latlng1, latlng2, unit='km'):
"""
Compute the spherical distance between two (lat, lng) points.

todo: do we handle lat/lng points consistently in the api? what
about (lat1, lng1, lat2, lng2) as the input? How will this work
for vectorized versions?
AKA: great circle distance or "haversine" distance.

todo: overload to allow two cell inputs?

Parameters
----------
point1 : tuple
latlng1 : tuple
(lat, lng) tuple in degrees
point2 : tuple
latlng2 : tuple
(lat, lng) tuple in degrees
unit: str
Unit for distance result ('km', 'm', or 'rads')


Returns
-------
Spherical (or "haversine") distance between the points
The spherical distance between the points in the given units
"""
lat1, lng1 = point1
lat2, lng2 = point2

lat1, lng1 = latlng1
lat2, lng2 = latlng2
return _cy.great_circle_distance(
lat1, lng1,
lat2, lng2,
unit=unit
unit = unit
)
4 changes: 2 additions & 2 deletions src/h3/api/basic_int/_public_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
is_valid_directed_edge = _b.is_valid_directed_edge
is_res_class_III = _b.is_res_class_III

int_to_string = _b.int_to_string
string_to_int = _b.string_to_int
int_to_str = _b.int_to_str
str_to_int = _b.str_to_int

cell_area = _b.cell_area
edge_length = _b.edge_length
Expand Down
10 changes: 5 additions & 5 deletions src/h3/api/basic_str/_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@


def _in_collection(hexes):
it = [_cy.hex2int(h) for h in hexes]
it = [_cy.str_to_int(h) for h in hexes]

return _cy.iter_to_mv(it)


def _out_unordered(mv):
# todo: should this be an (immutable) frozenset?
return set(_cy.int2hex(h) for h in mv)
return set(_cy.int_to_str(h) for h in mv)


def _out_ordered(mv):
# todo: should this be an (immutable) tuple?
return list(_cy.int2hex(h) for h in mv)
return list(_cy.int_to_str(h) for h in mv)


_binding = _API_FUNCTIONS(
_in_scalar = _cy.hex2int,
_out_scalar = _cy.int2hex,
_in_scalar = _cy.str_to_int,
_out_scalar = _cy.int_to_str,
_in_collection = _in_collection,
_out_unordered = _out_unordered,
_out_ordered = _out_ordered,
Expand Down
2 changes: 1 addition & 1 deletion src/h3lib
Submodule h3lib updated 42 files
+4 −0 .github/workflows/test-windows.yml
+14 −0 CHANGELOG.md
+2 −2 CMakeLists.txt
+1 −1 README.md
+1 −1 VERSION
+2 −2 dev-docs/RFCs/v4.0.0/error-handling-rfc.md
+16 −10 dev-docs/RFCs/v4.0.0/names_for_concepts_types_functions.md
+2 −2 scripts/update_version.sh
+1 −1 src/apps/fuzzers/README.md
+3 −3 src/apps/fuzzers/fuzzerDistances.c
+4 −4 src/apps/fuzzers/fuzzerEdgeLength.c
+16 −0 src/apps/testapps/testBBox.c
+5 −7 src/apps/testapps/testDirectedEdge.c
+19 −17 src/apps/testapps/testH3CellAreaExhaustive.c
+10 −9 src/apps/testapps/testH3Memory.c
+10 −9 src/apps/testapps/testLatLng.c
+1 −1 src/apps/testapps/testPolygon.c
+68 −0 src/apps/testapps/testPolygonToCells.c
+7 −0 src/apps/testapps/testVertex.c
+3 −3 src/h3lib/include/bbox.h
+1 −1 src/h3lib/include/constants.h
+14 −11 src/h3lib/include/h3api.h.in
+17 −9 src/h3lib/lib/algos.c
+36 −19 src/h3lib/lib/bbox.c
+3 −3 src/h3lib/lib/h3Index.c
+15 −14 src/h3lib/lib/latLng.c
+1 −2 src/h3lib/lib/vertex.c
+36 −36 website/docs/api/misc.mdx
+13 −2 website/docs/community/bindings.md
+1 −1 website/docs/library/errors.md
+21 −15 website/docs/library/migration-3.x/functions.md
+2 −1 website/package.json
+2 −1 website/src/theme/ReactLiveScope/index.js
+5 −5 website/versioned_docs/version-3.x/api/hierarchy.mdx
+3 −3 website/versioned_docs/version-3.x/api/indexing.mdx
+6 −6 website/versioned_docs/version-3.x/api/inspection.mdx
+16 −16 website/versioned_docs/version-3.x/api/misc.mdx
+2 −2 website/versioned_docs/version-3.x/api/regions.mdx
+7 −7 website/versioned_docs/version-3.x/api/traversal.mdx
+8 −8 website/versioned_docs/version-3.x/api/uniedge.mdx
+3 −3 website/versioned_docs/version-3.x/quickstart.md
+58 −22 website/yarn.lock
8 changes: 4 additions & 4 deletions tests/test_cells_and_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_parent_err():

# todo: revist this weird formatting stuff
expected = 'Invalid parent resolution -1 for cell {}.'
expected = expected.format(hex(h3.string_to_int(h)))
expected = expected.format(hex(h3.str_to_int(h)))

assert msg == expected

Expand Down Expand Up @@ -480,12 +480,12 @@ def test_versions():

def test_str_int_convert():
s = '8928308280fffff'
i = h3.string_to_int(s)
i = h3.str_to_int(s)

assert h3.int_to_string(i) == s
assert h3.int_to_str(i) == s


def test_hex2int_fail():
def test_str_to_int_fail():
h_invalid = {}

assert not h3.is_valid_cell(h_invalid)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_memview_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test1():
def test_line():
h1 = '8928308280fffff'
h2 = '8928308287bffff'
h1, h2 = h3.string_to_int(h1), h3.string_to_int(h2)
h1, h2 = h3.str_to_int(h1), h3.str_to_int(h2)

out = h3.grid_path_cells(h1, h2)

Expand Down