Skip to content

Commit

Permalink
dg3c: ensure that arguments to up are exactly 3d (#313)
Browse files Browse the repository at this point in the history
Adds tuple unpacking from inputs for d3ga up function, so that it throws a ValueError if a list of the wrong length is passed.
  • Loading branch information
hugohadfield committed May 18, 2020
1 parent d3ef9ce commit e22f827
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions clifford/dg3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def up_cga1(pnt_vector):
Take a vector and embed it as a point in the first
copy of cga
"""
euc_point = pnt_vector[0]*e1 + pnt_vector[1]*e2 + pnt_vector[2]*e3
x, y, z = pnt_vector
euc_point = x*e1 + y*e2 + z*e3
return euc_point + 0.5*(euc_point|euc_point)*einf1 + eo1


Expand All @@ -54,7 +55,8 @@ def up_cga2(pnt_vector):
Take a vector and embed it as a point in the second
copy of cga
"""
euc_point = pnt_vector[0]*e6 + pnt_vector[1]*e7 + pnt_vector[2]*e8
x, y, z = pnt_vector
euc_point = x*e6 + y*e7 + z*e8
return euc_point + 0.5*euc_point**2*einf2 + eo2


Expand Down
9 changes: 9 additions & 0 deletions clifford/test/test_dg3c.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import pytest
import numpy as np
from ..dg3c import *

Expand Down Expand Up @@ -40,6 +41,10 @@ def test_up_down(self):
res = down(100*pnt)
np.testing.assert_allclose(res, pnt_vector)

# Assert an error is raised if the point is not 3d
with pytest.raises(ValueError):
up([1, 2, 3, 4])

def test_up_down_cga1(self):
"""
Test that we can map points up and down from cga1
Expand All @@ -51,6 +56,10 @@ def test_up_down_cga1(self):
res = down_cga1(100*pnt)
np.testing.assert_allclose(res, pnt_vector)

# Assert an error is raised if the point is not 3d
with pytest.raises(ValueError):
up_cga1([1, 2, 3, 4])


class GeometricPrimitiveTests(unittest.TestCase):
def test_reciprocality(self):
Expand Down

0 comments on commit e22f827

Please sign in to comment.