mirror of
https://github.com/panda3d/panda3d.git
synced 2026-04-28 18:21:21 -05:00
linmath: Backport support for floor division to 1.10
Backport of 8944737844
(Also fixes return type of `__pow__` to always be derived class)
This commit is contained in:
@@ -2,6 +2,7 @@ from math import floor, ceil
|
||||
import sys
|
||||
|
||||
from panda3d.core import Vec2, Vec3, Vec4, Vec2F, Vec2D
|
||||
from panda3d import core
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -121,3 +122,22 @@ def test_vec2_ceil():
|
||||
rounded_vector = ceil(original_vector)
|
||||
assert rounded_vector.x == 3
|
||||
assert rounded_vector.y == -2
|
||||
|
||||
|
||||
@pytest.mark.parametrize("type", (core.LVecBase2f, core.LVecBase2d, core.LVecBase2i))
|
||||
def test_vec2_floordiv(type):
|
||||
with pytest.raises(ZeroDivisionError):
|
||||
type(1, 2) // 0
|
||||
|
||||
for i in range(-100, 100):
|
||||
for j in range(1, 100):
|
||||
assert (type(i) // j).x == i // j
|
||||
assert (type(i) // -j).x == i // -j
|
||||
|
||||
v = type(i)
|
||||
v //= j
|
||||
assert v.x == i // j
|
||||
|
||||
v = type(i)
|
||||
v //= -j
|
||||
assert v.x == i // -j
|
||||
|
||||
@@ -2,6 +2,7 @@ from math import floor, ceil
|
||||
import sys
|
||||
|
||||
from panda3d.core import Vec2, Vec3, Vec3F, Vec3D
|
||||
from panda3d import core
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -106,3 +107,22 @@ def test_vec3_ceil():
|
||||
assert rounded_vector.x == 3
|
||||
assert rounded_vector.y == -2
|
||||
assert rounded_vector.z == 4
|
||||
|
||||
|
||||
@pytest.mark.parametrize("type", (core.LVecBase3f, core.LVecBase3d, core.LVecBase3i))
|
||||
def test_vec3_floordiv(type):
|
||||
with pytest.raises(ZeroDivisionError):
|
||||
type(1, 2, 3) // 0
|
||||
|
||||
for i in range(-100, 100):
|
||||
for j in range(1, 100):
|
||||
assert (type(i) // j).x == i // j
|
||||
assert (type(i) // -j).x == i // -j
|
||||
|
||||
v = type(i)
|
||||
v //= j
|
||||
assert v.x == i // j
|
||||
|
||||
v = type(i)
|
||||
v //= -j
|
||||
assert v.x == i // -j
|
||||
|
||||
@@ -2,6 +2,7 @@ from math import floor, ceil
|
||||
import sys
|
||||
|
||||
from panda3d.core import Vec2, Vec3, Vec4, Vec4F, Vec4D
|
||||
from panda3d import core
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -122,3 +123,22 @@ def test_vec4_ceil():
|
||||
assert rounded_vector.y == -2
|
||||
assert rounded_vector.z == 4
|
||||
assert rounded_vector.w == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("type", (core.LVecBase4f, core.LVecBase4d, core.LVecBase4i))
|
||||
def test_vec4_floordiv(type):
|
||||
with pytest.raises(ZeroDivisionError):
|
||||
type(1, 2, 3, 4) // 0
|
||||
|
||||
for i in range(-100, 100):
|
||||
for j in range(1, 100):
|
||||
assert (type(i) // j).x == i // j
|
||||
assert (type(i) // -j).x == i // -j
|
||||
|
||||
v = type(i)
|
||||
v //= j
|
||||
assert v.x == i // j
|
||||
|
||||
v = type(i)
|
||||
v //= -j
|
||||
assert v.x == i // -j
|
||||
|
||||
Reference in New Issue
Block a user