diff --git a/prettyqt/gui/__init__.py b/prettyqt/gui/__init__.py index 1b1282513..7d5df3f4e 100644 --- a/prettyqt/gui/__init__.py +++ b/prettyqt/gui/__init__.py @@ -71,7 +71,8 @@ from .syntaxhighlighter import SyntaxHighlighter from .pdfwriter import PdfWriter from .desktopservices import DesktopServices - +from .matrix4x4 import Matrix4x4 +from .vector4d import Vector4D __all__ = [ "KeyEvent", @@ -133,4 +134,6 @@ "Surface", "Window", "DesktopServices", + "Matrix4x4", + "Vector4D", ] diff --git a/prettyqt/gui/matrix4x4.py b/prettyqt/gui/matrix4x4.py new file mode 100644 index 000000000..497d738bc --- /dev/null +++ b/prettyqt/gui/matrix4x4.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +from qtpy import QtGui + + +class Matrix4x4(QtGui.QMatrix4x4): + # def __repr__(self): + # return f"{type(self).__name__}()" + pass + + +if __name__ == "__main__": + matrix = Matrix4x4([1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) + print(matrix) diff --git a/prettyqt/gui/vector4d.py b/prettyqt/gui/vector4d.py new file mode 100644 index 000000000..b73f0df03 --- /dev/null +++ b/prettyqt/gui/vector4d.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +from qtpy import QtGui + +from prettyqt import core + + +class Vector4D(QtGui.QVector4D): + # def __repr__(self): + # return f"{type(self).__name__}()" + pass + + def __bool__(self): + return not self.isNull() + + def __abs__(self) -> float: + return self.length() + + def to_point(self) -> core.Point: + return core.Point(self.toPoint()) + + def to_pointf(self) -> core.PointF: + return core.PointF(self.toPointF()) + + +if __name__ == "__main__": + vector = Vector4D(0, 0, 0, 1) + print(abs(vector)) diff --git a/tests/test_gui.py b/tests/test_gui.py index 4285bfa73..c6daccb09 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -481,3 +481,11 @@ def test_window(): def test_validator(): gui.Validator() + + +def test_vector4d(): + vector = gui.Vector4D(0, 0, 0, 1) + assert abs(vector) == 1.0 + assert bool(vector) is True + vector.to_point() + vector.to_pointf()