-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
140 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,3 +199,6 @@ pyrightconfig.json | |
result | ||
data/* | ||
cert/* | ||
|
||
cython_lib/*.c | ||
cython_lib/*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import cython | ||
|
||
from models.bbox import BBox | ||
from models.lonlat import LonLat | ||
|
||
if cython.compiled: | ||
from cython.cimports.libc.math import atan, pi, sinh | ||
|
||
print(f'{__name__}: 🐇 compiled') | ||
else: | ||
from math import atan, pi, sinh | ||
|
||
print(f'{__name__}: 🐌 not compiled') | ||
|
||
|
||
@cython.cfunc | ||
def _degrees(radians: cython.double) -> cython.double: | ||
return radians * 180 / pi | ||
|
||
|
||
@cython.cfunc | ||
def _tile_to_lonlat(z: cython.int, x: cython.int, y: cython.int) -> tuple[cython.double, cython.double]: | ||
n: cython.double = 2**z | ||
lon_deg: cython.double = x / n * 360.0 - 180.0 | ||
lat_rad: cython.double = atan(sinh(pi * (1 - 2 * y / n))) | ||
lat_deg: cython.double = _degrees(lat_rad) | ||
return lon_deg, lat_deg | ||
|
||
|
||
def tile_to_bbox(z: cython.int, x: cython.int, y: cython.int) -> BBox: | ||
p1_lon, p1_lat = _tile_to_lonlat(z, x, y) | ||
p2_lon, p2_lat = _tile_to_lonlat(z, x + 1, y + 1) | ||
return BBox(LonLat(p1_lon, p2_lat), LonLat(p2_lon, p1_lat)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Cython.Compiler.Options as Options | ||
from Cython.Build import cythonize | ||
from setuptools import Extension, setup | ||
|
||
Options.docstrings = False | ||
Options.annotate = True | ||
|
||
setup( | ||
ext_modules=cythonize( | ||
[ | ||
Extension( | ||
'*', | ||
['cython_lib/*.py'], | ||
extra_compile_args=[ | ||
'-march=x86-64', | ||
'-ffast-math', | ||
'-fopenmp', | ||
'-flto=auto', | ||
], | ||
extra_link_args=[ | ||
'-fopenmp', | ||
'-flto=auto', | ||
], | ||
), | ||
], | ||
compiler_directives={ | ||
# https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html#compiler-directives | ||
'language_level': 3, | ||
}, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters