Skip to content

Commit

Permalink
Drop py 2 support and migrate to github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
loicgasser committed Jan 26, 2021
1 parent 750125d commit 3a39615
Show file tree
Hide file tree
Showing 22 changed files with 236 additions and 213 deletions.
10 changes: 0 additions & 10 deletions .flake8

This file was deleted.

62 changes: 62 additions & 0 deletions .github/workflows/main.yml
@@ -0,0 +1,62 @@
name: CI

on:
push:
branches: [master]
tags:
- "*"
pull_request:

jobs:
tests:
strategy:
fail-fast: false
matrix:
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y python-dev libgeos-dev
pip install -U pip setuptools
pip install -r dev-requirements.txt
- name: Lint
run: flake8

- name: Isort
run: isort --check-only --diff .

- name: Test
run: coverage run --source=quantized_mesh_tile setup.py test

- name: Coveralls
uses: AndreMiras/coveralls-python-action@develop
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.python-version }}
parallel: true

coveralls:
needs: tests
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: AndreMiras/coveralls-python-action@develop
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,3 +9,4 @@ doc/build/
.idea/
.coverage
.vscode
.eggs
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE → LICENSE.txt
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Gasser Loïc
Copyright (c) 2021 Gasser Loïc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,7 +1,7 @@
quantized-mesh-tile
===================

