Expand description
§use-trigonometry
Small angle and trigonometry helpers for `RustUse`.
Explicit degree/radian handling, normalization, and direct sine, cosine, and tangent helpers.
§Install
[dependencies]
use-trigonometry = "0.0.1"§Foundation
use-trigonometry provides a deliberately small trigonometry surface around explicit angle units. The crate exposes an Angle type stored in radians, conversion helpers for degrees and radians, normalization helpers for wrapped inputs, and direct sin, cos, and tan utilities for degree-based call sites. The first slice stays close to ordinary f64 values instead of introducing a larger symbolic or identity-heavy framework.
Explicit unitsAngle, degrees_to_radians, and radians_to_degrees keep unit intent visible at the call site.
|
Wrapping helpersnormalized, normalized_signed, normalize_degrees, and normalize_radians handle wrapped inputs directly.
|
Basic trig evaluationsin, cos, tan, sin_deg, cos_deg, and tan_deg cover the common numeric cases.
|
| Helper group | Primary items | Best fit |
|---|---|---|
| Angle values and unit conversion | Angle, degrees_to_radians, radians_to_degrees | Code that should stay explicit about whether an input is degrees or radians |
| Normalization | Angle::normalized, Angle::normalized_signed, normalize_degrees, normalize_radians | Handling wrapped or cyclic inputs before downstream math |
| Direct trig helpers | Angle::sin, Angle::cos, Angle::tan, sin_deg, cos_deg, tan_deg | Small apps and utilities that want direct numeric trig without a larger abstraction |
§When to use directly
Choose use-trigonometry directly when angle or trigonometric utilities are the only surface you need and you want to keep that concern narrower than the full facade.
| Scenario | Use use-trigonometry directly? | Why |
|---|---|---|
| You need explicit degree/radian handling without a broader math facade | Yes | The crate keeps unit intent local and direct |
| You need wrapped-angle normalization and basic trig evaluation | Yes | The current surface already covers those cases with a small API |
| You also need geometry, calculus, or other math domains | Usually no | use-math can compose the concrete surfaces behind features |
§Scope
- The current surface is intentionally small and concrete.
- Helpers stay numeric and explicit instead of introducing symbolic identities or generalized expression trees.
- Geometry-specific orientation and calculus-specific analytic helpers belong in adjacent focused crates.
§Examples
§Angle conversion and normalization
use use_trigonometry::{Angle, degrees_to_radians, normalize_degrees, radians_to_degrees};
let acute = Angle::from_degrees(30.0);
let wrapped = Angle::from_degrees(765.0).normalized();
assert!((acute.radians() - degrees_to_radians(30.0)).abs() < 1.0e-12);
assert!((acute.degrees() - radians_to_degrees(acute.radians())).abs() < 1.0e-12);
assert!((wrapped.degrees() - 45.0).abs() < 1.0e-12);
assert!((normalize_degrees(-90.0) - 270.0).abs() < 1.0e-12);§Direct trig helpers
use use_trigonometry::{Angle, cos_deg, sin_deg, tan_deg};
let acute = Angle::from_degrees(30.0);
assert!((acute.sin() - 0.5).abs() < 1.0e-12);
assert!((acute.cos() - cos_deg(30.0)).abs() < 1.0e-12);
assert!((sin_deg(30.0) - 0.5).abs() < 1.0e-12);
assert!((tan_deg(45.0) - 1.0).abs() < 1.0e-12);§Status
use-trigonometry is a concrete pre-1.0 crate in the RustUse docs surface. The API remains intentionally small while adjacent geometry and calculus crates continue to grow around it.
Trigonometric utilities for RustUse.
Modules§
- prelude
- Common ergonomic imports for
use-trigonometry.
Structs§
- Angle
- Explicit angle value stored in radians.
Functions§
- cos_deg
- Evaluates
cosfor a degrees input. - degrees_
to_ radians - Converts a degrees value into radians.
- normalize_
degrees - Normalizes a degrees value into the interval
[0, 360). - normalize_
radians - Normalizes a radians value into the interval
[0, 2π). - radians_
to_ degrees - Converts a radians value into degrees.
- sin_deg
- Evaluates
sinfor a degrees input. - tan_deg
- Evaluates
tanfor a degrees input.