mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 08:15:18 -04:00
parent
2960b67c7a
commit
ffed59679d
@ -1,30 +1,90 @@
|
|||||||
from math import floor, ceil
|
from math import floor, ceil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from panda3d.core import Vec2, Vec3, Vec4, Vec2F, Vec2D
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from panda3d.core import Vec2
|
|
||||||
|
|
||||||
|
|
||||||
original_vector = Vec2(2.3, -2.6)
|
|
||||||
|
|
||||||
reason = '''Rounding in Python 2.7 expects to return a float value, since it returns a Vector it
|
reason = '''Rounding in Python 2.7 expects to return a float value, since it returns a Vector it
|
||||||
does not work. When Python 2.7 gets deprecated, remove this check.'''
|
does not work. When Python 2.7 gets deprecated, remove this check.'''
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
||||||
def test_round():
|
def test_round():
|
||||||
|
original_vector = Vec2(2.3, -2.6)
|
||||||
|
|
||||||
rounded_vector = round(original_vector)
|
rounded_vector = round(original_vector)
|
||||||
assert rounded_vector.x == 2
|
assert rounded_vector.x == 2
|
||||||
assert rounded_vector.y == -3
|
assert rounded_vector.y == -3
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
||||||
def test_floor():
|
def test_floor():
|
||||||
|
original_vector = Vec2(2.3, -2.6)
|
||||||
|
|
||||||
rounded_vector = floor(original_vector)
|
rounded_vector = floor(original_vector)
|
||||||
assert rounded_vector.x == 2
|
assert rounded_vector.x == 2
|
||||||
assert rounded_vector.y == -3
|
assert rounded_vector.y == -3
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
||||||
def test_ceil():
|
def test_ceil():
|
||||||
|
original_vector = Vec2(2.3, -2.6)
|
||||||
|
|
||||||
rounded_vector = ceil(original_vector)
|
rounded_vector = ceil(original_vector)
|
||||||
assert rounded_vector.x == 3
|
assert rounded_vector.x == 3
|
||||||
assert rounded_vector.y == -2
|
assert rounded_vector.y == -2
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec2_creation():
|
||||||
|
assert Vec2(x=1, y=2) == Vec2(1, 2) == Vec2((1, 2))
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec2_getter_setter():
|
||||||
|
original_vector = Vec2(2, 3)
|
||||||
|
|
||||||
|
assert original_vector.x == 2
|
||||||
|
assert original_vector.y == 3
|
||||||
|
|
||||||
|
original_vector.x = 1
|
||||||
|
original_vector.y = 3
|
||||||
|
|
||||||
|
assert original_vector == Vec2(1, 3)
|
||||||
|
|
||||||
|
original_vector[0] = 3
|
||||||
|
original_vector[1] = 1
|
||||||
|
|
||||||
|
assert original_vector == Vec2(3, 1)
|
||||||
|
|
||||||
|
original_vector.set_x(-8)
|
||||||
|
original_vector.set_y(6)
|
||||||
|
|
||||||
|
assert original_vector.x == -8
|
||||||
|
assert original_vector.y == 6
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec2_sum():
|
||||||
|
original_vector = Vec2(2, 3)
|
||||||
|
|
||||||
|
assert original_vector + original_vector == Vec2(4, 6)
|
||||||
|
assert original_vector + 3 == Vec2(5, 6)
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec2_power():
|
||||||
|
assert Vec2(2, -3) ** 2 == Vec2(4, 9)
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec2_len():
|
||||||
|
assert len(Vec2(2, -3)) == 2
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec2_swizzle_mask():
|
||||||
|
original_vector = Vec2(3, 5)
|
||||||
|
|
||||||
|
assert original_vector.yx == Vec2(5, 3)
|
||||||
|
assert original_vector.xy == original_vector
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec2_str():
|
||||||
|
assert str(Vec2F(2, 3)) == "LVector2f(2, 3)"
|
||||||
|
assert str(Vec2D(2, 3)) == "LVector2d(2, 3)"
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
from math import floor, ceil
|
from math import floor, ceil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from panda3d.core import Vec2, Vec3, Vec3F, Vec3D
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from panda3d.core import Vec3
|
|
||||||
|
|
||||||
|
|
||||||
original_vector = Vec3(2.3, -2.6, 3.5)
|
|
||||||
|
|
||||||
reason = '''Rounding in Python 2.7 expects to return a float value, since it returns a Vector it
|
reason = '''Rounding in Python 2.7 expects to return a float value, since it returns a Vector it
|
||||||
does not work. When Python 2.7 gets deprecated, remove this check.'''
|
does not work. When Python 2.7 gets deprecated, remove this check.'''
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
||||||
def test_round():
|
def test_round():
|
||||||
|
original_vector = Vec3(2.3, -2.6, 3.5)
|
||||||
|
|
||||||
rounded_vector = round(original_vector)
|
rounded_vector = round(original_vector)
|
||||||
assert rounded_vector.x == 2
|
assert rounded_vector.x == 2
|
||||||
assert rounded_vector.y == -3
|
assert rounded_vector.y == -3
|
||||||
@ -21,6 +20,8 @@ def test_round():
|
|||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
||||||
def test_floor():
|
def test_floor():
|
||||||
|
original_vector = Vec3(2.3, -2.6, 3.5)
|
||||||
|
|
||||||
rounded_vector = floor(original_vector)
|
rounded_vector = floor(original_vector)
|
||||||
assert rounded_vector.x == 2
|
assert rounded_vector.x == 2
|
||||||
assert rounded_vector.y == -3
|
assert rounded_vector.y == -3
|
||||||
@ -29,7 +30,67 @@ def test_floor():
|
|||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
||||||
def test_ceil():
|
def test_ceil():
|
||||||
|
original_vector = Vec3(2.3, -2.6, 3.5)
|
||||||
|
|
||||||
rounded_vector = ceil(original_vector)
|
rounded_vector = ceil(original_vector)
|
||||||
assert rounded_vector.x == 3
|
assert rounded_vector.x == 3
|
||||||
assert rounded_vector.y == -2
|
assert rounded_vector.y == -2
|
||||||
assert rounded_vector.z == 4
|
assert rounded_vector.z == 4
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec3_creation():
|
||||||
|
assert Vec3(x=1, y=2, z=1) == Vec3(1, 2, 1) == Vec3((1, 2, 1))
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec3_getter_setter():
|
||||||
|
original_vector = Vec3(2, 3, 7)
|
||||||
|
|
||||||
|
assert original_vector.x == 2
|
||||||
|
assert original_vector.y == 3
|
||||||
|
assert original_vector.z == 7
|
||||||
|
|
||||||
|
original_vector.x = 1
|
||||||
|
original_vector.y = 3
|
||||||
|
original_vector.z = 5
|
||||||
|
|
||||||
|
assert original_vector == Vec3(1, 3, 5)
|
||||||
|
|
||||||
|
original_vector[0] = 3
|
||||||
|
original_vector[1] = 1
|
||||||
|
original_vector[2] = 1
|
||||||
|
|
||||||
|
assert original_vector == Vec3(3, 1, 1)
|
||||||
|
|
||||||
|
original_vector.set_x(-8)
|
||||||
|
original_vector.set_y(6)
|
||||||
|
original_vector.set_z(10)
|
||||||
|
|
||||||
|
assert original_vector.x == -8
|
||||||
|
assert original_vector.y == 6
|
||||||
|
assert original_vector.z == 10
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec3_sum():
|
||||||
|
original_vector = Vec3(2, 3, -2)
|
||||||
|
|
||||||
|
assert original_vector + original_vector == Vec3(4, 6, -4)
|
||||||
|
assert original_vector + 3 == Vec3(5, 6, 1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec3_power():
|
||||||
|
assert Vec3(2, -3, 2) ** 2 == Vec3(4, 9, 4)
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec3_len():
|
||||||
|
assert len(Vec3(2, -3, 10)) == 3
|
||||||
|
|
||||||
|
def test_vec3_swizzle_mask():
|
||||||
|
original_vector = Vec3(3, 5, 1)
|
||||||
|
|
||||||
|
assert original_vector.xy == Vec2(3, 5)
|
||||||
|
assert original_vector.zxy == Vec3(1, 3, 5)
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec3_str():
|
||||||
|
assert str(Vec3F(2, 3, 1)) == "LVector3f(2, 3, 1)"
|
||||||
|
assert str(Vec3D(2, 3, 1)) == "LVector3d(2, 3, 1)"
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
from math import floor, ceil
|
from math import floor, ceil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from panda3d.core import Vec2, Vec3, Vec4, Vec4F, Vec4D
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from panda3d.core import Vec4
|
|
||||||
|
|
||||||
|
|
||||||
original_vector = Vec4(2.3, -2.6, 3.5, 1)
|
|
||||||
|
|
||||||
reason = '''Rounding in Python 2.7 expects to return a float value, since it returns a Vector it
|
reason = '''Rounding in Python 2.7 expects to return a float value, since it returns a Vector it
|
||||||
does not work. When Python 2.7 gets deprecated, remove this check.'''
|
does not work. When Python 2.7 gets deprecated, remove this check.'''
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
||||||
def test_round():
|
def test_round():
|
||||||
|
original_vector = Vec4(2.3, -2.6, 3.5, 1)
|
||||||
|
|
||||||
rounded_vector = round(original_vector)
|
rounded_vector = round(original_vector)
|
||||||
assert rounded_vector.x == 2
|
assert rounded_vector.x == 2
|
||||||
assert rounded_vector.y == -3
|
assert rounded_vector.y == -3
|
||||||
@ -22,6 +21,8 @@ def test_round():
|
|||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
||||||
def test_floor():
|
def test_floor():
|
||||||
|
original_vector = Vec4(2.3, -2.6, 3.5, 1)
|
||||||
|
|
||||||
rounded_vector = floor(original_vector)
|
rounded_vector = floor(original_vector)
|
||||||
assert rounded_vector.x == 2
|
assert rounded_vector.x == 2
|
||||||
assert rounded_vector.y == -3
|
assert rounded_vector.y == -3
|
||||||
@ -31,8 +32,75 @@ def test_floor():
|
|||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
@pytest.mark.skipif(sys.version_info < (3, 5), reason=reason)
|
||||||
def test_ceil():
|
def test_ceil():
|
||||||
|
original_vector = Vec4(2.3, -2.6, 3.5, 1)
|
||||||
|
|
||||||
rounded_vector = ceil(original_vector)
|
rounded_vector = ceil(original_vector)
|
||||||
assert rounded_vector.x == 3
|
assert rounded_vector.x == 3
|
||||||
assert rounded_vector.y == -2
|
assert rounded_vector.y == -2
|
||||||
assert rounded_vector.z == 4
|
assert rounded_vector.z == 4
|
||||||
assert rounded_vector.w == 1
|
assert rounded_vector.w == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec4_creation():
|
||||||
|
assert Vec4(x=1, y=2, z=1, w=7) == Vec4(1, 2, 1, 7) == Vec4((1, 2, 1, 7))
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec4_getter_setter():
|
||||||
|
original_vector = Vec4(2, 3, 7, 9)
|
||||||
|
|
||||||
|
assert original_vector.x == 2
|
||||||
|
assert original_vector.y == 3
|
||||||
|
assert original_vector.z == 7
|
||||||
|
assert original_vector.w == 9
|
||||||
|
|
||||||
|
original_vector.x = 1
|
||||||
|
original_vector.y = 3
|
||||||
|
original_vector.z = 5
|
||||||
|
original_vector.w = -8
|
||||||
|
|
||||||
|
assert original_vector == Vec4(1, 3, 5, -8)
|
||||||
|
|
||||||
|
original_vector[0] = 3
|
||||||
|
original_vector[1] = 1
|
||||||
|
original_vector[2] = 1
|
||||||
|
original_vector[3] = -2
|
||||||
|
|
||||||
|
assert original_vector == Vec4(3, 1, 1, -2)
|
||||||
|
|
||||||
|
original_vector.set_x(-8)
|
||||||
|
original_vector.set_y(6)
|
||||||
|
original_vector.set_z(10)
|
||||||
|
original_vector.set_w(30)
|
||||||
|
|
||||||
|
assert original_vector.x == -8
|
||||||
|
assert original_vector.y == 6
|
||||||
|
assert original_vector.z == 10
|
||||||
|
assert original_vector.w == 30
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec4_sum():
|
||||||
|
original_vector = Vec4(2, 3, -2, 1)
|
||||||
|
|
||||||
|
assert original_vector + original_vector == Vec4(4, 6, -4, 2)
|
||||||
|
assert original_vector + 3 == Vec4(5, 6, 1, 4)
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec4_power():
|
||||||
|
assert Vec4(2, -3, 2, -1) ** 2 == Vec4(4, 9, 4, 1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec4_len():
|
||||||
|
assert len(Vec4(2, -3, 10, 30)) == 4
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec4_swizzle_mask():
|
||||||
|
original_vector = Vec4(3, 5, 1, 0)
|
||||||
|
|
||||||
|
assert original_vector.xy == Vec2(3, 5)
|
||||||
|
assert original_vector.zxy == Vec3(1, 3, 5)
|
||||||
|
assert original_vector.zxyw == Vec4(1, 3, 5, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_vec4_str():
|
||||||
|
assert str(Vec4F(2, 3, 1, 9)) == "LVector4f(2, 3, 1, 9)"
|
||||||
|
assert str(Vec4D(2, 3, 1, 9)) == "LVector4d(2, 3, 1, 9)"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user