From bbb8693298714fcf773726de8e2a8c810e9418e5 Mon Sep 17 00:00:00 2001 From: Charles Jekel Date: Sat, 21 Dec 2019 13:02:24 -0800 Subject: [PATCH] A simple quadrilateral will have at least three of the same sign cross products --- similaritymeasures/VERSION | 2 +- similaritymeasures/similaritymeasures.py | 4 +--- tests/tests.py | 22 +++++++++++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/similaritymeasures/VERSION b/similaritymeasures/VERSION index 267577d..2b7c5ae 100644 --- a/similaritymeasures/VERSION +++ b/similaritymeasures/VERSION @@ -1 +1 @@ -0.4.1 +0.4.2 diff --git a/similaritymeasures/similaritymeasures.py b/similaritymeasures/similaritymeasures.py index 2781113..44a6412 100644 --- a/similaritymeasures/similaritymeasures.py +++ b/similaritymeasures/similaritymeasures.py @@ -97,9 +97,7 @@ def is_simple_quad(ab, bc, cd, da): # Because they don't necessarily need to lie in the same 'Z' direction if sum(crossTF) <= 1: crossTF = cross <= 0 - if sum(crossTF) == 2: - return True - elif sum(crossTF) == 4: + if sum(crossTF) > 2: return True else: return False diff --git a/tests/tests.py b/tests/tests.py index 452762f..ffd0f87 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -135,13 +135,25 @@ def test_P_Q_dtw_minkowski_p3(self): self.assertTrue(r, 3.0) def test_complex_quad(self): - a = [0., 0.] - b = [1., 1.] - c = [1., 0.] - d = [0., 1.] - quad = similaritymeasures.is_simple_quad(a, b, d, c) + x = [0, 1, 1, 0] + y = [0, 1, 0, 1] + AB = [x[1]-x[0], y[1]-y[0]] + BC = [x[2]-x[1], y[2]-y[1]] + CD = [x[3]-x[2], y[3]-y[2]] + DA = [x[0]-x[3], y[0]-y[3]] + quad = similaritymeasures.is_simple_quad(AB, BC, CD, DA) self.assertFalse(quad) + def test_simple_quad(self): + x = [0, 0, 1, 1] + y = [0, 1, 1, 0] + AB = [x[1]-x[0], y[1]-y[0]] + BC = [x[2]-x[1], y[2]-y[1]] + CD = [x[3]-x[2], y[3]-y[2]] + DA = [x[0]-x[3], y[0]-y[3]] + quad = similaritymeasures.is_simple_quad(AB, BC, CD, DA) + self.assertTrue(quad) + def test_random_dtw(self): r, d = similaritymeasures.dtw(curve_a_rand, curve_b_rand) path = similaritymeasures.dtw_path(d)