Vertex now uses true division instead of casting RHS to float
- updated tests
This commit is contained in:
parent
c1f7ee46bc
commit
a4d9129d77
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import division
|
||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@ -66,8 +67,8 @@ class Vertex(object):
|
|||||||
|
|
||||||
def __div__(self, other):
|
def __div__(self, other):
|
||||||
# same assumption as __mult__
|
# same assumption as __mult__
|
||||||
other = float(other)
|
|
||||||
return Vertex(self.x / other, self.y / other, self.z / other)
|
return Vertex(self.x / other, self.y / other, self.z / other)
|
||||||
|
__truediv__ = __div__
|
||||||
|
|
||||||
def __neg__(self):
|
def __neg__(self):
|
||||||
return Vertex(-self.x, -self.y, -self.z)
|
return Vertex(-self.x, -self.y, -self.z)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from surf.geometry import Vertex, cross
|
from surf.geometry import Vertex
|
||||||
|
|
||||||
|
|
||||||
class TestVertexOperations(unittest.TestCase):
|
class TestVertexOperations(unittest.TestCase):
|
||||||
@ -30,6 +30,14 @@ class TestVertexOperations(unittest.TestCase):
|
|||||||
v2 = self.v1 / 2.0
|
v2 = self.v1 / 2.0
|
||||||
self.assertEqual(v1, v2)
|
self.assertEqual(v1, v2)
|
||||||
|
|
||||||
|
def test_inappropriate_division(self):
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
self.v1 / self.v2
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
1.0 / self.v1
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
self.v1 / 'asdf'
|
||||||
|
|
||||||
def test_multiply(self):
|
def test_multiply(self):
|
||||||
self.assertEqual(type(self.v1 * 2), Vertex)
|
self.assertEqual(type(self.v1 * 2), Vertex)
|
||||||
self.assertEqual(type(self.v1 * self.v1), Vertex)
|
self.assertEqual(type(self.v1 * self.v1), Vertex)
|
||||||
@ -37,7 +45,6 @@ class TestVertexOperations(unittest.TestCase):
|
|||||||
self.assertEqual(self.v1 * self.v1, Vertex(0, 0, 0))
|
self.assertEqual(self.v1 * self.v1, Vertex(0, 0, 0))
|
||||||
self.assertEqual(self.v1 * self.v2, Vertex(0, 0, 0))
|
self.assertEqual(self.v1 * self.v2, Vertex(0, 0, 0))
|
||||||
self.assertEqual(self.v3 * self.v4, Vertex(58, -35, -50))
|
self.assertEqual(self.v3 * self.v4, Vertex(58, -35, -50))
|
||||||
|
|
||||||
|
|
||||||
def test_cross(self):
|
def test_cross(self):
|
||||||
i = Vertex(1, 0, 0)
|
i = Vertex(1, 0, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user