[![Build Status](https://travis-ci.org/loicgasser/quantized-mesh-tile.svg?branch=master)](https://travis-ci.org/loicgasser/quantized-mesh-tile)
![Build Status](https://github.com/loicgasser/quantized-mesh-tile/workflows/CI/badge.svg?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/loicgasser/quantized-mesh-tile/badge.svg?branch=master)](https://coveralls.io/github/loicgasser/quantized-mesh-tile?branch=master)
[![Doc Status](https://readthedocs.org/projects/quantized-mesh-tile/badge/?version=latest)](http://quantized-mesh-tile.readthedocs.io/en/latest/?badge=latest)

Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
@@ -1,6 +1,6 @@
coveralls
flake8
future
isort
mock==1.0.1
nose
sphinx
Expand Down
2 changes: 1 addition & 1 deletion doc/source/index.rst
Expand Up @@ -17,7 +17,7 @@ Reference Documentation
Requirements
------------

Quantized mesh tile requires Python >=2.7 (not including Python 3.x) and GEOS >= 3.3.
Quantized mesh tile requires Python >= 3.5 and GEOS >= 3.3.

Installation
------------
Expand Down
27 changes: 11 additions & 16 deletions quantized_mesh_tile/bbsphere.py
@@ -1,12 +1,6 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division

import math
from builtins import map, object

from past.builtins import xrange
from past.utils import old_div

from . import cartesian3d as c3d

Expand All @@ -15,8 +9,9 @@ class BoundingSphere(object):
def __init__(self, *args, **kwargs):
MAX = float('infinity')
MIN = float('-infinity')
self.center = list(map(float, kwargs.get('center', [])))
self.radius = float(kwargs.get('radius', 0))

self.center = kwargs.get('center', [])
self.radius = kwargs.get('radius', 0)
self.minPointX = [MAX, MAX, MAX]
self.minPointY = [MAX, MAX, MAX]
self.minPointZ = [MAX, MAX, MAX]
Expand All @@ -31,7 +26,7 @@ def fromPoints(self, points):
if nbPositions < 2:
raise Exception('Your list of points must contain at least 2 points')

for i in xrange(0, nbPositions):
for i in range(0, nbPositions):
point = points[i]

# Store the points containing the smallest and largest component
Expand Down Expand Up @@ -86,7 +81,7 @@ def fromPoints(self, points):
naiveCenter = c3d.multiplyByScalar(c3d.add(minBoxPt, maxBoxPt), 0.5)
naiveRadius = 0.0

for i in xrange(0, nbPositions):
for i in range(0, nbPositions):
currentP = points[i]

# Find the furthest point from the naive center to calculate the naive radius.
Expand All @@ -104,12 +99,12 @@ def fromPoints(self, points):
# Calculate center of new Ritter sphere
oldToNew = oldCenterToPoint - ritterRadius
ritterCenter = [
old_div((ritterRadius * ritterCenter[0] + oldToNew * currentP[0]),
oldCenterToPoint),
old_div((ritterRadius * ritterCenter[1] + oldToNew * currentP[1]),
oldCenterToPoint),
old_div((ritterRadius * ritterCenter[2] + oldToNew * currentP[2]),
oldCenterToPoint)
(ritterRadius * ritterCenter[0] +
oldToNew * currentP[0]) / oldCenterToPoint,
(ritterRadius * ritterCenter[1] +
oldToNew * currentP[1]) / oldCenterToPoint,
(ritterRadius * ritterCenter[2] +
oldToNew * currentP[2]) / oldCenterToPoint
]

# Keep the naive sphere if smaller
Expand Down
6 changes: 1 addition & 5 deletions quantized_mesh_tile/cartesian3d.py
@@ -1,11 +1,7 @@
# -*- coding: utf-8 -*-

from __future__ import division

import math

from past.utils import old_div


def magnitudeSquared(p):
return p[0] ** 2 + p[1] ** 2 + p[2] ** 2
Expand Down Expand Up @@ -37,4 +33,4 @@ def multiplyByScalar(p, scalar):

def normalize(p):
mgn = magnitude(p)
return [old_div(p[0], mgn), old_div(p[1], mgn), old_div(p[2], mgn)]
return [p[0] / mgn, p[1] / mgn, p[2] / mgn]
23 changes: 9 additions & 14 deletions quantized_mesh_tile/global_geodetic.py
Expand Up @@ -15,12 +15,7 @@
Reference
---------
"""
from __future__ import division

import math
from builtins import object, range

from past.utils import old_div

MAXZOOMLEVEL = 32

Expand All @@ -46,27 +41,27 @@ class GlobalGeodetic(object):
def __init__(self, tmscompatible, tileSize=256):
self.tileSize = tileSize
if tmscompatible is not None:
self.resFact = old_div(180.0, self.tileSize)
self.resFact = 180.0 / self.tileSize
self._numberOfLevelZeroTilesX = 2
self._numberOfLevelZeroTilesY = 1
else:
self.resFact = old_div(360.0, self.tileSize)
self.resFact = 360.0 / self.tileSize
self._numberOfLevelZeroTilesX = 1
self._numberOfLevelZeroTilesY = 1

def LonLatToPixels(self, lon, lat, zoom):
"Converts lon/lat to pixel coordinates in given zoom of the EPSG:4326 pyramid"

res = old_div(self.resFact, 2 ** zoom)
px = old_div((180 + lon), res)
py = old_div((90 + lat), res)
res = self.resFact / 2 ** zoom
px = (180 + lon) / res
py = (90 + lat) / res
return px, py

def PixelsToTile(self, px, py):
"Returns coordinates of the tile covering region in pixel coordinates"

tx = int(math.ceil(old_div(px, float(self.tileSize))) - 1) if px > 0 else 0
ty = int(math.ceil(old_div(py, float(self.tileSize))) - 1) if py > 0 else 0
tx = int(math.ceil(px / float(self.tileSize)) - 1) if px > 0 else 0
ty = int(math.ceil(py / float(self.tileSize)) - 1) if py > 0 else 0
return tx, ty

def LonLatToTile(self, lon, lat, zoom):
Expand All @@ -78,7 +73,7 @@ def LonLatToTile(self, lon, lat, zoom):
def Resolution(self, zoom):
"Resolution (arc/pixel) for given zoom level (measured at Equator)"

return old_div(self.resFact, 2 ** zoom)
return self.resFact / 2 ** zoom
# return 180 / float( 1 << (8+zoom) )

def ZoomForPixelSize(self, pixelSize):
Expand All @@ -93,7 +88,7 @@ def ZoomForPixelSize(self, pixelSize):

def TileBounds(self, tx, ty, zoom):
"Returns bounds of the given tile"
res = old_div(self.resFact, 2 ** zoom)
res = self.resFact / 2 ** zoom
return (
tx * self.tileSize * res - 180,
ty * self.tileSize * res - 90,
Expand Down
20 changes: 8 additions & 12 deletions quantized_mesh_tile/horizon_occlusion_point.py
@@ -1,37 +1,33 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division

import math
from builtins import map

import numpy as np
from past.utils import old_div

from . import cartesian3d as c3d
from . import llh_ecef as ecef

# Constants taken from http://cesiumjs.org/2013/04/25/Horizon-culling/
rX = old_div(1.0, ecef.radiusX)
rY = old_div(1.0, ecef.radiusY)
rZ = old_div(1.0, ecef.radiusZ)
rX = 1.0 / ecef.radiusX
rY = 1.0 / ecef.radiusY
rZ = 1.0 / ecef.radiusZ

# Functions assumes ellipsoid scaled coordinates


def computeMagnitude(point, sphereCenter):
magnitudeSquared = c3d.magnitudeSquared(point)
magnitude = math.sqrt(magnitudeSquared)
direction = c3d.multiplyByScalar(point, old_div(1, magnitude))
direction = c3d.multiplyByScalar(point, 1 / magnitude)

magnitudeSquared = max(1.0, magnitudeSquared)
magnitude = max(1.0, magnitude)

cosAlpha = np.dot(direction, sphereCenter)
sinAlpha = c3d.magnitude(np.cross(direction, sphereCenter))
cosBeta = old_div(1.0, magnitude)
cosBeta = 1.0 / magnitude
sinBeta = math.sqrt(magnitudeSquared - 1.0) * cosBeta
return old_div(1.0, (cosAlpha * cosBeta - sinAlpha * sinBeta))
return 1.0 / (cosAlpha * cosBeta - sinAlpha * sinBeta)


# https://cesiumjs.org/2013/05/09/Computing-the-horizon-occlusion-point/
Expand All @@ -43,11 +39,11 @@ def fromPoints(points, boundingSphere):
# Bring coordinates to ellipsoid scaled coordinates
def scaleDown(coord):
return [coord[0] * rX, coord[1] * rY, coord[2] * rZ]
scaledPoints = list(map(scaleDown, points))
scaledPoints = [scaleDown(coord) for coord in points]
scaledSphereCenter = scaleDown(boundingSphere.center)

def magnitude(coord):
return computeMagnitude(coord, scaledSphereCenter)
magnitudes = list(map(magnitude, scaledPoints))
magnitudes = [magnitude(coord) for coord in scaledPoints]

return c3d.multiplyByScalar(scaledSphereCenter, max(magnitudes))
22 changes: 9 additions & 13 deletions quantized_mesh_tile/llh_ecef.py
@@ -1,11 +1,7 @@
# -*- coding: utf-8 -*-

from __future__ import division

import math

from past.utils import old_div

# Constants taken from http://cesiumjs.org/2013/04/25/Horizon-culling/
radiusX = 6378137.0
radiusY = 6378137.0
Expand All @@ -23,12 +19,11 @@


def LLH2ECEF(lon, lat, alt):
lat *= (old_div(math.pi, 180.0))
lon *= (old_div(math.pi, 180.0))
lat *= (math.pi / 180.0)
lon *= (math.pi / 180.0)

def n(x):
return old_div(wgs84_a, math.sqrt(
1 - wgs84_e2 * (math.sin(x) ** 2)))
return wgs84_a / math.sqrt(1 - wgs84_e2 * (math.sin(x) ** 2))

x = (n(lat) + alt) * math.cos(lat) * math.cos(lon)
y = (n(lat) + alt) * math.cos(lat) * math.sin(lon)
Expand All @@ -40,18 +35,19 @@ def n(x):


def ECEF2LLH(x, y, z):
ep = math.sqrt(old_div((wgs84_a2 - wgs84_b2), wgs84_b2))
ep = math.sqrt((wgs84_a2 - wgs84_b2) / wgs84_b2)
p = math.sqrt(x ** 2 + y ** 2)
th = math.atan2(wgs84_a * z, wgs84_b * p)
lon = math.atan2(y, x)
lat = math.atan2(
z + ep ** 2 * wgs84_b * math.sin(th) ** 3,
p - wgs84_e2 * wgs84_a * math.cos(th) ** 3
)
N = old_div(wgs84_a, math.sqrt(1 - wgs84_e2 * math.sin(lat) ** 2))
alt = old_div(p, math.cos(lat)) - N
N = wgs84_a / math.sqrt(1 - wgs84_e2 * math.sin(lat) ** 2)
alt = p / math.cos(lat) - N

lon *= (old_div(180., math.pi))
lat *= (old_div(180., math.pi))
r = 180 / math.pi
lon *= r
lat *= r

return [lon, lat, alt]

0 comments on commit 3a39615

Please sign in to comment.