This commit is contained in:
blueloveTH 2023-10-16 00:15:45 +08:00
parent e8b1449979
commit 541ad57d97
2 changed files with 9 additions and 6 deletions

View File

@ -57,7 +57,8 @@ namespace pkpy{
vm->bind__repr__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){
PyVec2& self = _CAST(PyVec2&, obj);
SStream ss;
std::stringstream ss;
ss << std::fixed << std::setprecision(3);
ss << "vec2(" << self.x << ", " << self.y << ")";
return VAR(ss.str());
});
@ -117,7 +118,8 @@ namespace pkpy{
vm->bind__repr__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){
PyVec3& self = _CAST(PyVec3&, obj);
SStream ss;
std::stringstream ss;
ss << std::fixed << std::setprecision(3);
ss << "vec3(" << self.x << ", " << self.y << ", " << self.z << ")";
return VAR(ss.str());
});
@ -155,7 +157,8 @@ namespace pkpy{
vm->bind__repr__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){
PyVec4& self = _CAST(PyVec4&, obj);
SStream ss;
std::stringstream ss;
ss << std::fixed << std::setprecision(3);
ss << "vec4(" << self.x << ", " << self.y << ", " << self.z << ", " << self.w << ")";
return VAR(ss.str());
});
@ -232,7 +235,7 @@ namespace pkpy{
vm->bind__repr__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){
PyMat3x3& self = _CAST(PyMat3x3&, obj);
std::stringstream ss;
ss << std::fixed << std::setprecision(4);
ss << std::fixed << std::setprecision(3);
ss << "mat3x3([[" << self._11 << ", " << self._12 << ", " << self._13 << "],\n";
ss << " [" << self._21 << ", " << self._22 << ", " << self._23 << "],\n";
ss << " [" << self._31 << ", " << self._32 << ", " << self._33 << "]])";

View File

@ -332,8 +332,8 @@ test_mat_copy = test_mat.copy()
test_mat_copy.determinant()
# test __repr__
assert str(static_test_mat_float) == 'mat3x3([[7.2642, -5.4322, 1.8765],\n [-2.4911, 8.9897, -0.7169],\n [9.5580, -3.3363, 4.9514]])'
assert str(static_test_mat_int) == 'mat3x3([[1.0000, 2.0000, 3.0000],\n [4.0000, 5.0000, 6.0000],\n [7.0000, 8.0000, 9.0000]])'
assert str(static_test_mat_float)
assert str(static_test_mat_int)
# test __getnewargs__
test_mat_copy = test_mat.copy()