Skip to content

Commit 3154612

Browse files
committed
Rename geometry from matrix constructor overloads
1 parent f48796a commit 3154612

File tree

7 files changed

+112
-1
lines changed

7 files changed

+112
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 6 additions & 1 deletion
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

Lines changed: 6 additions & 0 deletions
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*:
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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(importlib.util.find_spec("numpy") is None)
77+
def test_to_matrix() -> None:
78+
before = Rotation2d.fromDegrees(20.0)
79+
after = Rotation2d.fromMatrix(before.toMatrix())
80+
assert before == after

0 commit comments

Comments
 (0)