Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more constructors and math helpers for primitive shapes #10632

Merged
merged 35 commits into from
Jan 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
fbdeeea
Add more helpers and constructors for 2D primitives
Jondolf Nov 18, 2023
0206169
Add more helpers and constructors for 3D primitives
Jondolf Nov 18, 2023
15824e8
Fix doc comment
Jondolf Nov 18, 2023
5ee96a5
Fix circumference formula
Jondolf Nov 18, 2023
bfa7c2c
Use area in debug assert
Jondolf Nov 18, 2023
8196a9c
Fix method order inconsistency
Jondolf Nov 18, 2023
a81cb75
Improve numerical precision of `RegularPolygon::area`
Jondolf Nov 18, 2023
cf4f372
Rename apothem to inradius with apothem as a doc alias
Jondolf Nov 18, 2023
a924ed9
Add tests for 2D primitive math
Jondolf Nov 18, 2023
ed9f519
Fix test precision
Jondolf Nov 18, 2023
f5f5fa7
Derive `PartialEq` for trivial primitives
Jondolf Nov 18, 2023
a80a482
Fix `Capsule` volume computation
Jondolf Nov 18, 2023
c383202
Improve `Torus` docs and computations
Jondolf Nov 18, 2023
954551d
Add tests for 3D primitive math
Jondolf Nov 18, 2023
7334d94
Add more assert messages
Jondolf Nov 18, 2023
72d0ab7
Revert torus representation changes
Jondolf Nov 19, 2023
2ca7ce8
Simplify mathematical computations
Jondolf Nov 19, 2023
aabcc38
Merge branch 'main' into primitive-helpers
Jondolf Nov 20, 2023
0eff5a6
Trigger CI
Jondolf Nov 20, 2023
29cb1e6
Trigger CI again
Jondolf Nov 20, 2023
ca33bc7
Trigger CI again pretty pleeease
Jondolf Nov 20, 2023
ee94842
Merge branch 'main' into primitive-helpers
Jondolf Nov 21, 2023
684f5e4
Add assert message in `Plane3d::from_points`
Jondolf Nov 21, 2023
b34780b
Clean up formula
Jondolf Nov 21, 2023
f25808f
Remove assert
Jondolf Nov 21, 2023
4ee621c
Compute `RegularPolygon::area` with simpler formula
Jondolf Nov 21, 2023
7cf0615
Change assert in `Plane3d::from_points`
Jondolf Nov 28, 2023
54fb9c3
Improve and clarify docs
Jondolf Nov 28, 2023
02ea616
Change number to word in assert
Jondolf Nov 28, 2023
e03488b
Merge branch 'main' into primitive-helpers
Jondolf Dec 6, 2023
e42ef6c
Merge branch 'main' into primitive-helpers
Jondolf Dec 13, 2023
5965561
Revert
Jondolf Jan 27, 2024
04cfb27
Merge branch 'main' into primitive-helpers
Jondolf Jan 27, 2024
e81138c
Fix merge issues
Jondolf Jan 27, 2024
3c1f8a8
Merge branch 'main' into primitive-helpers
Jondolf Jan 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more assert messages
  • Loading branch information
Jondolf committed Nov 18, 2023
commit 7334d94dc5233352547f4407e733d2726626cd0d
34 changes: 23 additions & 11 deletions crates/bevy_math/src/primitives/dim2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,15 @@ mod tests {
#[test]
fn circle_math() {
let circle = Circle { radius: 3.0 };
assert_eq!(circle.diameter(), 6.0);
assert_relative_eq!(circle.area(), 28.274334);
assert_relative_eq!(circle.perimeter(), 18.849556);
assert_eq!(circle.diameter(), 6.0, "incorrect diameter");
assert_eq!(circle.area(), 28.274334, "incorrect area");
assert_eq!(circle.perimeter(), 18.849556, "incorrect perimeter");
}

#[test]
fn ellipse_math() {
let ellipse = Ellipse::new(6.0, 2.0);
assert_relative_eq!(ellipse.area(), 9.424778);
assert_eq!(ellipse.area(), 9.424778, "incorrect area");
}

#[test]
Expand All @@ -473,8 +473,8 @@ mod tests {
Vec2::new(1.0, 4.0),
Vec2::new(7.0, 0.0),
);
assert_relative_eq!(triangle.perimeter(), 22.097439);
assert_relative_eq!(triangle.area(), 21.0);
assert_eq!(triangle.area(), 21.0, "incorrect area");
assert_eq!(triangle.perimeter(), 22.097439, "incorrect perimeter");
}

#[test]
Expand All @@ -484,8 +484,8 @@ mod tests {
rectangle,
Rectangle::from_corners(Vec2::new(-1.5, -3.5), Vec2::new(1.5, 3.5))
);
assert_eq!(rectangle.area(), 21.0);
assert_eq!(rectangle.perimeter(), 20.0);
assert_eq!(rectangle.area(), 21.0, "incorrect area");
assert_eq!(rectangle.perimeter(), 20.0, "incorrect perimeter");
}

#[test]
Expand All @@ -500,8 +500,20 @@ mod tests {
120.0,
"incorrect internal angle"
);
assert_eq!(polygon.internal_angle_radians(), 120_f32.to_radians());
assert_eq!(polygon.external_angle_degrees(), 60.0);
assert_eq!(polygon.external_angle_radians(), 60_f32.to_radians());
assert_eq!(
polygon.internal_angle_radians(),
120_f32.to_radians(),
"incorrect internal angle"
);
assert_eq!(
polygon.external_angle_degrees(),
60.0,
"incorrect external angle"
);
assert_eq!(
polygon.external_angle_radians(),
60_f32.to_radians(),
"incorrect external angle"
);
}
}
Loading