Skip to content

Commit

Permalink
feat(gui): add Vector4D / Matrix4x4 classes
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Nov 19, 2020
1 parent d4f9c85 commit fa12f91
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
5 changes: 4 additions & 1 deletion prettyqt/gui/__init__.py
Expand Up @@ -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",
Expand Down Expand Up @@ -133,4 +134,6 @@
"Surface",
"Window",
"DesktopServices",
"Matrix4x4",
"Vector4D",
]
14 changes: 14 additions & 0 deletions 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)
28 changes: 28 additions & 0 deletions 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))
8 changes: 8 additions & 0 deletions tests/test_gui.py
Expand Up @@ -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()

0 comments on commit fa12f91

Please sign in to comment.