Compare commits

...
7 Commits
Author SHA1 Message Date
Tonii2206 71c9eb485b jetzt funktionierts 2026-10-27 09:56:49 +01:00
Tonii2206 bb785bb25c jetzt funktionierts 2026-10-27 09:44:03 +01:00
Tonii2206 bf436441ce Hausaufgabe tests hinzufügen und §D funktion in commit 2026-10-27 09:41:01 +01:00
Tonii2206 153b0ac6b4 praktikum stand 2026-10-20 17:09:22 +02:00
Tonii2206 875f2bcded pyprojekt.toml unbennannt 2026-10-20 17:09:00 +02:00
Tonii2206 f7282cf4db pyprojekt.toml unbennannt 2026-10-20 16:55:20 +02:00
Tonii2206 1d1671ef3a pyprojekt.toml unbennannt 2026-10-20 16:04:05 +02:00
22 changed files with 368 additions and 7 deletions

No files matched your search

View File
File renamed without changes.
+5
View File
@@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.13 (MatrixMania)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+16
View File
@@ -0,0 +1,16 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyCompatibilityInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ourVersions">
<value>
<list size="3">
<item index="0" class="java.lang.String" itemvalue="2.7" />
<item index="1" class="java.lang.String" itemvalue="3.14" />
<item index="2" class="java.lang.String" itemvalue="3.13" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>
+6
View File
@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.13 (MatrixMania)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (MatrixMania)" project-jdk-type="Python SDK" />
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/MatrixMania.iml" filepath="$PROJECT_DIR$/.idea/MatrixMania.iml" />
</modules>
</component>
</project>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
+5 -1
View File
@@ -1,4 +1,8 @@
# Regeln für dieses Projekt # Regeln für dieses Projekt
- 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_"
+146
View File
@@ -0,0 +1,146 @@
#!/usr/bin/env python3
"""Installiert die Abhängigkeiten aus pyproject.toml in die aktuelle Python-Umgebung.
Ersatz für "Install requirements" aus PyCharm, wenn das Projekt eine pyproject.toml
statt einer requirements.txt hat. Kein Build, keine besondere Projektstruktur nötig,
nur Standardbibliothek (Python >= 3.11).
Benutzung:
In PyCharm: Rechtsklick auf diese Datei -> Run 'install_dependencies'
Im Terminal (venv aktiv): python install_dependencies.py
Ohne Parameter wird ALLES installiert:
[project].dependencies + alle [project.optional-dependencies] + alle [dependency-groups]
Abweichendes Verhalten:
python install_dependencies.py --extra dev nur Basis + Extra "dev"
python install_dependencies.py --group test nur Basis + Gruppe "test"
python install_dependencies.py --no-main --group dev
python install_dependencies.py --list nur anzeigen, nichts installieren
python install_dependencies.py --write requirements.txt schreiben statt installieren
python install_dependencies.py --write -o reqs.txt
"""
from __future__ import annotations
import sys
if sys.version_info < (3, 11):
sys.exit("Dieses Skript braucht Python 3.11 oder neuer (tomllib). "
f"Aktuell: {sys.version.split()[0]}")
import argparse
import subprocess
import tempfile
import tomllib
from pathlib import Path
PROJECT_DIR = Path(__file__).resolve().parent
def resolve_group(groups: dict, name: str, seen: set[str] | None = None) -> list[str]:
"""Löst eine Dependency-Group inkl. {include-group = "..."} rekursiv auf."""
seen = set() if seen is None else seen
if name in seen:
raise ValueError(f"Zyklische include-group: {name}")
if name not in groups:
raise KeyError(f"Dependency-Group '{name}' nicht gefunden")
seen.add(name)
result: list[str] = []
for entry in groups[name]:
if isinstance(entry, str):
result.append(entry)
elif isinstance(entry, dict) and "include-group" in entry:
result.extend(resolve_group(groups, entry["include-group"], seen))
return result
def collect(data: dict, extras: list[str], groups: list[str], no_main: bool) -> list[str]:
project = data.get("project", {})
optional = project.get("optional-dependencies", {})
dep_groups = data.get("dependency-groups", {})
deps: list[str] = []
if not no_main:
deps.extend(project.get("dependencies", []))
for extra in extras:
if extra not in optional:
raise KeyError(f"Optional-Dependency '{extra}' nicht gefunden")
deps.extend(optional[extra])
for group in groups:
deps.extend(resolve_group(dep_groups, group))
# Duplikate entfernen, Reihenfolge behalten
return list(dict.fromkeys(d.strip() for d in deps if d.strip()))
def main() -> int:
p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
p.add_argument("-p", "--pyproject", type=Path, default=PROJECT_DIR / "pyproject.toml",
help="Pfad zur pyproject.toml (Standard: neben diesem Skript)")
p.add_argument("--extra", action="append", default=None,
help="nur diese optional-dependencies (mehrfach möglich)")
p.add_argument("--group", action="append", default=None,
help="nur diese dependency-groups (mehrfach möglich)")
p.add_argument("--no-main", action="store_true", help="[project].dependencies weglassen")
p.add_argument("--list", action="store_true", help="Abhängigkeiten nur anzeigen")
p.add_argument("--write", action="store_true", help="requirements-Datei schreiben statt installieren")
p.add_argument("-o", "--output", type=Path, default=PROJECT_DIR / "requirements.txt",
help="Zieldatei für --write")
args = p.parse_args()
if not args.pyproject.exists():
print(f"{args.pyproject} nicht gefunden", file=sys.stderr)
return 1
data = tomllib.loads(args.pyproject.read_text(encoding="utf-8"))
all_extras = list(data.get("project", {}).get("optional-dependencies", {}))
all_groups = list(data.get("dependency-groups", {}))
# Ohne --extra/--group: alles. Mit einem davon: nur das Gewählte.
selective = args.extra is not None or args.group is not None
extras = (args.extra or []) if selective else all_extras
groups = (args.group or []) if selective else all_groups
try:
deps = collect(data, extras, groups, args.no_main)
except (KeyError, ValueError) as e:
print(f"Fehler: {e.args[0]}", file=sys.stderr)
print(f" Vorhandene --extra: {', '.join(all_extras) or '(keine)'}", file=sys.stderr)
print(f" Vorhandene --group: {', '.join(all_groups) or '(keine)'}", file=sys.stderr)
return 1
parts = ([] if args.no_main else ["Basis"]) + [f"extra:{e}" for e in extras] + [f"group:{g}" for g in groups]
print(f"Auswahl: {', '.join(parts) or '(nichts)'}")
if args.list:
print("\n".join(deps) or "(keine Abhängigkeiten)")
return 0
content = f"# Automatisch erzeugt aus {args.pyproject.name} – nicht von Hand bearbeiten\n" + "\n".join(deps) + "\n"
if args.write:
args.output.write_text(content, encoding="utf-8")
print(f"{len(deps)} Abhängigkeiten -> {args.output}")
return 0
if not deps:
print("Keine Abhängigkeiten gefunden – nichts zu tun.")
return 0
if sys.prefix == sys.base_prefix:
print("WARNUNG: Es ist kein virtuelles Environment aktiv – es wird in die globale "
f"Python-Installation installiert:\n {sys.prefix}", file=sys.stderr)
if sys.stdin.isatty() and input("Trotzdem fortfahren? [j/N] ").strip().lower() not in ("j", "ja", "y", "yes"):
return 1
with tempfile.NamedTemporaryFile("w", suffix=".txt", delete=False, encoding="utf-8") as tmp:
tmp.write(content)
tmp_path = Path(tmp.name)
try:
print(f"Installiere {len(deps)} Abhängigkeiten in {sys.prefix}\n")
return subprocess.call([sys.executable, "-m", "pip", "install", "-r", str(tmp_path)])
finally:
tmp_path.unlink(missing_ok=True)
if __name__ == "__main__":
raise SystemExit(main())
+10
View File
@@ -0,0 +1,10 @@
[project]
name = "matrixmania"
version = "0.1.0"
dependencies = ["tabulate", "ruff"]
[project.optional-dependencies]
dev = ["pytest", "ruff", "pytest-cov"]
[tool.pytest.ini_options]
pythonpath = "src"
-4
View File
@@ -1,4 +0,0 @@
[project]
name = "matrixmania"
version = "0.1.0"
dependencies = ["tabulate", "ruff"]
+9
View File
@@ -0,0 +1,9 @@
Metadata-Version: 2.4
Name: matrixmania
Version: 0.1.0
Requires-Dist: tabulate
Requires-Dist: ruff
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
+8
View File
@@ -0,0 +1,8 @@
pyproject.toml
src/matrixmania/__init__.py
src/matrixmania/compute.py
src/matrixmania.egg-info/PKG-INFO
src/matrixmania.egg-info/SOURCES.txt
src/matrixmania.egg-info/dependency_links.txt
src/matrixmania.egg-info/requires.txt
src/matrixmania.egg-info/top_level.txt
@@ -0,0 +1 @@
+7
View File
@@ -0,0 +1,7 @@
tabulate
ruff
[dev]
pytest
ruff
pytest-cov
+1
View File
@@ -0,0 +1 @@
matrixmania
+1
View File
@@ -0,0 +1 @@
from matrixmania.compute import matmul, transpose, rot_2D, rot_3D
+68 -2
View File
@@ -23,8 +23,6 @@ __all__ = ["matmul", "transpose"]
def matmul(a: list[list[float]] , b:list[list[float]]) -> list[list[float]]: def matmul(a: list[list[float]] , b:list[list[float]]) -> list[list[float]]:
"""Return the product of two matrices ``a`` and ``b``. """Return the product of two matrices ``a`` and ``b``.
Returns Returns
------- -------
List[List[float]] List[List[float]]
@@ -102,12 +100,80 @@ def rot_2D(winkel):
[math.cos(winkel), -math.sin(winkel)], [math.cos(winkel), -math.sin(winkel)],
[math.sin(winkel), math.cos(winkel)] [math.sin(winkel), math.cos(winkel)]
] ]
def rot_3D(angle: float, axis: str) -> list[list[float]]:
"""Gibt die Rotationsmatrix für einen Winkel in Radiant um die x-, y- oder z-Achse zurück.
Parameters
----------
angle : float
Rotationswinkel in Radiant.
axis : str
Rotationsachse: ``"x"``, ``"y"`` oder ``"z"``.
Returns
-------
list[list[float]]
Die entsprechende 3x3-Rotationsmatrix.
Raises
------
ValueError
Wenn ``axis`` nicht ``"x"``, ``"y"`` oder ``"z"`` ist.
Formeln
-------
Rx(theta) =
[[1, 0, 0],
[0, cos(theta), -sin(theta)],
[0, sin(theta), cos(theta)]]
Ry(theta) =
[[cos(theta), 0, sin(theta)],
[0, 1, 0],
[-sin(theta), 0, cos(theta)]]
Rz(theta) =
[[cos(theta), -sin(theta), 0],
[sin(theta), cos(theta), 0],
[0, 0, 1]]
"""
if axis == "x":
return [
[1.0, 0.0, 0.0],
[0.0, math.cos(angle), -math.sin(angle)],
[0.0, math.sin(angle), math.cos(angle)],
]
if axis == "y":
return [
[math.cos(angle), 0.0, math.sin(angle)],
[0.0, 1.0, 0.0],
[-math.sin(angle), 0.0, math.cos(angle)],
]
if axis == "z":
return [
[math.cos(angle), -math.sin(angle), 0.0],
[math.sin(angle), math.cos(angle), 0.0],
[0.0, 0.0, 1.0],
]
raise ValueError("axis must be 'x', 'y' or 'z'")
def transpose(a: list[list[float]]) -> list[list[float]]: def transpose(a: list[list[float]]) -> list[list[float]]:
"""Gibt die transponierte Matrix a zurück.""" """Gibt die transponierte Matrix a zurück."""
return [ return [
[row[i] for row in a] [row[i] for row in a]
for i in range(len(a[0])) for i in range(len(a[0]))
] ]
def project_ortho(point: tuple[float, float], scale: float= 1) -> tuple[float, float]:
#das dreidimensionale wird zweidimensional gezeichnet z muss hinten immer weg
x, y, z = point
return (x * scale, y * scale)
def main() -> None: def main() -> None:
"""Demonstrate :func:`matmul` with a simple example. """Demonstrate :func:`matmul` with a simple example.
This function is only executed when the module is run as a script. This function is only executed when the module is run as a script.
View File
Whitespace-only changes.
+23
View File
@@ -0,0 +1,23 @@
from matrixmania.compute import project_ortho
def test_project_ortho_ohneSkalierung():
# Arrange
point =(1, 2, 3)
expected = (1, 2)
#Act
result = project_ortho(point)
#Assert
assert result == expected
def test_project_ortho_mitskalierung():
#Arrange
point = (1, 2, 3)
scale = 100
expected =(100, 200)
#Act
result = project_ortho(point, scale)
#Assert
assert result == expected
+30
View File
@@ -0,0 +1,30 @@
import math
import pytest
from matrixmania.compute import rot_2D, rot_3D
def test_rot2D_90_grad(): # dreht es sich wirklich um 90 grad?
#Arrange
angle = math.pi/2
expected = [
[math.cos(angle), -math.sin(angle)],
[math.sin(angle), math.cos(angle)]
]
#Act
result = rot_2D(angle)
#Assert
assert result == expected
def test_rot3D_drehen(): #dreht sich um 90 grad?
#Arrange
angle = math.pi/2
achse = "z"
expected = [
[math.cos(angle), -math.sin(angle), 0.0],
[math.sin(angle), math.cos(angle), 0.0],
[0.0, 0.0, 1.0],
]
result = rot_3D(angle, achse)
assert result == expected