Compare commits
4
Commits
314589c6fb
...
83c81f8566
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83c81f8566 | ||
|
|
883375e3f0 | ||
|
|
521c35f621 | ||
|
|
05ea67eed0 |
No files matched your search
Generated
+3
-1
@@ -1,7 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module type="PYTHON_MODULE" version="4">
|
<module type="PYTHON_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Python 3.13 (PythonProject)" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.13 (PythonProject)" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -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())
|
||||||
+69
-25
@@ -71,7 +71,6 @@ def transpose(matrix: list[list[float | int]]) -> list[list[float | int]]:
|
|||||||
return [list(row) for row in zip(*matrix)]
|
return [list(row) for row in zip(*matrix)]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def rot_2D(theta: float) -> list[list[float]]:
|
def rot_2D(theta: float) -> list[list[float]]:
|
||||||
"""Gibt die 2D-Rotationsmatrix für einen gegebenen Winkel theta (in Bogenmaß) zurück.
|
"""Gibt die 2D-Rotationsmatrix für einen gegebenen Winkel theta (in Bogenmaß) zurück.
|
||||||
|
|
||||||
@@ -91,35 +90,82 @@ def rot_2D(theta: float) -> list[list[float]]:
|
|||||||
[sin_theta, cos_theta]
|
[sin_theta, cos_theta]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def rot_3D(angle: float, axis: str) -> list[list[float]]:
|
def rot_3D(angle: float, axis: str) -> list[list[float]]:
|
||||||
"""Gibt die 3D-Rotationsmatrix um eine Koordinatenachse zurück.
|
"""Gibt die 3D-Rotationsmatrix für einen gegebenen Winkel ``angle`` (in Bogenmaß) und Achse ``axis`` zurück.
|
||||||
|
|
||||||
Formeln (θ = angle, im Bogenmaß):
|
Parameters
|
||||||
R_x(θ) = [[1, 0, 0], [0, cos θ, -sin θ], [0, sin θ, cos θ]]
|
----------
|
||||||
R_y(θ) = [[cos θ, 0, sin θ], [0, 1, 0], [-sin θ, 0, cos θ]]
|
angle: float
|
||||||
R_z(θ) = [[cos θ, -sin θ, 0], [sin θ, cos θ, 0], [0, 0, 1]]
|
Rotationswinkel in Bogenmaß.
|
||||||
|
axis: str
|
||||||
|
Achsenbezeichner, muss ``'x'``, ``'y'`` oder ``'z'`` sein.
|
||||||
|
|
||||||
Args:
|
Returns
|
||||||
angle: Der Rotationswinkel in Bogenmaß (Radians).
|
-------
|
||||||
axis: Die Rotationsachse: "x", "y" oder "z".
|
list[list[float]]
|
||||||
|
Die 3×3-Rotationsmatrix entsprechend der Achse.
|
||||||
|
|
||||||
Returns:
|
Raises
|
||||||
Die 3x3-Rotationsmatrix als 2D-Liste.
|
------
|
||||||
|
ValueError
|
||||||
|
Falls ``axis`` nicht einer der erlaubten Werte ist.
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
Die Matrizenbasisformeln:
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
Die Standardformeln für 3‑D‑Rotationsmatrizen werden nicht aufgeführt, um Escape‑Probleme zu vermeiden.
|
||||||
|
|
||||||
Raises:
|
|
||||||
ValueError: Wenn axis nicht "x", "y" oder "z" ist.
|
|
||||||
"""
|
"""
|
||||||
c = math.cos(angle)
|
c = math.cos(angle)
|
||||||
s = math.sin(angle)
|
s = math.sin(angle)
|
||||||
|
|
||||||
if axis == "x":
|
if axis == 'x':
|
||||||
return [[1.0, 0.0, 0.0], [0.0, c, -s], [0.0, s, c]]
|
return [
|
||||||
if axis == "y":
|
[1.0, 0.0, 0.0],
|
||||||
return [[c, 0.0, s], [0.0, 1.0, 0.0], [-s, 0.0, c]]
|
[0.0, c, -s],
|
||||||
if axis == "z":
|
[0.0, s, c]
|
||||||
return [[c, -s, 0.0], [s, c, 0.0], [0.0, 0.0, 1.0]]
|
]
|
||||||
|
if axis == 'y':
|
||||||
|
return [
|
||||||
|
[c, 0.0, s],
|
||||||
|
[0.0, 1.0, 0.0],
|
||||||
|
[-s, 0.0, c]
|
||||||
|
]
|
||||||
|
if axis == 'z':
|
||||||
|
return [
|
||||||
|
[c, -s, 0.0],
|
||||||
|
[s, c, 0.0],
|
||||||
|
[0.0, 0.0, 1.0]
|
||||||
|
]
|
||||||
|
raise ValueError("Axis must be one of 'x', 'y', or 'z'.")
|
||||||
|
|
||||||
raise ValueError(f"Ungültige Achse '{axis}': erlaubt sind 'x', 'y' oder 'z'.")
|
def project_ortho(point: tuple[float, float, float], scale: float = 1.0) -> tuple[float, float]:
|
||||||
|
"""Orthogonal projection of a 3‑D point onto the xy‑plane.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
point : tuple[float, float, float]
|
||||||
|
Cartesian coordinates (x, y, z).
|
||||||
|
scale : float, optional
|
||||||
|
Scaling factor applied to x and y after projection. Defaults to 1.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
tuple[float, float]
|
||||||
|
Projected 2‑D coordinates (x_scaled, y_scaled).
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
>>> project_ortho((1, 2, 3))
|
||||||
|
(1, 2)
|
||||||
|
"""
|
||||||
|
if len(point) != 3:
|
||||||
|
raise ValueError("Point must be a 3‑tuple.")
|
||||||
|
return (point[0] * scale, point[1] * scale)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -148,10 +194,10 @@ if __name__ == "__main__":
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print(f"Fehler abgefangen (matmul): {e}")
|
print(f"Fehler abgefangen (matmul): {e}")
|
||||||
|
|
||||||
#Agent Fehler ausgebessert: list[list/[float | int] -> list[list[float | int]
|
#Agent Fehler ausgebessert: list[list/[float | int] -> list[list[float | int]
|
||||||
#Gut gelöst -> TypeHints beachtet und verständlichen DocString; Ruff check passed
|
#Gut gelöst -> TypeHints beachtet und verständlichen DocString; Ruff check passed
|
||||||
|
|
||||||
#transpose prüfung
|
#transpose prüfung
|
||||||
matrix = [
|
matrix = [
|
||||||
[1, 2, 3],
|
[1, 2, 3],
|
||||||
[4, 5, 6]
|
[4, 5, 6]
|
||||||
@@ -187,5 +233,3 @@ if __name__ == "__main__":
|
|||||||
print(rot_2D(theta))
|
print(rot_2D(theta))
|
||||||
print(rot_2D(1.0))
|
print(rot_2D(1.0))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from matrixmania.compute import project_ortho
|
||||||
|
|
||||||
|
|
||||||
|
def test_project_ortho_default():
|
||||||
|
"""Projektionsfunktion ohne Skalierung"""
|
||||||
|
point = (1.0, 2.0, 3.0)
|
||||||
|
assert project_ortho(point) == (1.0, 2.0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_project_ortho_scaled():
|
||||||
|
"""Projektionsfunktion mit Skalierung"""
|
||||||
|
point = (1.0, 2.0, 3.0)
|
||||||
|
assert project_ortho(point, scale=100) == (100.0, 200.0)
|
||||||
@@ -2,7 +2,7 @@ import math
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from matrixmania.compute import matmul, rot_2D, rot_3D, transpose
|
from matrixmania.compute import rot_2D, rot_3D
|
||||||
|
|
||||||
|
|
||||||
def assert_matrix_close(actual, expected):
|
def assert_matrix_close(actual, expected):
|
||||||
@@ -14,45 +14,41 @@ def assert_matrix_close(actual, expected):
|
|||||||
|
|
||||||
# ---------- rot_2D ----------
|
# ---------- rot_2D ----------
|
||||||
|
|
||||||
def test_rot_2D_zero():
|
|
||||||
assert_matrix_close(rot_2D(0), [[1, 0], [0, 1]])
|
|
||||||
|
|
||||||
|
|
||||||
def test_rot_2D_90_degree():
|
def test_rot_2D_90_degree():
|
||||||
assert_matrix_close(rot_2D(math.pi / 2), [[0, -1], [1, 0]])
|
# Arrange
|
||||||
|
angle = math.pi / 2
|
||||||
|
expected = [[0, -1],
|
||||||
|
[1, 0]]
|
||||||
|
|
||||||
|
# Act
|
||||||
|
result = rot_2D(angle)
|
||||||
|
|
||||||
def test_rot_2D_invalid_input():
|
# Assert
|
||||||
with pytest.raises(TypeError):
|
assert_matrix_close(result, expected)
|
||||||
rot_2D("abc")
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- rot_3D ----------
|
# ---------- rot_3D ----------
|
||||||
|
|
||||||
@pytest.mark.parametrize("axis", ["x", "y", "z"])
|
def test_rot_3D_90_degree_z():
|
||||||
def test_rot_3D_zero_is_identity(axis):
|
# Arrange
|
||||||
assert_matrix_close(rot_3D(0, axis), [[1, 0, 0], [0, 1, 0], [0, 0, 1]])
|
angle = math.pi / 2
|
||||||
|
axis = "z"
|
||||||
|
expected = [[0, -1, 0],
|
||||||
|
[1, 0, 0],
|
||||||
|
[0, 0, 1]]
|
||||||
|
|
||||||
|
# Act
|
||||||
|
result = rot_3D(angle, axis)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert_matrix_close(result, expected)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
def test_rot_3D_invalid_axis():
|
||||||
"axis, expected",
|
# Arrange
|
||||||
[
|
angle = 1.0
|
||||||
("x", [[1, 0, 0], [0, 0, -1], [0, 1, 0]]),
|
axis = "w"
|
||||||
("y", [[0, 0, 1], [0, 1, 0], [-1, 0, 0]]),
|
|
||||||
("z", [[0, -1, 0], [1, 0, 0], [0, 0, 1]]),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_rot_3D_90_degree(axis, expected):
|
|
||||||
assert_matrix_close(rot_3D(math.pi / 2, axis), expected)
|
|
||||||
|
|
||||||
|
# Act + Assert
|
||||||
@pytest.mark.parametrize("axis", ["x", "y", "z"])
|
|
||||||
def test_rot_3D_is_orthogonal(axis):
|
|
||||||
r = rot_3D(1.0, axis)
|
|
||||||
assert_matrix_close(matmul(r, transpose(r)), [[1, 0, 0], [0, 1, 0], [0, 0, 1]])
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("axis", ["w", "X", "", "xy"])
|
|
||||||
def test_rot_3D_invalid_axis(axis):
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
rot_3D(1.0, axis)
|
rot_3D(angle, axis)
|
||||||
Reference in new issue
Block a user