6 个版本 (破坏性)
0.6.0 | 2023 年 12 月 18 日 |
---|---|
0.5.0 | 2023 年 4 月 15 日 |
0.4.1 | 2023 年 2 月 11 日 |
0.3.0 | 2023 年 2 月 2 日 |
0.1.0 | 2022 年 8 月 30 日 |
#81 在 值格式化
每月 22 次下载
73KB
1.5K SLoC
angulus
无单位的角。
它解决了什么问题?
使用简单的浮点数存储角度值是容易出错的:您可能将一个以弧度为单位的角度和一个以度为单位的角度相加,或者您可能尝试计算一个度数的余弦值并得到一个意外的结果。
angulus
提供了一个表示无特定单位的角的类型。
示例
use angulus::{Angle, ToAngle};
use angulus::units::Degrees;
// Create an angle of 90°.
let alpha = 90.0_f32.deg();
// Create an angle of π/4 rad (45°).
let beta = Angle::RAD_FRAC_PI_4;
// Add the two angle without worrying about units.
let gamma = alpha + beta;
// Print the result.
println!(
"The cosine of {} is {}",
Degrees(gamma), // The angle is wrapped to display the value in degrees.
gamma.cos() // Compute the cosine without worrying about units.
);
// Output : The cosine of 135° is -0.70710677
功能
std
:默认情况下,angulus 链接到标准库。禁用此功能可删除此依赖项,并在#![no_std]
Crates 中使用 angulus。libm
:当禁用std
时,使用 libm crate 对数学方法(sin、cos、tan)进行操作。serde
:使用 serde crate 启用序列化和反序列化。rand
:使用 rand crate 生成随机角度。
最低支持的 Rust 版本
此 crate 需要 Rust 1.61.0 或更高版本。
许可证
根据您的选择,以下任一许可证
除非明确说明,否则任何有意提交以包含在此 crate 中,根据 Apache-2.0 许可证定义的贡献,都应按上述方式双许可,而无需任何其他条款或条件。
依赖项
~0–345KB