Compare commits
2
Commits
7c2e2782ec
...
77a2faa345
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77a2faa345 | ||
|
|
b5c3ce3308 |
No files matched your search
Generated
-14
@@ -1,14 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="PYTHON_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="jdk" jdkName="~\PycharmProjects\matrixmania\.venv" jdkType="Python SDK" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
<component name="PackageRequirementsSettings" />
|
|
||||||
<component name="PyDocumentationSettings" />
|
|
||||||
<component name="ReSTService" />
|
|
||||||
<component name="TestRunnerService" />
|
|
||||||
</module>
|
|
||||||
Generated
+1
@@ -3,6 +3,7 @@
|
|||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/matrixmania.iml" filepath="$PROJECT_DIR$/.idea/matrixmania.iml" />
|
<module fileurl="file://$PROJECT_DIR$/.idea/matrixmania.iml" filepath="$PROJECT_DIR$/.idea/matrixmania.iml" />
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/matrixmania@1.iml" filepath="$PROJECT_DIR$/.idea/matrixmania@1.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
Generated
+143
-7
@@ -4,19 +4,30 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="32afd46d-add2-46b7-adb8-c1257e181060" name="Changes" comment="second" />
|
<list default="true" id="32afd46d-add2-46b7-adb8-c1257e181060" name="Changes" comment="structure redefined and tests implemented">
|
||||||
|
<change afterPath="$PROJECT_DIR$/test/test_matrixmania/test_projection.py" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/matrixmania/compute.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/matrixmania/compute.py" afterDir="false" />
|
||||||
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="FileTemplateManagerImpl">
|
||||||
|
<option name="RECENT_TEMPLATES">
|
||||||
|
<list>
|
||||||
|
<option value="Python Script" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectColorInfo"><![CDATA[{
|
<component name="ProjectColorInfo">{
|
||||||
"associatedIndex": 4,
|
"associatedIndex": 4,
|
||||||
"fromUser": false
|
"fromUser": false
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="ProjectId" id="3Kjg54ruNHC2aqLlG9PEoEnFRxm" />
|
<component name="ProjectId" id="3Kjg54ruNHC2aqLlG9PEoEnFRxm" />
|
||||||
<component name="ProjectViewState">
|
<component name="ProjectViewState">
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
@@ -25,12 +36,20 @@
|
|||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||||
|
"Python tests.Python tests for test.test_matrixmania.test_projection.test_project_ortho_no_scale.executor": "Run",
|
||||||
|
"Python tests.Python tests for test.test_matrixmania.test_projection.test_project_ortho_scale.executor": "Run",
|
||||||
|
"Python tests.Python tests for test.test_matrixmania.test_rot.test_rot_2d.executor": "Run",
|
||||||
|
"Python tests.Python tests in test_rot.py.executor": "Run",
|
||||||
|
"Python.compute.executor": "Run",
|
||||||
|
"Python.install_dependencies.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
||||||
"codeWithMe.voiceChat.enabledByDefault": "false",
|
"codeWithMe.voiceChat.enabledByDefault": "false",
|
||||||
"git-widget-placeholder": "master",
|
"git-widget-placeholder": "master",
|
||||||
"last_opened_file_path": "C:/Users/julia/PycharmProjects/matrixmania",
|
"last_opened_file_path": "C:/Users/julia/PycharmProjects/matrixmania",
|
||||||
|
"node.js.detected.package.jshint": "true",
|
||||||
|
"node.js.selected.package.jshint": "",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"python.packages.toolwindow.project.migrated.to.right.top.v2": "true"
|
"python.packages.toolwindow.project.migrated.to.right.top.v2": "true"
|
||||||
}
|
}
|
||||||
@@ -39,6 +58,94 @@
|
|||||||
<key name="CopyFile.RECENT_KEYS">
|
<key name="CopyFile.RECENT_KEYS">
|
||||||
<recent name="C:\Users\julia\PycharmProjects\matrixmania" />
|
<recent name="C:\Users\julia\PycharmProjects\matrixmania" />
|
||||||
</key>
|
</key>
|
||||||
|
<key name="MoveFile.RECENT_KEYS">
|
||||||
|
<recent name="C:\Users\julia\PycharmProjects\matrixmania\src\matrixmania" />
|
||||||
|
</key>
|
||||||
|
</component>
|
||||||
|
<component name="RunManager" selected="Python tests.Python tests for test.test_matrixmania.test_projection.test_project_ortho_scale">
|
||||||
|
<configuration name="install_dependencies" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="matrixmania@1" />
|
||||||
|
<option name="ENV_FILES" value="" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<envs>
|
||||||
|
<env name="PYTHONUNBUFFERED" value="1" />
|
||||||
|
</envs>
|
||||||
|
<option name="SDK_HOME" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||||
|
<option name="IS_MODULE_SDK" value="true" />
|
||||||
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
|
<option name="DEBUG_JUST_MY_CODE" value="false" />
|
||||||
|
<option name="RUN_TOOL" value="" />
|
||||||
|
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/install_dependencies.py" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||||
|
<option name="EMULATE_TERMINAL" value="false" />
|
||||||
|
<option name="MODULE_MODE" value="false" />
|
||||||
|
<option name="REDIRECT_INPUT" value="false" />
|
||||||
|
<option name="INPUT_FILE" value="" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
<configuration name="Python tests for test.test_matrixmania.test_projection.test_project_ortho_no_scale" type="tests" factoryName="Autodetect" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="matrixmania@1" />
|
||||||
|
<option name="ENV_FILES" value="" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<option name="SDK_HOME" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||||
|
<option name="IS_MODULE_SDK" value="true" />
|
||||||
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
|
<option name="DEBUG_JUST_MY_CODE" value="false" />
|
||||||
|
<option name="RUN_TOOL" value="" />
|
||||||
|
<option name="_new_additionalArguments" value="""" />
|
||||||
|
<option name="_new_target" value=""test.test_matrixmania.test_projection.test_project_ortho_no_scale"" />
|
||||||
|
<option name="_new_targetType" value=""PYTHON"" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
<configuration name="Python tests for test.test_matrixmania.test_projection.test_project_ortho_scale" type="tests" factoryName="Autodetect" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="matrixmania@1" />
|
||||||
|
<option name="ENV_FILES" value="" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<option name="SDK_HOME" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||||
|
<option name="IS_MODULE_SDK" value="true" />
|
||||||
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
|
<option name="DEBUG_JUST_MY_CODE" value="false" />
|
||||||
|
<option name="RUN_TOOL" value="" />
|
||||||
|
<option name="_new_additionalArguments" value="""" />
|
||||||
|
<option name="_new_target" value=""test.test_matrixmania.test_projection.test_project_ortho_scale"" />
|
||||||
|
<option name="_new_targetType" value=""PYTHON"" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
<configuration name="Python tests for test.test_matrixmania.test_rot.test_rot_2d" type="tests" factoryName="Autodetect" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="matrixmania@1" />
|
||||||
|
<option name="ENV_FILES" value="" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<option name="SDK_HOME" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||||
|
<option name="IS_MODULE_SDK" value="true" />
|
||||||
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
|
<option name="DEBUG_JUST_MY_CODE" value="false" />
|
||||||
|
<option name="RUN_TOOL" value="" />
|
||||||
|
<option name="_new_additionalArguments" value="""" />
|
||||||
|
<option name="_new_target" value=""test.test_matrixmania.test_rot.test_rot_2d"" />
|
||||||
|
<option name="_new_targetType" value=""PYTHON"" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
<recent_temporary>
|
||||||
|
<list>
|
||||||
|
<item itemvalue="Python tests.Python tests for test.test_matrixmania.test_projection.test_project_ortho_scale" />
|
||||||
|
<item itemvalue="Python tests.Python tests for test.test_matrixmania.test_projection.test_project_ortho_no_scale" />
|
||||||
|
<item itemvalue="Python tests.Python tests for test.test_matrixmania.test_rot.test_rot_2d" />
|
||||||
|
<item itemvalue="Python.install_dependencies" />
|
||||||
|
</list>
|
||||||
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
<component name="SharedIndexes">
|
<component name="SharedIndexes">
|
||||||
<attachedChunks>
|
<attachedChunks>
|
||||||
@@ -71,15 +178,44 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1792076682847</updated>
|
<updated>1792076682847</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="3" />
|
<task id="LOCAL-00003" summary="tabulate and ruff added">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1792077022970</created>
|
||||||
|
<option name="number" value="00003" />
|
||||||
|
<option name="presentableId" value="LOCAL-00003" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1792077022970</updated>
|
||||||
|
</task>
|
||||||
|
<task id="LOCAL-00004" summary="structure redefined and tests implemented">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1792679838169</created>
|
||||||
|
<option name="number" value="00004" />
|
||||||
|
<option name="presentableId" value="LOCAL-00004" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1792679838169</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="5" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
<option name="version" value="3" />
|
<option name="version" value="3" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
<option name="TAB_STATES">
|
||||||
|
<map>
|
||||||
|
<entry key="MAIN">
|
||||||
|
<value>
|
||||||
|
<State />
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<MESSAGE value="first commit" />
|
<MESSAGE value="first commit" />
|
||||||
<MESSAGE value="second" />
|
<MESSAGE value="second" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="second" />
|
<MESSAGE value="tabulate and ruff added" />
|
||||||
|
<MESSAGE value="structure redefined and tests implemented" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="structure redefined and tests implemented" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -2,3 +2,7 @@
|
|||||||
- Code nach PEP 8, Zeilenlänge maximal 88 Zeichen.
|
- Code nach PEP 8, Zeilenlänge maximal 88 Zeichen.
|
||||||
- Jede Funktion und Methode hat einen Docstring und Type Hints.
|
- Jede Funktion und Methode hat einen Docstring und Type Hints.
|
||||||
- Vor jedem Commit: `ruff check` und `ruff format`.
|
- Vor jedem Commit: `ruff check` und `ruff format`.
|
||||||
|
|
||||||
|
## Projektstruktur
|
||||||
|
- Quellcode liegt unter "src/matrixmania/", Tests unter "test/test_matrixmania/"
|
||||||
|
- Testpakete, Testdateien und Testfunktionen beginnen mit "test_"
|
||||||
@@ -2,3 +2,7 @@
|
|||||||
name = "matrixmania"
|
name = "matrixmania"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = ["tabulate", "ruff"]
|
dependencies = ["tabulate", "ruff"]
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
pythonpath = "src"
|
||||||
|
[project.optional-dependencies]
|
||||||
|
dev = ["pytest", "ruff", "pytest-cov"]
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from .compute import matmul, rot_2d, rot_3d, transpose
|
||||||
|
|
||||||
|
__all__ = ["matmul", "rot_2d", "rot_3d", "transpose"]
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
"""Modul zur Matrizenmultiplikation."""
|
"""Modul zur Matrizenmultiplikation."""
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import sys
|
|
||||||
from numbers import Number
|
from numbers import Number
|
||||||
from tabulate import tabulate
|
|
||||||
|
|
||||||
def _validate_matrix(matrix: object, name: str) -> list[list[Number]]:
|
def _validate_matrix(matrix: object, name: str) -> list[list[Number]]:
|
||||||
"""Prüft, ob es sich um eine gültige Matrix handelt.
|
"""Prüft, ob es sich um eine gültige Matrix handelt.
|
||||||
@@ -22,14 +21,18 @@ def _validate_matrix(matrix: object, name: str) -> list[list[Number]]:
|
|||||||
aufweist.
|
aufweist.
|
||||||
"""
|
"""
|
||||||
if not isinstance(matrix, list):
|
if not isinstance(matrix, list):
|
||||||
raise TypeError(f"'{name}' muss eine Liste von Listen sein, nicht {type(matrix).__name__}.")
|
raise TypeError(
|
||||||
|
f"'{name}' muss eine Liste von Listen sein, nicht {type(matrix).__name__}."
|
||||||
|
)
|
||||||
|
|
||||||
if len(matrix) == 0:
|
if len(matrix) == 0:
|
||||||
raise ValueError(f"'{name}' darf nicht leer sein.")
|
raise ValueError(f"'{name}' darf nicht leer sein.")
|
||||||
|
|
||||||
for index, row in enumerate(matrix):
|
for index, row in enumerate(matrix):
|
||||||
if not isinstance(row, list):
|
if not isinstance(row, list):
|
||||||
raise TypeError(f"Zeile {index} von '{name}' muss eine Liste sein, nicht {type(row).__name__}.")
|
raise TypeError(
|
||||||
|
f"Zeile {index} von '{name}' muss eine Liste sein, nicht {type(row).__name__}."
|
||||||
|
)
|
||||||
|
|
||||||
if len(row) == 0:
|
if len(row) == 0:
|
||||||
raise ValueError(f"Zeile {index} von '{name}' darf nicht leer sein.")
|
raise ValueError(f"Zeile {index} von '{name}' darf nicht leer sein.")
|
||||||
@@ -49,7 +52,9 @@ def _validate_matrix(matrix: object, name: str) -> list[list[Number]]:
|
|||||||
return matrix
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
def matmul(matrix_a: list[list[Number]], matrix_b: list[list[Number]]) -> list[list[Number]]:
|
def matmul(
|
||||||
|
matrix_a: list[list[Number]], matrix_b: list[list[Number]]
|
||||||
|
) -> list[list[Number]]:
|
||||||
"""Multipliziert zwei Matrizen.
|
"""Multipliziert zwei Matrizen.
|
||||||
|
|
||||||
Die Anzahl der Spalten von ``matrix_a`` muss mit der Anzahl der Zeilen von
|
Die Anzahl der Spalten von ``matrix_a`` muss mit der Anzahl der Zeilen von
|
||||||
@@ -118,8 +123,7 @@ def transpose(matrix: list[list[Number]]) -> list[list[Number]]:
|
|||||||
return [[matrix[i][j] for i in range(rows)] for j in range(columns)]
|
return [[matrix[i][j] for i in range(rows)] for j in range(columns)]
|
||||||
|
|
||||||
|
|
||||||
def rotate(angle: float) -> list[list[float]]:
|
def rot_2d(angle: float) -> list[list[float]]:
|
||||||
"""Ergänzter Kommentar"""
|
|
||||||
"""Erstellt die Rotationsmatrix für einen Winkel.
|
"""Erstellt die Rotationsmatrix für einen Winkel.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -142,105 +146,54 @@ def rotate(angle: float) -> list[list[float]]:
|
|||||||
return [[cosine, -sine], [sine, cosine]]
|
return [[cosine, -sine], [sine, cosine]]
|
||||||
|
|
||||||
|
|
||||||
def _parse_number(token: str) -> float:
|
def rot_3d(angle: float, axis: str) -> list[list[float]]:
|
||||||
"""Wandelt einen eingegebenen Text in eine Zahl um.
|
"""Erstellt die 3D-Rotationsmatrix für einen Winkel um eine Achse.
|
||||||
|
|
||||||
|
Die Rotation erfolgt im Uhrzeigersinn (Rechtssystem) um die angegebene
|
||||||
|
Achse. Die zurückgegebene Matrix ist 3x3 groß und kann direkt auf einen
|
||||||
|
3D-Vektor angewendet werden.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
token (str): Einzelner Eingabewert.
|
angle (float): Drehwinkel im Bogenmaß.
|
||||||
|
axis (str): Rotationsachse, eine von ``"x"``, ``"y"`` oder ``"z"``.
|
||||||
|
Groß- und Kleinschreibung spielt keine Rolle.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: Zahlwert des Eingabetokens.
|
list[list[float]]: 3x3-Rotationsmatrix, die auf einen 3D-Vektor
|
||||||
|
angewendet werden kann.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: Wenn der Text keine gültige Zahl ist.
|
TypeError: Wenn ``angle`` keine Zahl oder ``axis`` kein String ist.
|
||||||
|
ValueError: Wenn ``axis`` keine der drei Hauptachsen ist.
|
||||||
"""
|
"""
|
||||||
try:
|
if isinstance(angle, bool) or not isinstance(angle, Number):
|
||||||
return float(token)
|
raise TypeError(f"'angle' muss eine Zahl sein, nicht {type(angle).__name__}.")
|
||||||
except ValueError as error:
|
|
||||||
raise ValueError(f"'{token}' ist keine gültige Zahl.") from error
|
|
||||||
|
|
||||||
|
if not isinstance(axis, str):
|
||||||
|
raise TypeError(f"'axis' muss ein String sein, nicht {type(axis).__name__}.")
|
||||||
|
|
||||||
def _read_matrix(name: str) -> list[list[float]]:
|
normalized_axis = axis.strip().lower()
|
||||||
"""Liest eine Matrix zeilenweise aus der Konsole ein.
|
|
||||||
|
|
||||||
Der Benutzer gibt zuerst die Anzahl der Zeilen an. Anschließend wird jede
|
if normalized_axis not in ("x", "y", "z"):
|
||||||
Zeile als Leerzeichen-getrennte Liste von Zahlen eingegeben. Bei ungültiger
|
raise ValueError(
|
||||||
Eingabe wird die jeweilige Eingabe erneut abgefragt.
|
f"'axis' muss eine der Achsen 'x', 'y' oder 'z' sein, nicht '{axis}'."
|
||||||
|
)
|
||||||
|
|
||||||
Args:
|
cosine = math.cos(angle)
|
||||||
name (str): Name der Matrix für die Ausgabe.
|
sine = math.sin(angle)
|
||||||
|
|
||||||
Returns:
|
if normalized_axis == "x":
|
||||||
list[list[float]]: Eingelesene Matrix.
|
return [[1.0, 0.0, 0.0], [0.0, cosine, -sine], [0.0, sine, cosine]]
|
||||||
"""
|
|
||||||
print(f"\nEingabe der Matrix {name}:")
|
|
||||||
|
|
||||||
while True:
|
if normalized_axis == "y":
|
||||||
raw = input("Anzahl der Zeilen: ").strip()
|
return [[cosine, 0.0, sine], [0.0, 1.0, 0.0], [-sine, 0.0, cosine]]
|
||||||
try:
|
|
||||||
rows = int(raw)
|
|
||||||
except ValueError:
|
|
||||||
print(f"Fehler: '{raw}' ist keine ganze Zahl. Bitte erneut eingeben.")
|
|
||||||
continue
|
|
||||||
if rows <= 0:
|
|
||||||
print("Fehler: Die Anzahl der Zeilen muss größer als 0 sein.")
|
|
||||||
continue
|
|
||||||
break
|
|
||||||
|
|
||||||
matrix: list[list[float]] = []
|
return [[cosine, -sine, 0.0], [sine, cosine, 0.0], [0.0, 0.0, 1.0]]
|
||||||
expected_columns: int | None = None
|
|
||||||
|
|
||||||
for index in range(rows):
|
def project_ortho(point: tuple[float, float, float], scale: float = 1) -> tuple[float, float] :
|
||||||
while True:
|
"""Ignoriert Z-Koordinate und skaliert mit scale multiplier"""
|
||||||
raw_row = input(f"Zeile {index} (Zahlen durch Leerzeichen getrennt): ").strip()
|
new_point : tuple[float, float] = (
|
||||||
tokens = raw_row.split()
|
point[0] * scale,
|
||||||
|
point[1] * scale
|
||||||
if not tokens:
|
)
|
||||||
print("Fehler: Die Zeile darf nicht leer sein. Bitte erneut eingeben.")
|
return new_point
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
row = [_parse_number(token) for token in tokens]
|
|
||||||
except ValueError as error:
|
|
||||||
print(f"Fehler: {error} Bitte erneut eingeben.")
|
|
||||||
continue
|
|
||||||
|
|
||||||
if expected_columns is None:
|
|
||||||
expected_columns = len(row)
|
|
||||||
elif len(row) != expected_columns:
|
|
||||||
print(
|
|
||||||
f"Fehler: Die Zeile hat {len(row)} Spalten, "
|
|
||||||
f"erwartet werden {expected_columns}. Bitte erneut eingeben."
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
|
|
||||||
matrix.append(row)
|
|
||||||
break
|
|
||||||
|
|
||||||
return matrix
|
|
||||||
|
|
||||||
|
|
||||||
def _print_matrix(matrix: list[list[Number]]) -> None:
|
|
||||||
"""Gibt eine Matrix formatiert auf der Konsole aus.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
matrix (list[list[Number]]): Auszugebende Matrix.
|
|
||||||
"""
|
|
||||||
for row in matrix:
|
|
||||||
print(" [" + ", ".join(str(value) for value in row) + "]")
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
|
||||||
"""Startet das Programm und liest zwei Matrizen zur Multiplikation ein.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
int: Exit-Code des Programms (0 bei Erfolg, 1 bei Fehler).
|
|
||||||
"""
|
|
||||||
#print(rotate(45))
|
|
||||||
print(tabulate(rotate(1.0)))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(main())
|
|
||||||
Whitespace-only changes.
@@ -0,0 +1,26 @@
|
|||||||
|
from matrixmania.compute import project_ortho
|
||||||
|
|
||||||
|
def test_project_ortho_no_scale() -> None:
|
||||||
|
"""Prüft die Funktion project_ortho, ob richtige Form zurückgegeben wird. Ohne scale Parameter"""
|
||||||
|
|
||||||
|
#Arrange: Es wird mit dem Tupel (1,2,3) geprüft, erwartet wird das Tupel (1,2)
|
||||||
|
|
||||||
|
test_tupel = (1,2,3)
|
||||||
|
expected_tupel = (1,2)
|
||||||
|
|
||||||
|
#Act und Assert: Funktion mit Parameter test_tuple wird mit expected_tupel verglichen
|
||||||
|
|
||||||
|
assert project_ortho(test_tupel) == expected_tupel
|
||||||
|
|
||||||
|
def test_project_ortho_scale() -> None:
|
||||||
|
"""Prüft die Funktion project_ortho, ob richtige Form zurückgegeben wird. Mit scale Parameter"""
|
||||||
|
|
||||||
|
# Arrange: Es wird mit dem Tupel (1,2,3) geprüft, der scale parameter wird auf 10 gesetzt. Erwartet wird das Tupel (10,20)
|
||||||
|
|
||||||
|
test_tupel = (1,2,3)
|
||||||
|
scale = 10
|
||||||
|
expected_tupel = (10,20)
|
||||||
|
|
||||||
|
# Act und Assert: Funktion mit Parameter test_tuple wird mit expected_tupel verglichen
|
||||||
|
|
||||||
|
assert project_ortho(test_tupel,scale) == expected_tupel
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
"""Tests für die Rotationsfunktionen."""
|
||||||
|
|
||||||
|
import math
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from matrixmania.compute import rot_2d, rot_3d
|
||||||
|
|
||||||
|
|
||||||
|
def _flatten(matrix: list[list[float]]) -> list[float]:
|
||||||
|
"""Flacht eine Matrix zu einer flachen Liste ab.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
matrix (list[list[float]]): Zu flachende Matrix.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list[float]: Alle Matrixelemente in Zeilen-Reihenfolge.
|
||||||
|
"""
|
||||||
|
return [value for row in matrix for value in row]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("angle", "expected"),
|
||||||
|
[
|
||||||
|
(0.0, [1.0, 0.0, 0.0, 1.0]),
|
||||||
|
(math.pi / 2, [0.0, -1.0, 1.0, 0.0]),
|
||||||
|
(math.pi, [-1.0, 0.0, 0.0, -1.0]),
|
||||||
|
(2 * math.pi, [1.0, 0.0, 0.0, 1.0]),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_rot_2d(angle: float, expected: list[float]) -> None:
|
||||||
|
"""Prüft die 2D-Rotationsmatrix für einen Winkel.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
angle (float): Drehwinkel im Bogenmaß.
|
||||||
|
expected (list[float]): Erwartete Matrixwerte in Zeilen-Reihenfolge.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
AssertionError: Wenn die Rotationsmatrix nicht erwartet wird.
|
||||||
|
"""
|
||||||
|
# Arrange: Winkel und Erwartungswerte stammen aus der Parametrisierung.
|
||||||
|
|
||||||
|
# Act
|
||||||
|
result = _flatten(rot_2d(angle))
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert result == pytest.approx(expected)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("angle", "axis", "expected"),
|
||||||
|
[
|
||||||
|
(0.0, "x", [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]),
|
||||||
|
(0.0, "y", [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]),
|
||||||
|
(0.0, "z", [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]),
|
||||||
|
(math.pi / 2, "x", [1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0]),
|
||||||
|
(math.pi / 2, "y", [0.0, 0.0, 1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 0.0]),
|
||||||
|
(math.pi / 2, "z", [0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_rot_3d(angle: float, axis: str, expected: list[float]) -> None:
|
||||||
|
"""Prüft die 3D-Rotationsmatrix für einen Winkel und eine Achse.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
angle (float): Drehwinkel im Bogenmaß.
|
||||||
|
axis (str): Rotationsachse ("x", "y" oder "z").
|
||||||
|
expected (list[float]): Erwartete Matrixwerte in Zeilen-Reihenfolge.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
AssertionError: Wenn die Rotationsmatrix nicht erwartet wird.
|
||||||
|
"""
|
||||||
|
# Arrange: Winkel, Achse und Erwartungswerte stammen aus der Parametrisierung.
|
||||||
|
|
||||||
|
# Act
|
||||||
|
result = _flatten(rot_3d(angle, axis))
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert result == pytest.approx(expected)
|
||||||
Reference in new issue
Block a user