def set_from_tuple(self): vec = arkMath.Vec() vec.setFromList((0.5, 0.637)) self.assertEqual(vec.x, .5) self.assertEqual(vec.y, .637) vec = arkMath.Vec() vec.setFromList((0.5, 0.637, 1, .2)) self.assertEqual(vec.x, .5) self.assertEqual(vec.y, .637) self.assertEqual(vec.z, 1) self.assertEqual(vec.w, .2)
def is_matrix(self): matList = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0] matFromList = Mat44(matList) vec1 = arkMath.Vec(1.0, 0.0, 0.0, 0.0) vec2 = arkMath.Vec(0.0, 1.0, 0.0, 0.0) vec3 = arkMath.Vec(0.0, 0.0, 1.0, 0.0) vec4 = arkMath.Vec(0.0, 0.0, 0.0, 1.0) matFromVecs = Mat44(vec1, vec2, vec3, vec4) justVec = arkMath.Vec(1, 2, 3, 4) self.assertEqual(arkMath.isMatrix(matFromList), True) self.assertEqual(arkMath.isMatrix(matFromVecs), True) self.assertEqual(arkMath.isMatrix(justVec), False)
def math(self): # fix: laughable coverage vec = arkMath.Vec(1, 0, 0, 0) self.assertEqual(vec.length(), 1) vec *= 12 self.assertEqual(vec.x, 12) vec = vec.normalize() self.assertEqual(vec.x, 1) vec += arkMath.Vec(1, 1, 1, 1) self.assertEqual(vec.x, 2) self.assertEqual(vec.y, 1) self.assertEqual(vec.z, 1) self.assertEqual(vec.w, 1)
def set_from_list(self): vec = arkMath.Vec() vec.setFromList([0.5, 0.637, 1]) self.assertEqual(vec.x, .5) self.assertEqual(vec.y, .637) self.assertEqual(vec.z, 1) vec = arkMath.Vec() vec.setFromList([0.5, 0.637, 1, .2]) self.assertEqual(vec.x, .5) self.assertEqual(vec.y, .637) self.assertEqual(vec.z, 1) self.assertEqual(vec.w, .2)
def set_from_string(self): vec = arkMath.Vec() vec.setFromString('(0.5, 0.637, 1)') self.assertEqual(vec.x, .5) self.assertEqual(vec.y, .637) self.assertEqual(vec.z, 1) vec = arkMath.Vec() vec.setFromString('( 0.5, -0.637, 1, .2 )') self.assertEqual(vec.x, .5) self.assertEqual(vec.y, -0.637) self.assertEqual(vec.z, 1) self.assertEqual(vec.w, .2)
def serialize(self): vec = arkMath.Vec(1, 0.5, 0.637, 1) print 'vec:', vec x = json.dumps(vec) self.assertEqual(x, '[1, 0.5, 0.637, 1]') data = json.loads(x) self.assertEqual(data, [1, 0.5, 0.637, 1])
def create_from_string(self): vec = arkMath.Vec('(0.5, 0.637, 1)') self.assertEqual(vec.x, .5) self.assertEqual(vec.y, .637) self.assertEqual(vec.z, 1) vec = arkMath.Vec('(0.5, 0.637, 1, .2)') self.assertEqual(vec.x, .5) self.assertEqual(vec.y, .637) self.assertEqual(vec.z, 1) self.assertEqual(vec.w, .2) vec = arkMath.Vec('( 0.5, -.637, 1, .2 )') self.assertEqual(vec.x, .5) self.assertEqual(vec.y, -0.637) self.assertEqual(vec.z, 1) self.assertEqual(vec.w, .2)
def ensure_matrix(self): matList = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0] goalMat = Mat44(matList) sixteenMat = arkMath.ensureMatrix(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0) self.assertEqual(type(sixteenMat), type(goalMat)) vec1 = arkMath.Vec(1.0, 0.0, 0.0, 0.0) vec2 = arkMath.Vec(0.0, 1.0, 0.0, 0.0) vec3 = arkMath.Vec(0.0, 0.0, 1.0, 0.0) vec4 = arkMath.Vec(0.0, 0.0, 0.0, 1.0) vecsMat = arkMath.ensureMatrix(vec1, vec2, vec3, vec4) self.assertEqual(type(vecsMat), type(goalMat)) # Ensure_matrix of already matrix should just return itself selfMat = arkMath.ensureMatrix(goalMat) self.assertEqual(type(selfMat), type(goalMat))
def init(self): vec = arkMath.Vec(1, 2, 3, 4) self.assertEqual(vec.x, 1) self.assertEqual(vec.y, 2) self.assertEqual(vec.z, 3) self.assertEqual(vec.w, 4) self.assertEqual(vec.r, 1) self.assertEqual(vec.g, 2) self.assertEqual(vec.b, 3) self.assertEqual(vec.a, 4) self.assertEqual(vec.h, 1) self.assertEqual(vec.s, 2) self.assertEqual(vec.v, 3) self.assertEqual(vec.a, 4)
def ensure_vector(self): vec = arkMath.Vec(1,2,3,4) ensured = arkMath.ensureVector(vec) self.assertEqual(ensured.x, vec.x) ensured = arkMath.ensureVector(12) self.assertEqual(ensured.x, 12) self.assertEqual(ensured.y, 0) ensured = arkMath.ensureVector(12, 5, 4, 9) self.assertEqual(ensured.x, 12) self.assertEqual(ensured.y, 5) self.assertEqual(ensured.z, 4) self.assertEqual(ensured.w, 9) ensured = arkMath.ensureVector([15, 25, 7, 2]) self.assertEqual(ensured.x, 15) self.assertEqual(ensured.y, 25) self.assertEqual(ensured.z, 7) self.assertEqual(ensured.w, 2)
def is_vector(self): vec = arkMath.Vec(1,2,3,4) self.assertEqual(arkMath.isVector(vec), True) self.assertEqual(arkMath.isVector(12), False)