Expand description
§use-linear
Small 2D vector and 2×2 matrix helpers for `RustUse`.
Explicit dot products, matrix products, and small linear-system solves without a larger linear-algebra framework.
§Install
[dependencies]
use-linear = "0.0.1"§Foundation
use-linear provides a deliberately small numeric linear-algebra surface for 2D vectors and 2×2 matrices. The first slice includes a Vector2 type, a Matrix2 type, dot products, matrix-vector and matrix-matrix products, and explicit solving of small linear systems through LinearError. The crate stays close to ordinary f64 math instead of introducing a large generic tensor framework.
Vector primitivesVector2 covers basic 2D numeric vectors with arithmetic, dot products, and norms.
|
Matrix primitivesMatrix2 covers determinants, trace, transpose, matrix products, and matrix-vector products.
|
Small system solvessolve_2x2 and Matrix2::solve keep singular handling explicit with LinearError.
|
| Helper group | Primary items | Best fit |
|---|---|---|
| Vector operations | Vector2, dot | Small numeric code that needs explicit 2D linear operations |
| Matrix operations | Matrix2 | Call sites that need compact 2×2 products, determinants, and trace values |
| Solves and error handling | solve_2x2, LinearError | Small systems where singular behavior should stay explicit |
§When to use directly
Choose use-linear directly when vector and matrix utilities are the only surface you need and you want to keep that concern narrower than the umbrella facade.
| Scenario | Use use-linear directly? | Why |
|---|---|---|
| You need 2D numeric vectors and 2×2 matrices | Yes | The current surface already covers the common small linear-algebra cases directly |
| You need explicit handling of singular 2×2 solves | Yes | The API keeps failure visible through LinearError |
| 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 focused on
f64-based 2D vectors and 2×2 matrices instead of a broader generic tensor framework. - Geometry-specific spatial types and broader algebraic traits belong in adjacent focused crates.
§Examples
§Vector and matrix products
use use_linear::{Matrix2, Vector2, dot};
let vector = Vector2::new(3.0, 4.0);
let other = Vector2::new(-2.0, 1.0);
let matrix = Matrix2::new(2.0, 1.0, 5.0, 3.0);
assert!((dot(vector, other) + 2.0).abs() < 1.0e-12);
assert!((vector.magnitude() - 5.0).abs() < 1.0e-12);
assert_eq!(matrix.mul_vector(Vector2::new(1.0, -1.0)), Vector2::new(1.0, 2.0));
assert_eq!(matrix * Matrix2::identity(), matrix);§Solving a 2×2 system
use use_linear::{Matrix2, Vector2, solve_2x2};
let matrix = Matrix2::new(2.0, 1.0, 5.0, 3.0);
let rhs = Vector2::new(1.0, 2.0);
assert_eq!(solve_2x2(matrix, rhs)?, Vector2::new(1.0, -1.0));§Status
use-linear is a concrete pre-1.0 crate in the RustUse docs surface. The API remains intentionally small while adjacent geometry and algebra crates continue to grow around it.
Linear-algebra utilities for RustUse.
Modules§
- prelude
- Common ergonomic imports for
use-linear.
Structs§
Enums§
- Linear
Error - Errors returned by linear helpers when a system cannot be solved.