forked from AntSimi/py-eddy-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_poly.py
More file actions
31 lines (21 loc) · 858 Bytes
/
test_poly.py
File metadata and controls
31 lines (21 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from numpy import array, pi
from pytest import approx
from py_eddy_tracker.poly import convex, fit_circle, get_convex_hull, poly_area_vertice
# Vertices for next test
V = array(((2, 2, 3, 3, 2), (-10, -9, -9, -10, -10)))
V_concave = array(((2, 2, 2.5, 3, 3, 2), (-10, -9, -9.5, -9, -10, -10)))
def test_poly_area():
assert 1 == poly_area_vertice(V.T)
def test_fit_circle():
x0, y0, r, err = fit_circle(*V)
assert x0 == approx(2.5, rel=1e-10)
assert y0 == approx(-9.5, rel=1e-10)
assert r == approx(2 ** 0.5 / 2, rel=1e-10)
assert err == approx((1 - 2 / pi) * 100, rel=1e-10)
def test_convex():
assert convex(*V) is True
assert convex(*V[::-1]) is True
assert convex(*V_concave) is False
assert convex(*V_concave[::-1]) is False
def test_convex_hull():
assert convex(*get_convex_hull(*V_concave)) is True