|
| 1 | +# Minimal geometry stubs for Sphinx documentation |
| 2 | + |
| 3 | +class Rotation3d: |
| 4 | + def __init__(self, roll=0.0, pitch=0.0, yaw=0.0): |
| 5 | + # store yaw as the primary rotation for simple stubs |
| 6 | + self.roll = roll |
| 7 | + self.pitch = pitch |
| 8 | + self.yaw = yaw |
| 9 | + |
| 10 | + def toRotation2d(self): |
| 11 | + # convert yaw to a Rotation2d for simple compatibility in docs build |
| 12 | + return Rotation2d(self.yaw) |
| 13 | + |
| 14 | +class Translation3d: |
| 15 | + def __init__(self, x=0.0, y=0.0, z=0.0): |
| 16 | + # Support both (x, y, z) and (distance, Rotation3d) forms used by the real wpimath |
| 17 | + # If y is a Rotation3d, compute a point at 'distance' along its yaw/pitch |
| 18 | + try: |
| 19 | + from math import cos, sin |
| 20 | + except Exception: |
| 21 | + def cos(x): |
| 22 | + return x |
| 23 | + def sin(x): |
| 24 | + return x |
| 25 | + |
| 26 | + if hasattr(y, "yaw") and hasattr(y, "pitch"): |
| 27 | + # interpret constructor as Translation3d(distance, Rotation3d) |
| 28 | + distance = float(x) |
| 29 | + pitch = float(getattr(y, "pitch", 0.0)) |
| 30 | + yaw = float(getattr(y, "yaw", 0.0)) |
| 31 | + # approximate spherical -> cartesian |
| 32 | + self._x = distance * cos(pitch) * cos(yaw) |
| 33 | + self._y = distance * cos(pitch) * sin(yaw) |
| 34 | + self._z = distance * sin(pitch) |
| 35 | + else: |
| 36 | + self._x = float(x) |
| 37 | + self._y = float(y) |
| 38 | + self._z = float(z) |
| 39 | + |
| 40 | + def X(self): |
| 41 | + return self._x |
| 42 | + |
| 43 | + def Y(self): |
| 44 | + return self._y |
| 45 | + |
| 46 | + def Z(self): |
| 47 | + return self._z |
| 48 | + |
| 49 | +class Pose3d: |
| 50 | + def __init__(self, *args, **kwargs): |
| 51 | + pass |
| 52 | + |
| 53 | +class Rotation2d: |
| 54 | + def __init__(self, *args): |
| 55 | + # Accept several initialization forms used in the real wpimath Rotation2d |
| 56 | + # - Rotation2d(angle) |
| 57 | + # - Rotation2d(fx, xOffset) used by SimCameraProperties.getPixelYaw |
| 58 | + if len(args) == 0: |
| 59 | + self._angle = 0.0 |
| 60 | + elif len(args) == 1: |
| 61 | + self._angle = float(args[0]) |
| 62 | + else: |
| 63 | + # fallback: when called with fx, xOffset, approximate angle as 0.0 |
| 64 | + self._angle = 0.0 |
| 65 | + |
| 66 | + def degrees(self): |
| 67 | + from math import degrees |
| 68 | + |
| 69 | + return degrees(self._angle) |
| 70 | + |
| 71 | + def radians(self): |
| 72 | + return float(self._angle) |
| 73 | + |
| 74 | + def __add__(self, other): |
| 75 | + # allow Rotation2d + Rotation2d or Rotation2d + numeric |
| 76 | + if hasattr(other, "_angle"): |
| 77 | + return Rotation2d(self._angle + float(other._angle)) |
| 78 | + try: |
| 79 | + return Rotation2d(self._angle + float(other)) |
| 80 | + except Exception: |
| 81 | + return NotImplemented |
| 82 | + |
| 83 | + def __radd__(self, other): |
| 84 | + # numeric + Rotation2d |
| 85 | + return self.__add__(other) |
| 86 | + |
| 87 | + def __sub__(self, other): |
| 88 | + if hasattr(other, "_angle"): |
| 89 | + return Rotation2d(self._angle - float(other._angle)) |
| 90 | + try: |
| 91 | + return Rotation2d(self._angle - float(other)) |
| 92 | + except Exception: |
| 93 | + return NotImplemented |
| 94 | + |
| 95 | + def __neg__(self): |
| 96 | + return Rotation2d(-self._angle) |
| 97 | + |
| 98 | + def __repr__(self): |
| 99 | + return f"Rotation2d({self._angle})" |
| 100 | + |
| 101 | +class Translation2d: |
| 102 | + def __init__(self, x=0.0, y=0.0): |
| 103 | + self._x = float(x) |
| 104 | + self._y = float(y) |
| 105 | + |
| 106 | + def X(self): |
| 107 | + return self._x |
| 108 | + |
| 109 | + def Y(self): |
| 110 | + return self._y |
| 111 | + |
| 112 | +class Pose2d: |
| 113 | + def __init__(self, *args, **kwargs): |
| 114 | + pass |
| 115 | + |
| 116 | + def __repr__(self) -> str: |
| 117 | + return "Pose2d()" |
| 118 | + |
| 119 | + |
| 120 | +class Transform3d: |
| 121 | + def __init__(self, *args, **kwargs): |
| 122 | + pass |
| 123 | + |
| 124 | + |
| 125 | +class Quaternion: |
| 126 | + def __init__(self, *args, **kwargs): |
| 127 | + pass |
| 128 | + |
| 129 | +# Expose names commonly used by photonlibpy |
| 130 | +__all__ = ["Rotation3d", "Translation3d", "Pose3d", "Rotation2d", "Translation2d", "Pose2d"] |
0 commit comments