Skip to content

Commit

Permalink
Add type hints in geometrical functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayitzin committed Feb 1, 2021
1 parent 4b0d3c4 commit ad265e3
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions ahrs/common/geometry.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,62 @@
#! /usr/bin/python3
# -*- coding: utf-8 -*-
"""
Geometrical routines
Geometrical functions
---------------------
References
----------
.. [W1] Wikipedia: https://de.wikipedia.org/wiki/Ellipse#Ellipsengleichung_(Parameterform)
.. [WAE] Wolfram Alpha: Ellipse. (http://mathworld.wolfram.com/Ellipse.html)
"""

import numpy as np
from typing import Union

def circle(center, radius=1.0, num_points=20):
def circle(center: Union[list, np.ndarray], radius: float = 1.0, num_points: int = 20) -> np.ndarray:
"""
Build a circle with the given characteristics.
Parameters
----------
c : array
c : array-like
2D Coordinates of center.
r : float
Radius of the circle.
num_points : int
Number of points.
Number of points to build.
Returns
-------
points : array
points : numpy.ndarray
N-by-2 array with the coordinates of the circle.
References
----------
.. [WAC] Wolfram Alpha: Circle. (http://mathworld.wolfram.com/Circle.html)
"""
R = np.linspace(0.0, 2.0*np.pi, num_points+1)
x = center[0] + radius*np.cos(R)
y = center[1] + radius*np.sin(R)
return np.array([x, y]).transpose()

def ellipse(center, phi, axes, num_points=20):
def ellipse(center: Union[list, np.ndarray], phi: float, axes: : Union[list, np.ndarray], num_points: int = 20) -> np.ndarray:
"""
Build an ellipse with the given characteristics.
Parameters
----------
center : array
center : array-like
2D Coordinates of center.
phi : float
Angle, in radians, of the major axis w.r.t. the X-axis
axes : array
axes : array-like
Lengths of major and minor axes, respectively.
num_points : int
Number of points. Defaults to 20.
Returns
-------
points : array
points : numpy.ndarray
N-by-2 array with the coordinates of the ellipse.
References
----------
.. [W1] Wikipedia: https://de.wikipedia.org/wiki/Ellipse#Ellipsengleichung_(Parameterform)
.. [WAE] Wolfram Alpha: Ellipse. (http://mathworld.wolfram.com/Ellipse.html)
"""
R = np.linspace(0.0, 2.0*np.pi, num_points+1)
a, b = axes
Expand Down

0 comments on commit ad265e3

Please sign in to comment.