Skip to content

Commit 1d6c7ee

Browse files
authored
Merge pull request #120 from robotpy/geom-from-matrix
Rename geometry from matrix constructor overloads
2 parents 767ecf8 + 0dd99d2 commit 1d6c7ee

File tree

21 files changed

+128
-15
lines changed

21 files changed

+128
-15
lines changed

rdev.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exclude_artifacts = [
1313
"opencv-cpp"
1414
]
1515

16-
robotpy_build_req = "<2025.0.0b1,~=2025.0.0a6"
16+
robotpy_build_req = "<2025.0.0b1,~=2025.0.0a8"
1717

1818
#
1919
# Subproject configuration

subprojects/pyntcore/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ install_requires = [
1212

1313
[build-system]
1414
requires = [
15-
"robotpy-build<2025.0.0b1,~=2025.0.0a6",
15+
"robotpy-build<2025.0.0b1,~=2025.0.0a8",
1616
"robotpy-wpiutil~=2025.0.0b3",
1717
"robotpy-wpinet~=2025.0.0b3",
1818
]

subprojects/robotpy-apriltag/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ install_requires = [
1212

1313
[build-system]
1414
requires = [
15-
"robotpy-build<2025.0.0b1,~=2025.0.0a6",
15+
"robotpy-build<2025.0.0b1,~=2025.0.0a8",
1616
"robotpy-wpiutil~=2025.0.0b3",
1717
"robotpy-wpimath~=2025.0.0b3",
1818
]

subprojects/robotpy-cscore/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ install_requires = [
1313

1414
[build-system]
1515
requires = [
16-
"robotpy-build<2025.0.0b1,~=2025.0.0a6",
16+
"robotpy-build<2025.0.0b1,~=2025.0.0a8",
1717
"robotpy-wpiutil~=2025.0.0b3",
1818
"robotpy-wpinet~=2025.0.0b3",
1919
"pyntcore~=2025.0.0b3",

subprojects/robotpy-hal/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ install_requires = [
1111

1212
[build-system]
1313
requires = [
14-
"robotpy-build<2025.0.0b1,~=2025.0.0a6",
14+
"robotpy-build<2025.0.0b1,~=2025.0.0a8",
1515
"robotpy-wpiutil~=2025.0.0b3",
1616
]
1717

subprojects/robotpy-halsim-ds-socket/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ robotpysimext = ["ds-socket = halsim_ds_socket"]
1515

1616
[build-system]
1717
requires = [
18-
"robotpy-build<2025.0.0b1,~=2025.0.0a6",
18+
"robotpy-build<2025.0.0b1,~=2025.0.0a8",
1919
"robotpy-hal~=2025.0.0b3",
2020
"robotpy-wpinet~=2025.0.0b3",
2121
]

subprojects/robotpy-halsim-gui/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ install_requires = [
1414

1515
[build-system]
1616
requires = [
17-
"robotpy-build<2025.0.0b1,~=2025.0.0a6",
17+
"robotpy-build<2025.0.0b1,~=2025.0.0a8",
1818
"robotpy-wpiutil~=2025.0.0b3",
1919
"robotpy-wpimath~=2025.0.0b3",
2020
"robotpy-hal~=2025.0.0b3",

subprojects/robotpy-halsim-ws/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ robotpysimext = [
1919

2020
[build-system]
2121
requires = [
22-
"robotpy-build<2025.0.0b1,~=2025.0.0a6",
22+
"robotpy-build<2025.0.0b1,~=2025.0.0a8",
2323
"robotpy-hal~=2025.0.0b3",
2424
"robotpy-wpinet~=2025.0.0b3",
2525
]

subprojects/robotpy-romi/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ install_requires = [
1111

1212
[build-system]
1313
requires = [
14-
"robotpy-build<2025.0.0b1,~=2025.0.0a6",
14+
"robotpy-build<2025.0.0b1,~=2025.0.0a8",
1515
"wpilib~=2025.0.0b3"
1616
]
1717

subprojects/robotpy-wpilib/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ robotpy = ["run = wpilib._impl.start:Main"]
1818

1919
[build-system]
2020
requires = [
21-
"robotpy-build<2025.0.0b1,~=2025.0.0a6",
21+
"robotpy-build<2025.0.0b1,~=2025.0.0a8",
2222
"robotpy-wpiutil~=2025.0.0b3",
2323
"robotpy-wpimath~=2025.0.0b3",
2424
"robotpy-hal~=2025.0.0b3",

subprojects/robotpy-wpimath/gen/geometry/Pose2d.yml

+4
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ classes:
2121
'':
2222
Translation2d, Rotation2d:
2323
units::meter_t, units::meter_t, Rotation2d:
24+
const Eigen::Matrix3d&:
25+
rename: fromMatrix
26+
keepalive: []
2427
Translation:
2528
Rotation:
2629
RotateBy:
2730
TransformBy:
2831
RelativeTo:
2932
Exp:
3033
Log:
34+
ToMatrix:
3135
Nearest:
3236
overloads:
3337
std::span<const Pose2d> [const]:

subprojects/robotpy-wpimath/gen/geometry/Pose3d.yml

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ classes:
2323
Translation3d, Rotation3d:
2424
units::meter_t, units::meter_t, units::meter_t, Rotation3d:
2525
const Pose2d&:
26+
keepalive: []
27+
const Eigen::Matrix4d&:
28+
rename: fromMatrix
29+
keepalive: []
2630
operator+:
2731
operator-:
2832
operator==:
@@ -39,6 +43,7 @@ classes:
3943
RelativeTo:
4044
Exp:
4145
Log:
46+
ToMatrix:
4247
ToPose2d:
4348

4449
inline_code: |

subprojects/robotpy-wpimath/gen/geometry/Rotation2d.yml

+4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ classes:
2525
template_impls:
2626
- ['units::radian_t']
2727
double, double:
28+
const Eigen::Matrix2d&:
29+
rename: fromMatrix
30+
keepalive: []
2831
RotateBy:
32+
ToMatrix:
2933
Radians:
3034
Degrees:
3135
Cos:

subprojects/robotpy-wpimath/gen/geometry/Rotation3d.yml

+7
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ classes:
1616
overloads:
1717
'':
1818
const Quaternion&:
19+
keepalive: []
1920
units::radian_t, units::radian_t, units::radian_t:
2021
const Eigen::Vector3d&, units::radian_t:
22+
keepalive: []
2123
const Eigen::Vector3d&:
24+
keepalive: []
2225
const Eigen::Matrix3d&:
26+
keepalive: []
2327
const Eigen::Vector3d&, const Eigen::Vector3d&:
28+
keepalive: []
2429
const Rotation2d&:
30+
keepalive: []
2531
operator+:
2632
operator-:
2733
overloads:
@@ -38,6 +44,7 @@ classes:
3844
Z:
3945
Axis:
4046
Angle:
47+
ToMatrix:
4148
ToRotation2d:
4249

4350
inline_code: |

subprojects/robotpy-wpimath/gen/geometry/Transform2d.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ classes:
1616
Transform2d:
1717
overloads:
1818
const Pose2d&, const Pose2d&:
19+
keepalive: []
1920
Translation2d, Rotation2d:
2021
units::meter_t, units::meter_t, Rotation2d:
22+
const Eigen::Matrix3d&:
23+
rename: fromMatrix
24+
keepalive: []
2125
'':
2226
Translation:
23-
Rotation:
2427
X:
2528
Y:
29+
ToMatrix:
30+
Rotation:
2631
Inverse:
2732
operator*:
2833
operator/:

subprojects/robotpy-wpimath/gen/geometry/Transform3d.yml

+6
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@ classes:
1515
Transform3d:
1616
overloads:
1717
const Pose3d&, const Pose3d&:
18+
keepalive: []
1819
Translation3d, Rotation3d:
1920
units::meter_t, units::meter_t, units::meter_t, Rotation3d:
21+
const Eigen::Matrix4d&:
22+
rename: fromMatrix
23+
keepalive: []
2024
'':
2125
const frc::Transform2d&:
26+
keepalive: []
2227
Translation:
2328
X:
2429
Y:
2530
Z:
31+
ToMatrix:
2632
Rotation:
2733
Inverse:
2834
operator*:

subprojects/robotpy-wpimath/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ install_requires = [
1111

1212
[build-system]
1313
requires = [
14-
"robotpy-build<2025.0.0b1,~=2025.0.0a6",
14+
"robotpy-build<2025.0.0b1,~=2025.0.0a8",
1515
"robotpy-wpiutil~=2025.0.0b3",
1616
# "numpy", # broken in raspbian CI
1717
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import importlib.util
2+
import math
3+
4+
import pytest
5+
6+
from wpimath.geometry import Rotation2d
7+
8+
9+
@pytest.mark.parametrize(
10+
"radians,degrees",
11+
[
12+
(math.pi / 3, 60.0),
13+
(math.pi / 4, 45.0),
14+
],
15+
)
16+
def test_radians_to_degrees(radians: float, degrees: float):
17+
rot = Rotation2d(radians)
18+
assert math.isclose(degrees, rot.degrees())
19+
20+
21+
@pytest.mark.parametrize(
22+
"degrees,radians",
23+
[
24+
(45.0, math.pi / 4),
25+
(30.0, math.pi / 6),
26+
],
27+
)
28+
def test_degrees_to_radians(degrees: float, radians: float):
29+
rot = Rotation2d.fromDegrees(degrees)
30+
assert math.isclose(radians, rot.radians())
31+
32+
33+
def test_rotate_by_from_zero() -> None:
34+
zero = Rotation2d()
35+
rotated = zero + Rotation2d.fromDegrees(90)
36+
37+
assert math.isclose(math.pi / 2, rotated.radians())
38+
assert math.isclose(90.0, rotated.degrees())
39+
40+
41+
def test_rotate_by_non_zero() -> None:
42+
rot = Rotation2d.fromDegrees(90.0)
43+
rot += Rotation2d.fromDegrees(30.0)
44+
45+
assert math.isclose(120.0, rot.degrees())
46+
47+
48+
def test_minus() -> None:
49+
rot1 = Rotation2d.fromDegrees(70)
50+
rot2 = Rotation2d.fromDegrees(30)
51+
52+
assert math.isclose(40.0, (rot1 - rot2).degrees())
53+
54+
55+
def test_unary_minus() -> None:
56+
rot = Rotation2d.fromDegrees(20)
57+
assert math.isclose(-20.0, (-rot).degrees())
58+
59+
60+
def test_equality() -> None:
61+
rot1 = Rotation2d.fromDegrees(43.0)
62+
rot2 = Rotation2d.fromDegrees(43.0)
63+
assert rot1 == rot2
64+
65+
rot1 = Rotation2d.fromDegrees(-180.0)
66+
rot2 = Rotation2d.fromDegrees(180.0)
67+
assert rot1 == rot2
68+
69+
70+
def test_inequality() -> None:
71+
rot1 = Rotation2d.fromDegrees(43.0)
72+
rot2 = Rotation2d.fromDegrees(43.5)
73+
assert rot1 != rot2
74+
75+
76+
@pytest.mark.skipif(
77+
importlib.util.find_spec("numpy") is None, reason="numpy is not available"
78+
)
79+
def test_to_matrix() -> None:
80+
before = Rotation2d.fromDegrees(20.0)
81+
after = Rotation2d.fromMatrix(before.toMatrix())
82+
assert before == after

subprojects/robotpy-wpinet/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ install_requires = [
4141

4242
[build-system]
4343
requires = [
44-
"robotpy-build<2025.0.0b1,~=2025.0.0a6",
44+
"robotpy-build<2025.0.0b1,~=2025.0.0a8",
4545
"robotpy-wpiutil~=2025.0.0b3",
4646
]

subprojects/robotpy-wpiutil/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ install_requires = []
99

1010
[build-system]
1111
requires = [
12-
"robotpy-build<2025.0.0b1,~=2025.0.0a6",
12+
"robotpy-build<2025.0.0b1,~=2025.0.0a8",
1313
]
1414

1515
[tool.robotpy-build]

subprojects/robotpy-xrp/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ robotpysimext = [
1616

1717
[build-system]
1818
requires = [
19-
"robotpy-build<2025.0.0b1,~=2025.0.0a6",
19+
"robotpy-build<2025.0.0b1,~=2025.0.0a8",
2020
"wpilib~=2025.0.0b3"
2121
]
2222

0 commit comments

Comments
 (0)