From 08859c3921e12fc1558dfbcd8bf8686591bf6f17 Mon Sep 17 00:00:00 2001 From: Treagzhao <920866163@qq.com> Date: Tue, 10 Mar 2026 09:29:00 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ceof=E5=90=91=E9=87=8F?= =?UTF-8?q?=E5=92=8C=E6=A0=87=E9=87=8F=E7=9B=B8=E4=B9=98=E7=9A=84=E8=AF=AD?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.txt | 676 ++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 +- src/physics/basic.rs | 156 +++++---- src/physics/basic/vector.rs | 256 +++++++++++++- 4 files changed, 1006 insertions(+), 84 deletions(-) create mode 100644 1.txt diff --git a/1.txt b/1.txt new file mode 100644 index 0000000..2b1050b --- /dev/null +++ b/1.txt @@ -0,0 +1,676 @@ + Compiling zmatrix v0.2.27 (/Users/treagzhao/Documents/Workspace/zmatrix) +warning: unused import: `error` + --> src/dense/initial.rs:1:20 + | +1 | use crate::dense::{error, Matrix}; + | ^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: unused import: `array_init::array_init` + --> src/dense/initial.rs:2:5 + | +2 | use array_init::array_init; + | ^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `util` + --> src/dense/operation.rs:1:27 + | +1 | use crate::dense::{error, util, Matrix}; + | ^^^^ + +warning: unused import: `approx::assert_relative_eq` + --> src/dense/operation.rs:2:5 + | +2 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `array_init::array_init` + --> src/dense/operation.rs:3:5 + | +3 | use array_init::array_init; + | ^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused imports: `Arc` and `mpsc` + --> src/dense/operation.rs:9:17 + | +9 | use std::sync::{mpsc, Arc}; + | ^^^^ ^^^ + +warning: unused import: `std::thread` + --> src/dense/operation.rs:10:5 + | +10 | use std::thread; + | ^^^^^^^^^^^ + +warning: unused imports: `IntoParallelIterator` and `ParallelBridge` + --> src/dense/shape.rs:4:22 + | +4 | use rayon::prelude::{IntoParallelIterator, ParallelBridge}; + | ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ + +warning: unused imports: `Arc`, `Mutex`, and `RwLock` + --> src/dense/shape.rs:7:17 + | +7 | use std::sync::{Arc, Mutex, RwLock}; + | ^^^ ^^^^^ ^^^^^^ + +warning: unused imports: `AtomicPtr` and `Ordering` + --> src/dense/shape.rs:8:25 + | +8 | use std::sync::atomic::{AtomicPtr, Ordering}; + | ^^^^^^^^^ ^^^^^^^^ + +warning: unused import: `std::thread` + --> src/dense/shape.rs:9:5 + | +9 | use std::thread; + | ^^^^^^^^^^^ + +warning: unused import: `array_init::array_init` + --> src/dense/shape.rs:10:5 + | +10 | use array_init::array_init; + | ^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `Sub` + --> src/dense/util.rs:4:26 + | +4 | use std::ops::{Add, Mul, Sub}; + | ^^^ + +warning: unused imports: `Not` and `Sub` + --> src/dense.rs:8:26 + | +8 | use std::ops::{Add, Mul, Not, Sub}; + | ^^^ ^^^ + +warning: unused imports: `Arc` and `mpsc` + --> src/dense.rs:9:17 + | +9 | use std::sync::{mpsc, Arc}; + | ^^^^ ^^^ + +warning: unused import: `std::thread` + --> src/dense.rs:10:5 + | +10 | use std::thread; + | ^^^^^^^^^^^ + +warning: unused import: `crate::physics::basic` + --> src/physics/basic.rs:1:5 + | +1 | use crate::physics::basic; + | ^^^^^^^^^^^^^^^^^^^^^ + +warning: unused imports: `Acceleration`, `Mass`, and `Velocity` + --> src/physics/basic/energy.rs:2:5 + | +2 | Acceleration, Coef, Distance, Energy, EnergyType, Force, Mass, PhysicalQuantity, Velocity, + | ^^^^^^^^^^^^ ^^^^ ^^^^^^^^ + +warning: unused import: `approx::assert_relative_eq` + --> src/physics/basic/magnetic_angular_velocity.rs:4:5 + | +4 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `Area` + --> src/physics/basic/magnetic_moment.rs:342:52 + | +342 | use crate::physics::basic::{MagneticInduction, Area}; + | ^^^^ + +warning: unused imports: `AngularMomentumType`, `MassType`, and `Mass` + --> src/physics/basic/momentum.rs:3:46 + | +3 | use crate::physics::basic::{AngularMomentum, AngularMomentumType, Coef, Distance, Mass, MassType, Momentum, MomentumType, PhysicalQuantity}; + | ^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^ + +warning: duplicated attribute + --> src/physics/basic/vector/angular_velocity.rs:78:5 + | +78 | #[test] + | ^^^^^^^ + | + = note: `#[warn(duplicate_macro_attributes)]` on by default + +warning: unused import: `Mass` + --> src/physics/basic/vector/distance.rs:2:52 + | +2 | AngularMomentum, Coef, Distance, DistanceType, Mass, Momentum, Vector3, Velocity, + | ^^^^ + +warning: unused import: `Div` + --> src/physics/basic/vector/megnetic_induction.rs:1:16 + | +1 | use std::ops::{Div, Mul}; + | ^^^ + +warning: unused import: `crate::utils::float` + --> src/physics/basic/vector.rs:19:5 + | +19 | use crate::utils::float; + | ^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `crate::physics::basic::VelocityType::LightSpeed` + --> src/physics/basic/velocity.rs:3:5 + | +3 | use crate::physics::basic::VelocityType::LightSpeed; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `std::any::TypeId` + --> src/physics/basic/velocity.rs:318:9 + | +318 | use std::any::TypeId; + | ^^^^^^^^^^^^^^^^ + +warning: unused import: `DistanceType` + --> src/physics/basic/volume.rs:3:51 + | +3 | use crate::physics::basic::{Area, Coef, Distance, DistanceType, PhysicalQuantity, Volume, VolumeType}; + | ^^^^^^^^^^^^ + +warning: variant `g` should have an upper camel case name + --> src/physics/basic.rs:196:5 + | +196 | g, + | ^ help: convert the identifier to upper camel case: `G` + | + = note: `#[warn(non_camel_case_types)]` on by default + +warning: unused import: `super::*` + --> src/spatial_geometry/cos_matrix.rs:1:5 + | +1 | use super::*; + | ^^^^^^^^ + +warning: unused import: `sgn2_64` + --> src/spatial_geometry/cos_matrix.rs:6:32 + | +6 | use crate::utils::float::{sgn, sgn2_64}; + | ^^^^^^^ + +warning: unused import: `super::*` + --> src/spatial_geometry/quaternion.rs:1:5 + | +1 | use super::*; + | ^^^^^^^^ + +warning: duplicated attribute + --> src/utils/float.rs:51:5 + | +51 | #[test] + | ^^^^^^^ + +warning: unused import: `PhysicalQuantity` + --> src/spatial_geometry/cos_matrix.rs:4:44 + | +4 | use crate::physics::basic::{Angular, Coef, PhysicalQuantity, Vector3, VectorQuantity}; + | ^^^^^^^^^^^^^^^^ + +warning: unused import: `rayon::iter::ParallelIterator` + --> src/dense/operation.rs:4:5 + | +4 | use rayon::iter::ParallelIterator; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `rayon::prelude` + --> src/dense/operation.rs:5:5 + | +5 | use rayon::prelude::*; + | ^^^^^^^^^^^^^^ + +warning: unused import: `rayon::iter::ParallelIterator` + --> src/dense/shape.rs:3:5 + | +3 | use rayon::iter::ParallelIterator; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused variable: `expected` + --> src/dense/operation.rs:518:13 + | +518 | let expected: [i32; 0] = []; + | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_expected` + | + = note: `#[warn(unused_variables)]` on by default + +warning: unused variable: `result` + --> src/dense/operation.rs:870:13 + | +870 | let result = matrix.clamp(3.0, 2.0); + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` + +warning: unused variable: `data` + --> src/dense/shape.rs:185:13 + | +185 | let data = (1..=100).collect::>(); + | ^^^^ help: if this is intentional, prefix it with an underscore: `_data` + +warning: value assigned to `ceof` is never read + --> src/dense/util.rs:122:13 + | +122 | let mut ceof: i8 = 0; + | ^^^^ + | + = help: maybe it is overwritten before being read? + = note: `#[warn(unused_assignments)]` on by default + +warning: unused variable: `key` + --> src/dense/util.rs:128:9 + | +128 | let key = print_permutation(permutation); + | ^^^ help: if this is intentional, prefix it with an underscore: `_key` + +warning: unused variable: `vec` + --> src/dense/util.rs:286:19 + | +286 | if let Ok(vec) = res { + | ^^^ help: if this is intentional, prefix it with an underscore: `_vec` + +warning: variable does not need to be mutable + --> src/dense.rs:25:13 + | +25 | let mut digits: u8 = 0; + | ----^^^^^^ + | | + | help: remove this `mut` + | + = note: `#[warn(unused_mut)]` on by default + +warning: unused variable: `d2` + --> src/physics/basic/acceleration.rs:378:13 + | +378 | let d2 = d1.as_any().downcast_ref::().unwrap(); + | ^^ help: if this is intentional, prefix it with an underscore: `_d2` + +warning: unused variable: `d2` + --> src/physics/basic/angular_acceleration.rs:371:13 + | +371 | let d2 = dw.downcast_ref::().unwrap(); + | ^^ help: if this is intentional, prefix it with an underscore: `_d2` + +warning: unused variable: `d3` + --> src/physics/basic/angular_velocity.rs:506:13 + | +506 | let d3 = d2.downcast_ref::().unwrap(); + | ^^ help: if this is intentional, prefix it with an underscore: `_d3` + +warning: unused variable: `a` + --> src/physics/basic/area.rs:444:13 + | +444 | let a: &Area = any.downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_a` + +warning: unused variable: `c` + --> src/physics/basic/coef.rs:379:13 + | +379 | let c = result.downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_c` + +warning: unused variable: `result` + --> src/physics/basic/magnetic_induction.rs:372:13 + | +372 | let result = convert_gauss_value(1.0, MagneticInductionType::Tesla, MagneticInductionType::KiloGauss).unwrap(); + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` + +warning: unused variable: `result` + --> src/physics/basic/magnetic_induction.rs:378:13 + | +378 | let result = convert_gauss_value(1.0, MagneticInductionType::KiloGauss, MagneticInductionType::Tesla).unwrap(); + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` + +warning: unused variable: `result` + --> src/physics/basic/magnetic_induction.rs:400:13 + | +400 | let result = convert_tesla_value(1.0, MagneticInductionType::Tesla, MagneticInductionType::KiloGauss).unwrap(); + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` + +warning: unused variable: `result` + --> src/physics/basic/magnetic_induction.rs:406:13 + | +406 | let result = convert_tesla_value(1.0, MagneticInductionType::KiloGauss, MagneticInductionType::Tesla).unwrap(); + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` + +warning: unused variable: `a` + --> src/physics/basic/magnetic_induction.rs:464:13 + | +464 | let a = any.downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_a` + +warning: unused variable: `m2` + --> src/physics/basic/mass.rs:215:13 + | +215 | let m2 = m1.as_g(); + | ^^ help: if this is intentional, prefix it with an underscore: `_m2` + +warning: unused variable: `p_zero` + --> src/physics/basic/power.rs:876:13 + | +876 | let p_zero = Power::from_watt(0.0); + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_p_zero` + +warning: unused variable: `unit_name` + --> src/physics/basic/power.rs:895:21 + | +895 | for (power, unit_name) in units { + | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unit_name` + +warning: variable does not need to be mutable + --> src/physics/basic/vector/angular.rs:102:13 + | +102 | let mut result: Vector3 = Vector3::new( + | ----^^^^^^ + | | + | help: remove this `mut` + +warning: variable does not need to be mutable + --> src/physics/basic/vector/angular.rs:111:13 + | +111 | let mut result: Vector3 = Vector3::new( + | ----^^^^^^ + | | + | help: remove this `mut` + +warning: unused variable: `ti` + --> src/physics/basic/vector/angular.rs:1069:14 + | +1069 | let (ti, tj, tk) = (1u8, 2u8, 3u8); // 这里与上面 seq 一致为 Y(2) Z(3) X(1)? 修正如下: + | ^^ help: if this is intentional, prefix it with an underscore: `_ti` + +warning: unused variable: `tj` + --> src/physics/basic/vector/angular.rs:1069:18 + | +1069 | let (ti, tj, tk) = (1u8, 2u8, 3u8); // 这里与上面 seq 一致为 Y(2) Z(3) X(1)? 修正如下: + | ^^ help: if this is intentional, prefix it with an underscore: `_tj` + +warning: unused variable: `tk` + --> src/physics/basic/vector/angular.rs:1069:22 + | +1069 | let (ti, tj, tk) = (1u8, 2u8, 3u8); // 这里与上面 seq 一致为 Y(2) Z(3) X(1)? 修正如下: + | ^^ help: if this is intentional, prefix it with an underscore: `_tk` + +warning: unused variable: `input` + --> src/physics/basic/vector.rs:734:17 + | +734 | let mut input = [1f32, 4f32, 9f32]; + | ^^^^^ help: if this is intentional, prefix it with an underscore: `_input` + +warning: variable does not need to be mutable + --> src/physics/basic/vector.rs:734:13 + | +734 | let mut input = [1f32, 4f32, 9f32]; + | ----^^^^^ + | | + | help: remove this `mut` + +warning: unused variable: `a` + --> src/physics/basic/velocity.rs:498:13 + | +498 | let a = v_any.downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_a` + +warning: unused variable: `v` + --> src/physics/basic/volume.rs:254:13 + | +254 | let v = b.as_any().downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_v` + +warning: unused variable: `d` + --> src/physics/basic.rs:615:13 + | +615 | let d = g.as_any().downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_d` + +warning: unused variable: `d` + --> src/physics/basic.rs:618:13 + | +618 | let d = g.as_any().downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_d` + +warning: value assigned to `x` is never read + --> src/spatial_geometry/cos_matrix.rs:485:17 + | +485 | let mut x: Angular = Angular::default(); + | ^ + | + = help: maybe it is overwritten before being read? + +warning: field `digits` is never read + --> src/dense.rs:17:5 + | +12 | pub struct Matrix + | ------ field in this struct +... +17 | digits: u8, + | ^^^^^^ + | + = note: `Matrix` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis + = note: `#[warn(dead_code)]` on by default + +warning: constant `LIGHT_SPEED` is never used + --> src/physics/basic/distance.rs:5:7 + | +5 | const LIGHT_SPEED: f64 = 299792458.0; + | ^^^^^^^^^^^ + +warning: function `test_norm_square_basic` is never used + --> src/physics/basic/vector.rs:1058:8 + | +1058 | fn test_norm_square_basic() { + | ^^^^^^^^^^^^^^^^^^^^^^ + +warning: method `T` should have a snake case name + --> src/dense/shape.rs:26:12 + | +26 | pub fn T(&self) -> Matrix { + | ^ help: convert the identifier to snake case: `t` + | + = note: `#[warn(non_snake_case)]` on by default + +warning: function `test_T` should have a snake case name + --> src/dense/shape.rs:110:8 + | +110 | fn test_T() { + | ^^^^^^ help: convert the identifier to snake case: `test_t` + +warning: variable `delta_B` should have a snake case name + --> src/physics/basic/vector/magnetic_angular_velocity.rs:1578:13 + | +1578 | let delta_B = b - b_prev; + | ^^^^^^^ help: convert the identifier to snake case: `delta_b` + +warning: `zmatrix` (lib test) generated 75 warnings (run `cargo fix --lib -p zmatrix --tests` to apply 34 suggestions) +warning: unused import: `rayon::prelude::*` + --> src/dense/operation.rs:5:5 + | +5 | use rayon::prelude::*; + | ^^^^^^^^^^^^^^^^^ + +warning: unused import: `approx::assert_relative_eq` + --> src/physics/basic/energy.rs:4:5 + | +4 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `approx::assert_relative_eq` + --> src/physics/basic/force.rs:4:5 + | +4 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `approx::assert_relative_eq` + --> src/physics/basic/magnetic_moment.rs:4:5 + | +4 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `approx::assert_relative_eq` + --> src/physics/basic/mass.rs:4:5 + | +4 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `approx::assert_relative_eq` + --> src/physics/basic/power.rs:4:5 + | +4 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `approx::assert_relative_eq` + --> src/physics/basic/torque.rs:4:5 + | +4 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `super::*` + --> src/physics/basic/vector/magnetic_angular_velocity.rs:1:5 + | +1 | use super::*; + | ^^^^^^^^ + +warning: unused variable: `key` + --> src/dense/util.rs:128:9 + | +128 | let key = print_permutation(permutation); + | ^^^ help: if this is intentional, prefix it with an underscore: `_key` + | + = note: `#[warn(unused_variables)]` on by default + +warning: struct `CalculateResult` is never constructed + --> src/dense/util.rs:8:12 + | +8 | pub struct CalculateResult + | ^^^^^^^^^^^^^^^ + +warning: function `convert_to_f64` is never used + --> src/dense/util.rs:17:8 + | +17 | pub fn convert_to_f64(value: T) -> Result + | ^^^^^^^^^^^^^^ + +warning: function `calculate_in_threads` is never used + --> src/dense/util.rs:60:8 + | +60 | pub fn calculate_in_threads<'a, const ROWS: usize, const COLS: usize, T, F>( + | ^^^^^^^^^^^^^^^^^^^^ + +warning: function `calculate_multi` is never used + --> src/dense/util.rs:93:8 + | +93 | pub fn calculate_multi( + | ^^^^^^^^^^^^^^^ + +warning: `zmatrix` (lib) generated 53 warnings (40 duplicates) (run `cargo fix --lib -p zmatrix` to apply 8 suggestions) +warning: unused import: `Energy` + --> examples/example_magnetic_moment.rs:1:66 + | +1 | use zmatrix::physics::basic::{MagneticMoment, MagneticInduction, Energy, PhysicalQuantity}; + | ^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: unused imports: `Energy`, `MagneticInduction`, `Mass`, `Power`, `Torque`, `VectorQuantity`, and `Volume` + --> examples/example_vector_quantity_restriction.rs:1:31 + | +1 | use zmatrix::physics::basic::{VectorQuantity, Distance, Velocity, Force, Torque, MagneticInduction, Vector3, Mass, Energy, Power, Volume}; + | ^^^^^^^^^^^^^^ ^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^ ^^^^^ ^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: unused variable: `acc` + --> examples/example_physics.rs:20:9 + | +20 | let acc:Acceleration = velocity / time; + | ^^^ help: if this is intentional, prefix it with an underscore: `_acc` + | + = note: `#[warn(unused_variables)]` on by default + +warning: unused variable: `angular_accel` + --> examples/example_physics.rs:25:9 + | +25 | let angular_accel:AngularAcceleration = omg / time; + | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_angular_accel` + +warning: unused variable: `area` + --> examples/example_physics.rs:28:9 + | +28 | let area:Area = dis * dis; + | ^^^^ help: if this is intentional, prefix it with an underscore: `_area` + +warning: unused import: `Acceleration` + --> examples/example_energy.rs:1:65 + | +1 | use zmatrix::physics::basic::{Energy, Distance, Mass, Velocity, Acceleration, PhysicalQuantity}; + | ^^^^^^^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: unused variable: `pos_vector` + --> examples/example_physics.rs:33:9 + | +33 | let pos_vector:Vector3 = Vector3::new( + | ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_pos_vector` + +warning: function `calculate` is never used + --> examples/example_physics.rs:16:4 + | +16 | fn calculate() { + | ^^^^^^^^^ + | + = note: `#[warn(dead_code)]` on by default + +warning: function `exmples_vector3` is never used + --> examples/example_physics.rs:32:4 + | +32 | fn exmples_vector3(){ + | ^^^^^^^^^^^^^^^ + +warning: unused import: `zmatrix::dense` + --> examples/examples_dense.rs:1:5 + | +1 | use zmatrix::dense; + | ^^^^^^^^^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: unused `Result` that must be used + --> examples/examples_dense.rs:61:5 + | +61 | m1.set(1, 1, 12); + | ^^^^^^^^^^^^^^^^ + | + = note: this `Result` may be an `Err` variant, which should be handled + = note: `#[warn(unused_must_use)]` on by default +help: use `let _ = ...` to ignore the resulting value + | +61 | let _ = m1.set(1, 1, 12); + | +++++++ + +warning: `zmatrix` (example "example_magnetic_moment") generated 1 warning (run `cargo fix --example "example_magnetic_moment"` to apply 1 suggestion) +warning: `zmatrix` (example "example_physics") generated 6 warnings +warning: `zmatrix` (example "example_vector_quantity_restriction") generated 1 warning (run `cargo fix --example "example_vector_quantity_restriction"` to apply 1 suggestion) +warning: `zmatrix` (example "example_energy") generated 1 warning (run `cargo fix --example "example_energy"` to apply 1 suggestion) +warning: `zmatrix` (example "examples_dense") generated 2 warnings (run `cargo fix --example "examples_dense"` to apply 1 suggestion) +warning: unused import: `Energy` + --> examples/example_torque.rs:1:49 + | +1 | use zmatrix::physics::basic::{Torque, Distance, Energy, PhysicalQuantity}; + | ^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: `zmatrix` (example "example_torque") generated 1 warning (run `cargo fix --example "example_torque"` to apply 1 suggestion) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.85s + Running unittests src/lib.rs (target/debug/deps/zmatrix-0317ef656e62916a) + Doc-tests zmatrix +warning: variant `g` should have an upper camel case name + --> src/physics/basic.rs:196:5 + | +196 | g, + | ^ help: convert the identifier to upper camel case: `G` + | + = note: `#[warn(non_camel_case_types)]` on by default + +warning: 1 warning emitted + diff --git a/Cargo.toml b/Cargo.toml index bbe75d6..9ffc383 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zmatrix" -version = "0.2.26" +version = "0.2.27" edition = "2021" authors = ["Treagzhao"] license = "MIT" diff --git a/src/physics/basic.rs b/src/physics/basic.rs index 67aec79..415b822 100644 --- a/src/physics/basic.rs +++ b/src/physics/basic.rs @@ -50,13 +50,13 @@ pub enum VelocityType { LightSpeed, } /// 距离物理量结构体 -/// +/// /// 表示空间中的距离,支持多种单位制 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::Distance; -/// +/// /// let distance = Distance::from_m(100.0); /// println!("距离: {} 米", distance.as_m()); /// ``` @@ -66,13 +66,13 @@ pub struct Distance { v: f64, } /// 速度物理量结构体 -/// +/// /// 表示物体运动的快慢和方向,支持多种单位制 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::Velocity; -/// +/// /// let velocity = Velocity::from_m_per_sec(10.0); /// println!("速度: {} m/s", velocity.as_m_per_sec()); /// ``` @@ -83,13 +83,13 @@ pub struct Velocity { } /// 加速度物理量结构体 -/// +/// /// 表示速度变化的快慢,支持多种单位制 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::Acceleration; -/// +/// /// let acceleration = Acceleration::from_g(1.0); /// println!("加速度: {} g", acceleration.as_g()); /// ``` @@ -112,13 +112,13 @@ pub enum AngularType { } /// 角度物理量结构体 -/// +/// /// 表示角度大小,支持弧度和度数单位 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::Angular; -/// +/// /// let angle = Angular::from_rad(std::f64::consts::PI); /// println!("角度: {} 弧度", angle.as_rad()); /// ``` @@ -137,13 +137,13 @@ pub enum AngularVelocityType { } /// 角速度物理量结构体 -/// +/// /// 表示角度变化的快慢,支持多种单位制 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::AngularVelocity; -/// +/// /// let angular_velocity = AngularVelocity::from_rad_per_second(1.0); /// println!("角速度: {} rad/s", angular_velocity.as_rad_per_second()); /// ``` @@ -160,13 +160,13 @@ pub enum AngularAccelerationType { } /// 角加速度物理量结构体 -/// +/// /// 表示角速度变化的快慢,支持多种单位制 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::AngularAcceleration; -/// +/// /// let angular_acceleration = AngularAcceleration::from_rad_per_second2(1.0); /// println!("角加速度: {} rad/s²", angular_acceleration.as_rad_per_second2()); /// ``` @@ -176,13 +176,13 @@ pub struct AngularAcceleration { v: f64, } /// 系数物理量结构体 -/// +/// /// 表示无量纲的系数或比例因子 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::Coef; -/// +/// /// let coefficient = Coef::new(0.5); /// println!("系数: {}", coefficient.get_value()); /// ``` @@ -197,13 +197,13 @@ pub enum MassType { } /// 质量物理量结构体 -/// +/// /// 表示物体的质量,支持千克和克单位 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::Mass; -/// +/// /// let mass = Mass::from_kg(1.0); /// println!("质量: {} kg", mass.as_kg()); /// ``` @@ -222,13 +222,13 @@ pub enum AngularMomentumType { NanoNms, // 纳牛顿·米·秒 (nN·m·s) } /// 角动量物理量结构体 -/// +/// /// 表示物体绕轴旋转的动量,是质量、速度和距离的乘积 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::AngularMomentum; -/// +/// /// let angular_momentum = AngularMomentum::from_kg_m2_per_second(1.0); /// println!("角动量: {} kg·m²/s", angular_momentum.as_kg_m2_per_second()); /// ``` @@ -243,13 +243,13 @@ pub enum MomentumType { KgKmperSecond, // 每秒1千克1千米 } /// 动量物理量结构体 -/// +/// /// 表示物体运动的动量,是质量和速度的乘积 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::Momentum; -/// +/// /// let momentum = Momentum::from_kg_m_s(1.0); /// println!("动量: {} kg·m/s", momentum.as_kg_m_s()); /// ``` @@ -260,16 +260,16 @@ pub struct Momentum { } /// 三维向量结构体 -/// +/// /// 表示三维空间中的向量,包含x、y、z三个分量 -/// +/// /// # 类型参数 /// * `T` - 向量分量的物理量类型,必须实现 `VectorQuantity` 和 `Default` trait -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::{Vector3, Distance}; -/// +/// /// let position = Vector3 { /// x: Distance::from_m(1.0), /// y: Distance::from_m(2.0), @@ -291,13 +291,13 @@ pub enum AreaType { } /// 面积物理量结构体 -/// +/// /// 表示二维空间的面积大小,支持平方米和平方千米单位 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::Area; -/// +/// /// let area = Area::from_m2(100.0); /// println!("面积: {} m²", area.as_m2()); /// ``` @@ -318,13 +318,13 @@ pub enum MagneticInductionType { KiloGauss, // 千 } /// 磁感应强度物理量结构体 -/// +/// /// 表示磁场强度,单位是特斯拉或高斯 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::MagneticInduction; -/// +/// /// let magnetic_field = MagneticInduction::from_tesla(1.0); /// println!("磁感应强度: {} T", magnetic_field.as_tesla()); /// ``` @@ -347,13 +347,13 @@ pub enum MagneticMomentType { } /// 磁矩物理量结构体 -/// +/// /// 表示磁偶极子的磁矩,单位是安培·平方米或焦耳/特斯拉 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::MagneticMoment; -/// +/// /// let magnetic_moment = MagneticMoment::from_am2(1.0); /// println!("磁矩: {} A·m²", magnetic_moment.as_am2()); /// ``` @@ -374,13 +374,13 @@ pub enum TorqueType { } /// 力矩物理量结构体 -/// +/// /// 表示力对物体产生的转动效应,单位是牛顿·米 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::Torque; -/// +/// /// let torque = Torque::from_nm(10.0); /// println!("力矩: {} N·m", torque.as_nm()); /// ``` @@ -404,13 +404,13 @@ pub enum EnergyType { } /// 能量物理量结构体 -/// +/// /// 表示物体做功的能力,单位是焦耳 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::Energy; -/// +/// /// let energy = Energy::from_joule(100.0); /// println!("能量: {} J", energy.as_joule()); /// ``` @@ -431,13 +431,13 @@ pub enum ForceType { } /// 力物理量结构体 -/// +/// /// 表示物体间的相互作用,单位是牛顿 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::Force; -/// +/// /// let force = Force::from_newton(10.0); /// println!("力: {} N", force.as_newton()); /// ``` @@ -459,13 +459,13 @@ pub enum PowerType { } /// 功率物理量结构体 -/// +/// /// 表示单位时间内做功的多少,单位是瓦特 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::Power; -/// +/// /// let power = Power::from_watt(100.0); /// println!("功率: {} W", power.as_watt()); /// ``` @@ -487,13 +487,13 @@ pub enum MagneticAngularVelocityType { } /// 磁角速度物理量结构体 -/// +/// /// 表示磁场中的角速度,单位是特斯拉·弧度/秒或高斯·弧度/秒 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::MagneticAngularVelocity; -/// +/// /// let magnetic_angular_velocity = MagneticAngularVelocity::from_tesla_rad_per_second(1.0); /// println!("磁角速度: {} T·rad/s", magnetic_angular_velocity.as_tesla_rad_per_second()); /// ``` @@ -509,13 +509,13 @@ pub enum VolumeType { KM3, } /// 体积物理量结构体 -/// +/// /// 表示三维空间的体积大小,支持立方米和立方千米单位 -/// +/// /// # 示例 /// ``` /// use zmatrix::physics::basic::Volume; -/// +/// /// let volume = Volume::from_m3(1000.0); /// println!("体积: {} m³", volume.as_m3()); /// ``` @@ -739,23 +739,25 @@ mod tests { assert_eq!(false, e.is_zero()); } - #[test] - fn test_angular_default_unit_value_is_rad() { - // 默认单位为弧度时,default_unit_value 应等于 as_rad() - let a_rad = Angular::from_rad(std::f64::consts::PI); - assert_relative_eq!(a_rad.default_unit_value(), a_rad.as_rad(), epsilon = 1e-12); - - // 默认单位为度时,default_unit_value 也应返回弧度 - let a_deg = Angular::from_deg(180.0); - assert_relative_eq!(a_deg.default_unit_value(), a_deg.as_rad(), epsilon = 1e-12); - - // 随机值覆盖(包括负值和小数),确保统一弧度输出 - let cases = vec![-720.0, -360.0, -45.5, 0.0, 12.34, 90.0, 123.456, 360.0, 720.0]; - for deg in cases { - let a = Angular::from_deg(deg); - assert_relative_eq!(a.default_unit_value(), a.as_rad(), epsilon = 1e-12); - } + #[test] + fn test_angular_default_unit_value_is_rad() { + // 默认单位为弧度时,default_unit_value 应等于 as_rad() + let a_rad = Angular::from_rad(std::f64::consts::PI); + assert_relative_eq!(a_rad.default_unit_value(), a_rad.as_rad(), epsilon = 1e-12); + + // 默认单位为度时,default_unit_value 也应返回弧度 + let a_deg = Angular::from_deg(180.0); + assert_relative_eq!(a_deg.default_unit_value(), a_deg.as_rad(), epsilon = 1e-12); + + // 随机值覆盖(包括负值和小数),确保统一弧度输出 + let cases = vec![ + -720.0, -360.0, -45.5, 0.0, 12.34, 90.0, 123.456, 360.0, 720.0, + ]; + for deg in cases { + let a = Angular::from_deg(deg); + assert_relative_eq!(a.default_unit_value(), a.as_rad(), epsilon = 1e-12); } + } } // 手动实现 VectorQuantity trait 给所有支持向量的物理量 diff --git a/src/physics/basic/vector.rs b/src/physics/basic/vector.rs index c3bdccb..7d31cc5 100644 --- a/src/physics/basic/vector.rs +++ b/src/physics/basic/vector.rs @@ -17,7 +17,26 @@ mod velocity; use super::*; use crate::dense::Matrix; use crate::utils::float; -use std::ops::{Add, Mul, Sub, Neg}; +use std::ops::{Add, Mul, Neg, Sub}; + +// 定义空的 marker trait,用于标记非 Coef 类型 +// 所有实现 NonCoefficient 的类型必须也实现 VectorQuantity +pub trait NonCoefficient: VectorQuantity {} + +// 为各种物理量实现 NonCoefficient trait +impl NonCoefficient for super::Distance {} +impl NonCoefficient for super::Velocity {} +impl NonCoefficient for super::Acceleration {} +impl NonCoefficient for super::Angular {} +impl NonCoefficient for super::AngularVelocity {} +impl NonCoefficient for super::AngularAcceleration {} +impl NonCoefficient for super::AngularMomentum {} +impl NonCoefficient for super::Force {} +impl NonCoefficient for super::MagneticAngularVelocity {} +impl NonCoefficient for super::MagneticInduction {} +impl NonCoefficient for super::MagneticMoment {} +impl NonCoefficient for super::Momentum {} +impl NonCoefficient for super::Torque {} // 将值限制在 [-1, 1] 区间内,供角度计算使用 pub(crate) fn clamp_to_unit_interval(v: f64) -> f64 { @@ -246,6 +265,116 @@ impl + Default> Mul for Vector3< } } +// 实现 Vector3 与 Vector3 的乘法,产生 Vector3 +impl Mul> for Vector3 { + type Output = Vector3; + + fn mul(self, rhs: Vector3) -> Self::Output { + let mut result: Vector3 = Vector3::default(); + result + .x + .set_value(self.x.default_unit_value() * rhs.x.default_unit_value()); + result + .y + .set_value(self.y.default_unit_value() * rhs.y.default_unit_value()); + result + .z + .set_value(self.z.default_unit_value() * rhs.z.default_unit_value()); + result + } +} + +// 实现引用版本的乘法 +impl<'a, 'b, T: VectorQuantity + Default> Mul<&'b Vector3> for &'a Vector3 { + type Output = Vector3; + + fn mul(self, rhs: &'b Vector3) -> Self::Output { + let mut result: Vector3 = Vector3::default(); + result + .x + .set_value(self.x.default_unit_value() * rhs.x.default_unit_value()); + result + .y + .set_value(self.y.default_unit_value() * rhs.y.default_unit_value()); + result + .z + .set_value(self.z.default_unit_value() * rhs.z.default_unit_value()); + result + } +} + +// 实现混合引用版本的乘法 +impl<'a, T: VectorQuantity + Default> Mul> for &'a Vector3 { + type Output = Vector3; + + fn mul(self, rhs: Vector3) -> Self::Output { + let mut result: Vector3 = Vector3::default(); + result + .x + .set_value(self.x.default_unit_value() * rhs.x.default_unit_value()); + result + .y + .set_value(self.y.default_unit_value() * rhs.y.default_unit_value()); + result + .z + .set_value(self.z.default_unit_value() * rhs.z.default_unit_value()); + result + } +} + +impl<'a, T: VectorQuantity + Default> Mul<&'a Vector3> for Vector3 { + type Output = Vector3; + + fn mul(self, rhs: &'a Vector3) -> Self::Output { + let mut result: Vector3 = Vector3::default(); + result + .x + .set_value(rhs.x.default_unit_value() * self.x.default_unit_value()); + result + .y + .set_value(rhs.y.default_unit_value() * self.y.default_unit_value()); + result + .z + .set_value(rhs.z.default_unit_value() * self.z.default_unit_value()); + result + } +} + +// 实现 Vector3 与标量 T 的乘法,产生 Vector3 +// 使用 NonCoefficient trait 来避免与现有 Mul 实现冲突 +impl Mul for Vector3 +where + T: NonCoefficient + Default, +{ + type Output = Vector3; + + fn mul(self, rhs: T) -> Self::Output { + let rhs_value = rhs.default_unit_value(); + let mut result: Vector3 = Vector3::default(); + result.x.set_value(self.x.default_unit_value() * rhs_value); + result.y.set_value(self.y.default_unit_value() * rhs_value); + result.z.set_value(self.z.default_unit_value() * rhs_value); + result + } +} + +// 实现引用版本的标量乘法 +impl<'a, T> Mul for &'a Vector3 +where + T: NonCoefficient + Default, +{ + type Output = Vector3; + + fn mul(self, rhs: T) -> Self::Output { + let rhs_value = rhs.default_unit_value(); + let mut result: Vector3 = Vector3::default(); + result.x.set_value(self.x.default_unit_value() * rhs_value); + result.y.set_value(self.y.default_unit_value() * rhs_value); + result.z.set_value(self.z.default_unit_value() * rhs_value); + result + } +} + impl + Default> Sub for Vector3 { type Output = Vector3; @@ -705,8 +834,6 @@ mod tests { assert_relative_eq!(result.x.get_value(), expected[0], epsilon = 0.00001); assert_relative_eq!(result.y.get_value(), expected[1], epsilon = 0.00001); assert_relative_eq!(result.z.get_value(), expected[2], epsilon = 0.00001); - - } #[test] @@ -1069,9 +1196,9 @@ mod tests { // 测试混合单位的情况 let vec6 = Vector3::new( - Distance::from_m(1000.0), // 1000米 - Distance::from_km(2.0), // 2000米 - Distance::from_m(500.0), // 500米 + Distance::from_m(1000.0), // 1000米 + Distance::from_km(2.0), // 2000米 + Distance::from_m(500.0), // 500米 ); let max_val6 = vec6.max(); assert_relative_eq!(max_val6.as_m(), 2000.0); @@ -1093,4 +1220,121 @@ mod tests { let max_val8 = vec8.max(); assert_relative_eq!(max_val8.as_m_per_sec(), 15.0); } + + #[test] + fn test_vector3_coef_mul_vector_quantity() { + // 测试 Vector3 * Vector3 + let coef_vec = Vector3::new(Coef::new(2.0), Coef::new(3.0), Coef::new(4.0)); + let force_vec = Vector3::new( + Force::from_newton(10.0), + Force::from_newton(20.0), + Force::from_newton(30.0), + ); + let result = coef_vec * force_vec; + assert_relative_eq!(result.x.as_newton(), 20.0); + assert_relative_eq!(result.y.as_newton(), 60.0); + assert_relative_eq!(result.z.as_newton(), 120.0); + + // 测试 &Vector3 * &Vector3 + let coef_vec_ref = &coef_vec; + let force_vec_ref = &force_vec; + let result_ref = coef_vec_ref * force_vec_ref; + assert_relative_eq!(result_ref.x.as_newton(), 20.0); + assert_relative_eq!(result_ref.y.as_newton(), 60.0); + assert_relative_eq!(result_ref.z.as_newton(), 120.0); + + // 测试 &Vector3 * Vector3 + let result_mixed1 = coef_vec_ref * force_vec; + assert_relative_eq!(result_mixed1.x.as_newton(), 20.0); + assert_relative_eq!(result_mixed1.y.as_newton(), 60.0); + assert_relative_eq!(result_mixed1.z.as_newton(), 120.0); + + // 测试 Vector3 * &Vector3 + let result_mixed2 = force_vec * coef_vec_ref; + assert_relative_eq!(result_mixed2.x.as_newton(), 20.0); + assert_relative_eq!(result_mixed2.y.as_newton(), 60.0); + assert_relative_eq!(result_mixed2.z.as_newton(), 120.0); + + // 测试其他物理量类型:Distance + let distance_vec = Vector3::new( + Distance::from_m(5.0), + Distance::from_m(10.0), + Distance::from_m(15.0), + ); + let result_distance = coef_vec * distance_vec; + assert_relative_eq!(result_distance.x.as_m(), 10.0); + assert_relative_eq!(result_distance.y.as_m(), 30.0); + assert_relative_eq!(result_distance.z.as_m(), 60.0); + + // 测试其他物理量类型:Velocity + let velocity_vec = Vector3::new( + Velocity::from_m_per_sec(2.0), + Velocity::from_m_per_sec(4.0), + Velocity::from_m_per_sec(6.0), + ); + let result_velocity = coef_vec * velocity_vec; + assert_relative_eq!(result_velocity.x.as_m_per_sec(), 4.0); + assert_relative_eq!(result_velocity.y.as_m_per_sec(), 12.0); + assert_relative_eq!(result_velocity.z.as_m_per_sec(), 24.0); + + // 测试零值情况 + let zero_coef = Vector3::new(Coef::new(0.0), Coef::new(0.0), Coef::new(0.0)); + let result_zero = zero_coef * force_vec; + assert_relative_eq!(result_zero.x.as_newton(), 0.0); + assert_relative_eq!(result_zero.y.as_newton(), 0.0); + assert_relative_eq!(result_zero.z.as_newton(), 0.0); + + // 测试负系数情况 + let negative_coef = Vector3::new(Coef::new(-1.0), Coef::new(-2.0), Coef::new(-3.0)); + let result_negative = negative_coef * force_vec; + assert_relative_eq!(result_negative.x.as_newton(), -10.0); + assert_relative_eq!(result_negative.y.as_newton(), -40.0); + assert_relative_eq!(result_negative.z.as_newton(), -90.0); + } + + #[test] + fn test_vector3_coef_mul_scalar_quantity() { + // 测试 Vector3 * Force (标量) + let coef_vec = Vector3::new(Coef::new(2.0), Coef::new(3.0), Coef::new(4.0)); + let force_scalar = Force::from_newton(10.0); + let result = coef_vec * force_scalar; + assert_relative_eq!(result.x.as_newton(), 20.0); + assert_relative_eq!(result.y.as_newton(), 30.0); + assert_relative_eq!(result.z.as_newton(), 40.0); + + // 测试 &Vector3 * Force (标量) + let coef_vec_ref = &coef_vec; + let result_ref = coef_vec_ref * force_scalar; + assert_relative_eq!(result_ref.x.as_newton(), 20.0); + assert_relative_eq!(result_ref.y.as_newton(), 30.0); + assert_relative_eq!(result_ref.z.as_newton(), 40.0); + + // 测试其他物理量类型:Distance + let distance_scalar = Distance::from_m(5.0); + let result_distance = coef_vec * distance_scalar; + assert_relative_eq!(result_distance.x.as_m(), 10.0); + assert_relative_eq!(result_distance.y.as_m(), 15.0); + assert_relative_eq!(result_distance.z.as_m(), 20.0); + + // 测试其他物理量类型:Velocity + let velocity_scalar = Velocity::from_m_per_sec(2.0); + let result_velocity = coef_vec * velocity_scalar; + assert_relative_eq!(result_velocity.x.as_m_per_sec(), 4.0); + assert_relative_eq!(result_velocity.y.as_m_per_sec(), 6.0); + assert_relative_eq!(result_velocity.z.as_m_per_sec(), 8.0); + + // 测试零值情况 + let zero_coef = Vector3::new(Coef::new(0.0), Coef::new(0.0), Coef::new(0.0)); + let result_zero = zero_coef * force_scalar; + assert_relative_eq!(result_zero.x.as_newton(), 0.0); + assert_relative_eq!(result_zero.y.as_newton(), 0.0); + assert_relative_eq!(result_zero.z.as_newton(), 0.0); + + // 测试负系数情况 + let negative_coef = Vector3::new(Coef::new(-1.0), Coef::new(-2.0), Coef::new(-3.0)); + let result_negative = negative_coef * force_scalar; + assert_relative_eq!(result_negative.x.as_newton(), -10.0); + assert_relative_eq!(result_negative.y.as_newton(), -20.0); + assert_relative_eq!(result_negative.z.as_newton(), -30.0); + } } From 68c9efc10151d4f578af9241f341fb0038bcb30b Mon Sep 17 00:00:00 2001 From: Treagzhao <920866163@qq.com> Date: Tue, 10 Mar 2026 09:46:35 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=96=B0=E5=A2=9Efrom=5Farray=5Fwith=5Funi?= =?UTF-8?q?t=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.txt | 608 +++++++++--------- src/physics/basic/vector.rs | 1 - src/physics/basic/vector/acceleration.rs | 17 + src/physics/basic/vector/angular.rs | 17 + .../basic/vector/angular_acceleration.rs | 17 + src/physics/basic/vector/angular_momentum.rs | 17 + src/physics/basic/vector/angular_velocity.rs | 17 + src/physics/basic/vector/distance.rs | 17 + src/physics/basic/vector/force.rs | 48 ++ .../basic/vector/magnetic_angular_velocity.rs | 44 ++ .../basic/vector/magnetic_induction.rs | 35 +- src/physics/basic/vector/magnetic_moment.rs | 62 ++ .../basic/vector/megnetic_induction.rs | 132 ---- src/physics/basic/vector/momentum.rs | 17 + src/physics/basic/vector/torque.rs | 48 ++ src/physics/basic/vector/velocity.rs | 17 + 16 files changed, 676 insertions(+), 438 deletions(-) delete mode 100644 src/physics/basic/vector/megnetic_induction.rs diff --git a/1.txt b/1.txt index 2b1050b..9ba472e 100644 --- a/1.txt +++ b/1.txt @@ -31,6 +31,12 @@ warning: unused import: `array_init::array_init` 3 | use array_init::array_init; | ^^^^^^^^^^^^^^^^^^^^^^ +warning: unused import: `rayon::prelude::*` + --> src/dense/operation.rs:5:5 + | +5 | use rayon::prelude::*; + | ^^^^^^^^^^^^^^^^^ + warning: unused imports: `Arc` and `mpsc` --> src/dense/operation.rs:9:17 | @@ -109,17 +115,35 @@ warning: unused imports: `Acceleration`, `Mass`, and `Velocity` 2 | Acceleration, Coef, Distance, Energy, EnergyType, Force, Mass, PhysicalQuantity, Velocity, | ^^^^^^^^^^^^ ^^^^ ^^^^^^^^ +warning: unused import: `approx::assert_relative_eq` + --> src/physics/basic/energy.rs:4:5 + | +4 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `approx::assert_relative_eq` + --> src/physics/basic/force.rs:4:5 + | +4 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + warning: unused import: `approx::assert_relative_eq` --> src/physics/basic/magnetic_angular_velocity.rs:4:5 | 4 | use approx::assert_relative_eq; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: unused import: `Area` - --> src/physics/basic/magnetic_moment.rs:342:52 - | -342 | use crate::physics::basic::{MagneticInduction, Area}; - | ^^^^ +warning: unused import: `approx::assert_relative_eq` + --> src/physics/basic/magnetic_moment.rs:4:5 + | +4 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `approx::assert_relative_eq` + --> src/physics/basic/mass.rs:4:5 + | +4 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: unused imports: `AngularMomentumType`, `MassType`, and `Mass` --> src/physics/basic/momentum.rs:3:46 @@ -127,13 +151,17 @@ warning: unused imports: `AngularMomentumType`, `MassType`, and `Mass` 3 | use crate::physics::basic::{AngularMomentum, AngularMomentumType, Coef, Distance, Mass, MassType, Momentum, MomentumType, PhysicalQuantity}; | ^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^ -warning: duplicated attribute - --> src/physics/basic/vector/angular_velocity.rs:78:5 - | -78 | #[test] - | ^^^^^^^ - | - = note: `#[warn(duplicate_macro_attributes)]` on by default +warning: unused import: `approx::assert_relative_eq` + --> src/physics/basic/power.rs:4:5 + | +4 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `approx::assert_relative_eq` + --> src/physics/basic/torque.rs:4:5 + | +4 | use approx::assert_relative_eq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: unused import: `Mass` --> src/physics/basic/vector/distance.rs:2:52 @@ -141,16 +169,22 @@ warning: unused import: `Mass` 2 | AngularMomentum, Coef, Distance, DistanceType, Mass, Momentum, Vector3, Velocity, | ^^^^ +warning: unused import: `super::*` + --> src/physics/basic/vector/magnetic_angular_velocity.rs:1:5 + | +1 | use super::*; + | ^^^^^^^^ + warning: unused import: `Div` - --> src/physics/basic/vector/megnetic_induction.rs:1:16 + --> src/physics/basic/vector/magnetic_induction.rs:1:16 | 1 | use std::ops::{Div, Mul}; | ^^^ warning: unused import: `crate::utils::float` - --> src/physics/basic/vector.rs:19:5 + --> src/physics/basic/vector.rs:18:5 | -19 | use crate::utils::float; +18 | use crate::utils::float; | ^^^^^^^^^^^^^^^^^^^ warning: unused import: `crate::physics::basic::VelocityType::LightSpeed` @@ -159,12 +193,6 @@ warning: unused import: `crate::physics::basic::VelocityType::LightSpeed` 3 | use crate::physics::basic::VelocityType::LightSpeed; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: unused import: `std::any::TypeId` - --> src/physics/basic/velocity.rs:318:9 - | -318 | use std::any::TypeId; - | ^^^^^^^^^^^^^^^^ - warning: unused import: `DistanceType` --> src/physics/basic/volume.rs:3:51 | @@ -197,29 +225,17 @@ warning: unused import: `super::*` 1 | use super::*; | ^^^^^^^^ -warning: duplicated attribute - --> src/utils/float.rs:51:5 - | -51 | #[test] - | ^^^^^^^ - -warning: unused import: `PhysicalQuantity` - --> src/spatial_geometry/cos_matrix.rs:4:44 - | -4 | use crate::physics::basic::{Angular, Coef, PhysicalQuantity, Vector3, VectorQuantity}; - | ^^^^^^^^^^^^^^^^ - warning: unused import: `rayon::iter::ParallelIterator` --> src/dense/operation.rs:4:5 | 4 | use rayon::iter::ParallelIterator; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: unused import: `rayon::prelude` - --> src/dense/operation.rs:5:5 +warning: unused import: `PhysicalQuantity` + --> src/spatial_geometry/cos_matrix.rs:4:44 | -5 | use rayon::prelude::*; - | ^^^^^^^^^^^^^^ +4 | use crate::physics::basic::{Angular, Coef, PhysicalQuantity, Vector3, VectorQuantity}; + | ^^^^^^^^^^^^^^^^ warning: unused import: `rayon::iter::ParallelIterator` --> src/dense/shape.rs:3:5 @@ -227,26 +243,6 @@ warning: unused import: `rayon::iter::ParallelIterator` 3 | use rayon::iter::ParallelIterator; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: unused variable: `expected` - --> src/dense/operation.rs:518:13 - | -518 | let expected: [i32; 0] = []; - | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_expected` - | - = note: `#[warn(unused_variables)]` on by default - -warning: unused variable: `result` - --> src/dense/operation.rs:870:13 - | -870 | let result = matrix.clamp(3.0, 2.0); - | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` - -warning: unused variable: `data` - --> src/dense/shape.rs:185:13 - | -185 | let data = (1..=100).collect::>(); - | ^^^^ help: if this is intentional, prefix it with an underscore: `_data` - warning: value assigned to `ceof` is never read --> src/dense/util.rs:122:13 | @@ -261,12 +257,8 @@ warning: unused variable: `key` | 128 | let key = print_permutation(permutation); | ^^^ help: if this is intentional, prefix it with an underscore: `_key` - -warning: unused variable: `vec` - --> src/dense/util.rs:286:19 | -286 | if let Ok(vec) = res { - | ^^^ help: if this is intentional, prefix it with an underscore: `_vec` + = note: `#[warn(unused_variables)]` on by default warning: variable does not need to be mutable --> src/dense.rs:25:13 @@ -278,84 +270,6 @@ warning: variable does not need to be mutable | = note: `#[warn(unused_mut)]` on by default -warning: unused variable: `d2` - --> src/physics/basic/acceleration.rs:378:13 - | -378 | let d2 = d1.as_any().downcast_ref::().unwrap(); - | ^^ help: if this is intentional, prefix it with an underscore: `_d2` - -warning: unused variable: `d2` - --> src/physics/basic/angular_acceleration.rs:371:13 - | -371 | let d2 = dw.downcast_ref::().unwrap(); - | ^^ help: if this is intentional, prefix it with an underscore: `_d2` - -warning: unused variable: `d3` - --> src/physics/basic/angular_velocity.rs:506:13 - | -506 | let d3 = d2.downcast_ref::().unwrap(); - | ^^ help: if this is intentional, prefix it with an underscore: `_d3` - -warning: unused variable: `a` - --> src/physics/basic/area.rs:444:13 - | -444 | let a: &Area = any.downcast_ref::().unwrap(); - | ^ help: if this is intentional, prefix it with an underscore: `_a` - -warning: unused variable: `c` - --> src/physics/basic/coef.rs:379:13 - | -379 | let c = result.downcast_ref::().unwrap(); - | ^ help: if this is intentional, prefix it with an underscore: `_c` - -warning: unused variable: `result` - --> src/physics/basic/magnetic_induction.rs:372:13 - | -372 | let result = convert_gauss_value(1.0, MagneticInductionType::Tesla, MagneticInductionType::KiloGauss).unwrap(); - | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` - -warning: unused variable: `result` - --> src/physics/basic/magnetic_induction.rs:378:13 - | -378 | let result = convert_gauss_value(1.0, MagneticInductionType::KiloGauss, MagneticInductionType::Tesla).unwrap(); - | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` - -warning: unused variable: `result` - --> src/physics/basic/magnetic_induction.rs:400:13 - | -400 | let result = convert_tesla_value(1.0, MagneticInductionType::Tesla, MagneticInductionType::KiloGauss).unwrap(); - | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` - -warning: unused variable: `result` - --> src/physics/basic/magnetic_induction.rs:406:13 - | -406 | let result = convert_tesla_value(1.0, MagneticInductionType::KiloGauss, MagneticInductionType::Tesla).unwrap(); - | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` - -warning: unused variable: `a` - --> src/physics/basic/magnetic_induction.rs:464:13 - | -464 | let a = any.downcast_ref::().unwrap(); - | ^ help: if this is intentional, prefix it with an underscore: `_a` - -warning: unused variable: `m2` - --> src/physics/basic/mass.rs:215:13 - | -215 | let m2 = m1.as_g(); - | ^^ help: if this is intentional, prefix it with an underscore: `_m2` - -warning: unused variable: `p_zero` - --> src/physics/basic/power.rs:876:13 - | -876 | let p_zero = Power::from_watt(0.0); - | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_p_zero` - -warning: unused variable: `unit_name` - --> src/physics/basic/power.rs:895:21 - | -895 | for (power, unit_name) in units { - | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unit_name` - warning: variable does not need to be mutable --> src/physics/basic/vector/angular.rs:102:13 | @@ -372,62 +286,6 @@ warning: variable does not need to be mutable | | | help: remove this `mut` -warning: unused variable: `ti` - --> src/physics/basic/vector/angular.rs:1069:14 - | -1069 | let (ti, tj, tk) = (1u8, 2u8, 3u8); // 这里与上面 seq 一致为 Y(2) Z(3) X(1)? 修正如下: - | ^^ help: if this is intentional, prefix it with an underscore: `_ti` - -warning: unused variable: `tj` - --> src/physics/basic/vector/angular.rs:1069:18 - | -1069 | let (ti, tj, tk) = (1u8, 2u8, 3u8); // 这里与上面 seq 一致为 Y(2) Z(3) X(1)? 修正如下: - | ^^ help: if this is intentional, prefix it with an underscore: `_tj` - -warning: unused variable: `tk` - --> src/physics/basic/vector/angular.rs:1069:22 - | -1069 | let (ti, tj, tk) = (1u8, 2u8, 3u8); // 这里与上面 seq 一致为 Y(2) Z(3) X(1)? 修正如下: - | ^^ help: if this is intentional, prefix it with an underscore: `_tk` - -warning: unused variable: `input` - --> src/physics/basic/vector.rs:734:17 - | -734 | let mut input = [1f32, 4f32, 9f32]; - | ^^^^^ help: if this is intentional, prefix it with an underscore: `_input` - -warning: variable does not need to be mutable - --> src/physics/basic/vector.rs:734:13 - | -734 | let mut input = [1f32, 4f32, 9f32]; - | ----^^^^^ - | | - | help: remove this `mut` - -warning: unused variable: `a` - --> src/physics/basic/velocity.rs:498:13 - | -498 | let a = v_any.downcast_ref::().unwrap(); - | ^ help: if this is intentional, prefix it with an underscore: `_a` - -warning: unused variable: `v` - --> src/physics/basic/volume.rs:254:13 - | -254 | let v = b.as_any().downcast_ref::().unwrap(); - | ^ help: if this is intentional, prefix it with an underscore: `_v` - -warning: unused variable: `d` - --> src/physics/basic.rs:615:13 - | -615 | let d = g.as_any().downcast_ref::().unwrap(); - | ^ help: if this is intentional, prefix it with an underscore: `_d` - -warning: unused variable: `d` - --> src/physics/basic.rs:618:13 - | -618 | let d = g.as_any().downcast_ref::().unwrap(); - | ^ help: if this is intentional, prefix it with an underscore: `_d` - warning: value assigned to `x` is never read --> src/spatial_geometry/cos_matrix.rs:485:17 | @@ -448,18 +306,36 @@ warning: field `digits` is never read = note: `Matrix` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis = note: `#[warn(dead_code)]` on by default +warning: struct `CalculateResult` is never constructed + --> src/dense/util.rs:8:12 + | +8 | pub struct CalculateResult + | ^^^^^^^^^^^^^^^ + +warning: function `convert_to_f64` is never used + --> src/dense/util.rs:17:8 + | +17 | pub fn convert_to_f64(value: T) -> Result + | ^^^^^^^^^^^^^^ + +warning: function `calculate_in_threads` is never used + --> src/dense/util.rs:60:8 + | +60 | pub fn calculate_in_threads<'a, const ROWS: usize, const COLS: usize, T, F>( + | ^^^^^^^^^^^^^^^^^^^^ + +warning: function `calculate_multi` is never used + --> src/dense/util.rs:93:8 + | +93 | pub fn calculate_multi( + | ^^^^^^^^^^^^^^^ + warning: constant `LIGHT_SPEED` is never used --> src/physics/basic/distance.rs:5:7 | 5 | const LIGHT_SPEED: f64 = 299792458.0; | ^^^^^^^^^^^ -warning: function `test_norm_square_basic` is never used - --> src/physics/basic/vector.rs:1058:8 - | -1058 | fn test_norm_square_basic() { - | ^^^^^^^^^^^^^^^^^^^^^^ - warning: method `T` should have a snake case name --> src/dense/shape.rs:26:12 | @@ -468,100 +344,33 @@ warning: method `T` should have a snake case name | = note: `#[warn(non_snake_case)]` on by default -warning: function `test_T` should have a snake case name - --> src/dense/shape.rs:110:8 - | -110 | fn test_T() { - | ^^^^^^ help: convert the identifier to snake case: `test_t` - -warning: variable `delta_B` should have a snake case name - --> src/physics/basic/vector/magnetic_angular_velocity.rs:1578:13 - | -1578 | let delta_B = b - b_prev; - | ^^^^^^^ help: convert the identifier to snake case: `delta_b` - -warning: `zmatrix` (lib test) generated 75 warnings (run `cargo fix --lib -p zmatrix --tests` to apply 34 suggestions) -warning: unused import: `rayon::prelude::*` - --> src/dense/operation.rs:5:5 - | -5 | use rayon::prelude::*; - | ^^^^^^^^^^^^^^^^^ - -warning: unused import: `approx::assert_relative_eq` - --> src/physics/basic/energy.rs:4:5 - | -4 | use approx::assert_relative_eq; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -warning: unused import: `approx::assert_relative_eq` - --> src/physics/basic/force.rs:4:5 - | -4 | use approx::assert_relative_eq; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -warning: unused import: `approx::assert_relative_eq` - --> src/physics/basic/magnetic_moment.rs:4:5 - | -4 | use approx::assert_relative_eq; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -warning: unused import: `approx::assert_relative_eq` - --> src/physics/basic/mass.rs:4:5 - | -4 | use approx::assert_relative_eq; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -warning: unused import: `approx::assert_relative_eq` - --> src/physics/basic/power.rs:4:5 - | -4 | use approx::assert_relative_eq; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -warning: unused import: `approx::assert_relative_eq` - --> src/physics/basic/torque.rs:4:5 - | -4 | use approx::assert_relative_eq; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -warning: unused import: `super::*` - --> src/physics/basic/vector/magnetic_angular_velocity.rs:1:5 - | -1 | use super::*; - | ^^^^^^^^ - -warning: unused variable: `key` - --> src/dense/util.rs:128:9 - | -128 | let key = print_permutation(permutation); - | ^^^ help: if this is intentional, prefix it with an underscore: `_key` +warning: `zmatrix` (lib) generated 53 warnings (run `cargo fix --lib -p zmatrix` to apply 39 suggestions) +warning: unused import: `Area` + --> src/physics/basic/magnetic_moment.rs:342:52 | - = note: `#[warn(unused_variables)]` on by default - -warning: struct `CalculateResult` is never constructed - --> src/dense/util.rs:8:12 - | -8 | pub struct CalculateResult - | ^^^^^^^^^^^^^^^ +342 | use crate::physics::basic::{MagneticInduction, Area}; + | ^^^^ -warning: function `convert_to_f64` is never used - --> src/dense/util.rs:17:8 +warning: duplicated attribute + --> src/physics/basic/vector/angular_velocity.rs:95:5 | -17 | pub fn convert_to_f64(value: T) -> Result - | ^^^^^^^^^^^^^^ - -warning: function `calculate_in_threads` is never used - --> src/dense/util.rs:60:8 +95 | #[test] + | ^^^^^^^ | -60 | pub fn calculate_in_threads<'a, const ROWS: usize, const COLS: usize, T, F>( - | ^^^^^^^^^^^^^^^^^^^^ + = note: `#[warn(duplicate_macro_attributes)]` on by default -warning: function `calculate_multi` is never used - --> src/dense/util.rs:93:8 +warning: unused import: `std::any::TypeId` + --> src/physics/basic/velocity.rs:318:9 + | +318 | use std::any::TypeId; + | ^^^^^^^^^^^^^^^^ + +warning: duplicated attribute + --> src/utils/float.rs:51:5 | -93 | pub fn calculate_multi( - | ^^^^^^^^^^^^^^^ +51 | #[test] + | ^^^^^^^ -warning: `zmatrix` (lib) generated 53 warnings (40 duplicates) (run `cargo fix --lib -p zmatrix` to apply 8 suggestions) warning: unused import: `Energy` --> examples/example_magnetic_moment.rs:1:66 | @@ -570,11 +379,11 @@ warning: unused import: `Energy` | = note: `#[warn(unused_imports)]` on by default -warning: unused imports: `Energy`, `MagneticInduction`, `Mass`, `Power`, `Torque`, `VectorQuantity`, and `Volume` - --> examples/example_vector_quantity_restriction.rs:1:31 +warning: unused import: `Acceleration` + --> examples/example_energy.rs:1:65 | -1 | use zmatrix::physics::basic::{VectorQuantity, Distance, Velocity, Force, Torque, MagneticInduction, Vector3, Mass, Energy, Power, Volume}; - | ^^^^^^^^^^^^^^ ^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^ ^^^^^ ^^^^^^ +1 | use zmatrix::physics::basic::{Energy, Distance, Mass, Velocity, Acceleration, PhysicalQuantity}; + | ^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default @@ -598,14 +407,6 @@ warning: unused variable: `area` 28 | let area:Area = dis * dis; | ^^^^ help: if this is intentional, prefix it with an underscore: `_area` -warning: unused import: `Acceleration` - --> examples/example_energy.rs:1:65 - | -1 | use zmatrix::physics::basic::{Energy, Distance, Mass, Velocity, Acceleration, PhysicalQuantity}; - | ^^^^^^^^^^^^ - | - = note: `#[warn(unused_imports)]` on by default - warning: unused variable: `pos_vector` --> examples/example_physics.rs:33:9 | @@ -649,9 +450,8 @@ help: use `let _ = ...` to ignore the resulting value warning: `zmatrix` (example "example_magnetic_moment") generated 1 warning (run `cargo fix --example "example_magnetic_moment"` to apply 1 suggestion) warning: `zmatrix` (example "example_physics") generated 6 warnings -warning: `zmatrix` (example "example_vector_quantity_restriction") generated 1 warning (run `cargo fix --example "example_vector_quantity_restriction"` to apply 1 suggestion) -warning: `zmatrix` (example "example_energy") generated 1 warning (run `cargo fix --example "example_energy"` to apply 1 suggestion) warning: `zmatrix` (example "examples_dense") generated 2 warnings (run `cargo fix --example "examples_dense"` to apply 1 suggestion) +warning: `zmatrix` (example "example_energy") generated 1 warning (run `cargo fix --example "example_energy"` to apply 1 suggestion) warning: unused import: `Energy` --> examples/example_torque.rs:1:49 | @@ -660,8 +460,208 @@ warning: unused import: `Energy` | = note: `#[warn(unused_imports)]` on by default +warning: unused imports: `Energy`, `MagneticInduction`, `Mass`, `Power`, `Torque`, `VectorQuantity`, and `Volume` + --> examples/example_vector_quantity_restriction.rs:1:31 + | +1 | use zmatrix::physics::basic::{VectorQuantity, Distance, Velocity, Force, Torque, MagneticInduction, Vector3, Mass, Energy, Power, Volume}; + | ^^^^^^^^^^^^^^ ^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^ ^^^^^ ^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: `zmatrix` (example "example_vector_quantity_restriction") generated 1 warning (run `cargo fix --example "example_vector_quantity_restriction"` to apply 1 suggestion) warning: `zmatrix` (example "example_torque") generated 1 warning (run `cargo fix --example "example_torque"` to apply 1 suggestion) - Finished `test` profile [unoptimized + debuginfo] target(s) in 0.85s +warning: unused import: `rayon::prelude` + --> src/dense/operation.rs:5:5 + | +5 | use rayon::prelude::*; + | ^^^^^^^^^^^^^^ + +warning: unused variable: `expected` + --> src/dense/operation.rs:518:13 + | +518 | let expected: [i32; 0] = []; + | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_expected` + | + = note: `#[warn(unused_variables)]` on by default + +warning: unused variable: `result` + --> src/dense/operation.rs:870:13 + | +870 | let result = matrix.clamp(3.0, 2.0); + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` + +warning: unused variable: `data` + --> src/dense/shape.rs:185:13 + | +185 | let data = (1..=100).collect::>(); + | ^^^^ help: if this is intentional, prefix it with an underscore: `_data` + +warning: unused variable: `key` + --> src/dense/util.rs:128:9 + | +128 | let key = print_permutation(permutation); + | ^^^ help: if this is intentional, prefix it with an underscore: `_key` + +warning: unused variable: `vec` + --> src/dense/util.rs:286:19 + | +286 | if let Ok(vec) = res { + | ^^^ help: if this is intentional, prefix it with an underscore: `_vec` + +warning: unused variable: `d2` + --> src/physics/basic/acceleration.rs:378:13 + | +378 | let d2 = d1.as_any().downcast_ref::().unwrap(); + | ^^ help: if this is intentional, prefix it with an underscore: `_d2` + +warning: unused variable: `d2` + --> src/physics/basic/angular_acceleration.rs:371:13 + | +371 | let d2 = dw.downcast_ref::().unwrap(); + | ^^ help: if this is intentional, prefix it with an underscore: `_d2` + +warning: unused variable: `d3` + --> src/physics/basic/angular_velocity.rs:506:13 + | +506 | let d3 = d2.downcast_ref::().unwrap(); + | ^^ help: if this is intentional, prefix it with an underscore: `_d3` + +warning: unused variable: `a` + --> src/physics/basic/area.rs:444:13 + | +444 | let a: &Area = any.downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_a` + +warning: unused variable: `c` + --> src/physics/basic/coef.rs:379:13 + | +379 | let c = result.downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_c` + +warning: unused variable: `result` + --> src/physics/basic/magnetic_induction.rs:372:13 + | +372 | let result = convert_gauss_value(1.0, MagneticInductionType::Tesla, MagneticInductionType::KiloGauss).unwrap(); + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` + +warning: unused variable: `result` + --> src/physics/basic/magnetic_induction.rs:378:13 + | +378 | let result = convert_gauss_value(1.0, MagneticInductionType::KiloGauss, MagneticInductionType::Tesla).unwrap(); + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` + +warning: unused variable: `result` + --> src/physics/basic/magnetic_induction.rs:400:13 + | +400 | let result = convert_tesla_value(1.0, MagneticInductionType::Tesla, MagneticInductionType::KiloGauss).unwrap(); + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` + +warning: unused variable: `result` + --> src/physics/basic/magnetic_induction.rs:406:13 + | +406 | let result = convert_tesla_value(1.0, MagneticInductionType::KiloGauss, MagneticInductionType::Tesla).unwrap(); + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_result` + +warning: unused variable: `a` + --> src/physics/basic/magnetic_induction.rs:464:13 + | +464 | let a = any.downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_a` + +warning: unused variable: `m2` + --> src/physics/basic/mass.rs:215:13 + | +215 | let m2 = m1.as_g(); + | ^^ help: if this is intentional, prefix it with an underscore: `_m2` + +warning: unused variable: `p_zero` + --> src/physics/basic/power.rs:876:13 + | +876 | let p_zero = Power::from_watt(0.0); + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_p_zero` + +warning: unused variable: `unit_name` + --> src/physics/basic/power.rs:895:21 + | +895 | for (power, unit_name) in units { + | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unit_name` + +warning: unused variable: `ti` + --> src/physics/basic/vector/angular.rs:1086:14 + | +1086 | let (ti, tj, tk) = (1u8, 2u8, 3u8); // 这里与上面 seq 一致为 Y(2) Z(3) X(1)? 修正如下: + | ^^ help: if this is intentional, prefix it with an underscore: `_ti` + +warning: unused variable: `tj` + --> src/physics/basic/vector/angular.rs:1086:18 + | +1086 | let (ti, tj, tk) = (1u8, 2u8, 3u8); // 这里与上面 seq 一致为 Y(2) Z(3) X(1)? 修正如下: + | ^^ help: if this is intentional, prefix it with an underscore: `_tj` + +warning: unused variable: `tk` + --> src/physics/basic/vector/angular.rs:1086:22 + | +1086 | let (ti, tj, tk) = (1u8, 2u8, 3u8); // 这里与上面 seq 一致为 Y(2) Z(3) X(1)? 修正如下: + | ^^ help: if this is intentional, prefix it with an underscore: `_tk` + +warning: unused variable: `input` + --> src/physics/basic/vector.rs:733:17 + | +733 | let mut input = [1f32, 4f32, 9f32]; + | ^^^^^ help: if this is intentional, prefix it with an underscore: `_input` + +warning: variable does not need to be mutable + --> src/physics/basic/vector.rs:733:13 + | +733 | let mut input = [1f32, 4f32, 9f32]; + | ----^^^^^ + | | + | help: remove this `mut` + +warning: unused variable: `a` + --> src/physics/basic/velocity.rs:498:13 + | +498 | let a = v_any.downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_a` + +warning: unused variable: `v` + --> src/physics/basic/volume.rs:254:13 + | +254 | let v = b.as_any().downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_v` + +warning: unused variable: `d` + --> src/physics/basic.rs:615:13 + | +615 | let d = g.as_any().downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_d` + +warning: unused variable: `d` + --> src/physics/basic.rs:618:13 + | +618 | let d = g.as_any().downcast_ref::().unwrap(); + | ^ help: if this is intentional, prefix it with an underscore: `_d` + +warning: function `test_norm_square_basic` is never used + --> src/physics/basic/vector.rs:1057:8 + | +1057 | fn test_norm_square_basic() { + | ^^^^^^^^^^^^^^^^^^^^^^ + +warning: function `test_T` should have a snake case name + --> src/dense/shape.rs:110:8 + | +110 | fn test_T() { + | ^^^^^^ help: convert the identifier to snake case: `test_t` + +warning: variable `delta_B` should have a snake case name + --> src/physics/basic/vector/magnetic_angular_velocity.rs:1622:13 + | +1622 | let delta_B = b - b_prev; + | ^^^^^^^ help: convert the identifier to snake case: `delta_b` + +warning: `zmatrix` (lib test) generated 75 warnings (40 duplicates) (run `cargo fix --lib -p zmatrix --tests` to apply 3 suggestions) + Finished `test` profile [unoptimized + debuginfo] target(s) in 1.80s Running unittests src/lib.rs (target/debug/deps/zmatrix-0317ef656e62916a) Doc-tests zmatrix warning: variant `g` should have an upper camel case name diff --git a/src/physics/basic/vector.rs b/src/physics/basic/vector.rs index 7d31cc5..602ab4d 100644 --- a/src/physics/basic/vector.rs +++ b/src/physics/basic/vector.rs @@ -9,7 +9,6 @@ mod force; mod magnetic_angular_velocity; mod magnetic_induction; mod magnetic_moment; -mod megnetic_induction; mod momentum; mod torque; mod velocity; diff --git a/src/physics/basic/vector/acceleration.rs b/src/physics/basic/vector/acceleration.rs index 7d68fb1..720ba86 100644 --- a/src/physics/basic/vector/acceleration.rs +++ b/src/physics/basic/vector/acceleration.rs @@ -33,6 +33,23 @@ impl Vector3 { }; Vector3::new(x, y, z) } + + pub fn from_array_with_unit(array: [f64; 3], acceleration_type: AccelerationType) -> Vector3 { + let [x, y, z] = array; + let x = Acceleration { + v: x, + default_type: acceleration_type, + }; + let y = Acceleration { + v: y, + default_type: acceleration_type, + }; + let z = Acceleration { + v: z, + default_type: acceleration_type, + }; + Vector3::new(x, y, z) + } } #[cfg(test)] diff --git a/src/physics/basic/vector/angular.rs b/src/physics/basic/vector/angular.rs index 8ea3805..09002cb 100644 --- a/src/physics/basic/vector/angular.rs +++ b/src/physics/basic/vector/angular.rs @@ -145,6 +145,23 @@ impl Vector3 { Vector3::new(x, y, z) } + pub fn from_array_with_unit(array: [f64; 3], angular_type: AngularType) -> Vector3 { + let [x, y, z] = array; + let x = Angular { + v: x, + default_type: angular_type, + }; + let y = Angular { + v: y, + default_type: angular_type, + }; + let z = Angular { + v: z, + default_type: angular_type, + }; + Vector3::new(x, y, z) + } + pub fn to_cos_matrix( &self, seq: RotationSeq, diff --git a/src/physics/basic/vector/angular_acceleration.rs b/src/physics/basic/vector/angular_acceleration.rs index cb641c1..ab97f87 100644 --- a/src/physics/basic/vector/angular_acceleration.rs +++ b/src/physics/basic/vector/angular_acceleration.rs @@ -34,6 +34,23 @@ impl Vector3 { }; Vector3::new(x, y, z) } + + pub fn from_array_with_unit(array: [f64; 3], angular_acceleration_type: AngularAccelerationType) -> Vector3 { + let [x, y, z] = array; + let x = AngularAcceleration { + v: x, + default_type: angular_acceleration_type, + }; + let y = AngularAcceleration { + v: y, + default_type: angular_acceleration_type, + }; + let z = AngularAcceleration { + v: z, + default_type: angular_acceleration_type, + }; + Vector3::new(x, y, z) + } } #[cfg(test)] diff --git a/src/physics/basic/vector/angular_momentum.rs b/src/physics/basic/vector/angular_momentum.rs index b646646..834f09b 100644 --- a/src/physics/basic/vector/angular_momentum.rs +++ b/src/physics/basic/vector/angular_momentum.rs @@ -45,6 +45,23 @@ impl Vector3 { }; Vector3::new(x, y, z) } + + pub fn from_array_with_unit(array: [f64; 3], angular_momentum_type: AngularMomentumType) -> Vector3 { + let [x, y, z] = array; + let x = AngularMomentum { + v: x, + default_type: angular_momentum_type, + }; + let y = AngularMomentum { + v: y, + default_type: angular_momentum_type, + }; + let z = AngularMomentum { + v: z, + default_type: angular_momentum_type, + }; + Vector3::new(x, y, z) + } } #[cfg(test)] diff --git a/src/physics/basic/vector/angular_velocity.rs b/src/physics/basic/vector/angular_velocity.rs index 7886fee..8c5ce8f 100644 --- a/src/physics/basic/vector/angular_velocity.rs +++ b/src/physics/basic/vector/angular_velocity.rs @@ -57,6 +57,23 @@ impl Vector3 { }; Vector3::new(x, y, z) } + + pub fn from_array_with_unit(array: [f64; 3], angular_velocity_type: AngularVelocityType) -> Vector3 { + let [x, y, z] = array; + let x = AngularVelocity { + v: x, + default_type: angular_velocity_type, + }; + let y = AngularVelocity { + v: y, + default_type: angular_velocity_type, + }; + let z = AngularVelocity { + v: z, + default_type: angular_velocity_type, + }; + Vector3::new(x, y, z) + } } impl Mul for Vector3 { diff --git a/src/physics/basic/vector/distance.rs b/src/physics/basic/vector/distance.rs index 0310007..581c67f 100644 --- a/src/physics/basic/vector/distance.rs +++ b/src/physics/basic/vector/distance.rs @@ -62,6 +62,23 @@ impl Vector3 { }; Vector3::new(x, y, z) } + + pub fn from_array_with_unit(array: [f64; 3], distance_type: DistanceType) -> Vector3 { + let [x, y, z] = array; + let x = Distance { + v: x, + default_type: distance_type, + }; + let y = Distance { + v: y, + default_type: distance_type, + }; + let z = Distance { + v: z, + default_type: distance_type, + }; + Vector3::new(x, y, z) + } } #[cfg(test)] diff --git a/src/physics/basic/vector/force.rs b/src/physics/basic/vector/force.rs index 2127f75..331f973 100644 --- a/src/physics/basic/vector/force.rs +++ b/src/physics/basic/vector/force.rs @@ -79,6 +79,54 @@ impl Vector3 { } } } + + pub fn from_array_with_unit(array: [f64; 3], force_type: ForceType) -> Vector3 { + let [x, y, z] = array; + match force_type { + ForceType::Newton => { + Vector3::new( + Force::from_newton(x), + Force::from_newton(y), + Force::from_newton(z), + ) + } + ForceType::MillNewton => { + Vector3::new( + Force::from_mill_newton(x), + Force::from_mill_newton(y), + Force::from_mill_newton(z), + ) + } + ForceType::MicroNewton => { + Vector3::new( + Force::from_micro_newton(x), + Force::from_micro_newton(y), + Force::from_micro_newton(z), + ) + } + ForceType::NanoNewton => { + Vector3::new( + Force::from_nano_newton(x), + Force::from_nano_newton(y), + Force::from_nano_newton(z), + ) + } + ForceType::KiloNewton => { + Vector3::new( + Force::from_kilo_newton(x), + Force::from_kilo_newton(y), + Force::from_kilo_newton(z), + ) + } + ForceType::MegaNewton => { + Vector3::new( + Force::from_mega_newton(x), + Force::from_mega_newton(y), + Force::from_mega_newton(z), + ) + } + } + } } #[cfg(test)] diff --git a/src/physics/basic/vector/magnetic_angular_velocity.rs b/src/physics/basic/vector/magnetic_angular_velocity.rs index b37e1b4..9449728 100644 --- a/src/physics/basic/vector/magnetic_angular_velocity.rs +++ b/src/physics/basic/vector/magnetic_angular_velocity.rs @@ -114,6 +114,50 @@ impl Vector3 { } } + pub fn from_array_with_unit( + array: [f64; 3], + magnetic_angular_velocity_type: MagneticAngularVelocityType, + ) -> Vector3 { + let [x, y, z] = array; + match magnetic_angular_velocity_type { + MagneticAngularVelocityType::TeslaRadPerSecond => Vector3::new( + MagneticAngularVelocity::from_tesla_rad_per_second(x), + MagneticAngularVelocity::from_tesla_rad_per_second(y), + MagneticAngularVelocity::from_tesla_rad_per_second(z), + ), + MagneticAngularVelocityType::MillTeslaRadPerSecond => Vector3::new( + MagneticAngularVelocity::from_mill_tesla_rad_per_second(x), + MagneticAngularVelocity::from_mill_tesla_rad_per_second(y), + MagneticAngularVelocity::from_mill_tesla_rad_per_second(z), + ), + MagneticAngularVelocityType::MicroTeslaRadPerSecond => Vector3::new( + MagneticAngularVelocity::from_micro_tesla_rad_per_second(x), + MagneticAngularVelocity::from_micro_tesla_rad_per_second(y), + MagneticAngularVelocity::from_micro_tesla_rad_per_second(z), + ), + MagneticAngularVelocityType::NanoTeslaRadPerSecond => Vector3::new( + MagneticAngularVelocity::from_nano_tesla_rad_per_second(x), + MagneticAngularVelocity::from_nano_tesla_rad_per_second(y), + MagneticAngularVelocity::from_nano_tesla_rad_per_second(z), + ), + MagneticAngularVelocityType::GaussRadPerSecond => Vector3::new( + MagneticAngularVelocity::from_gauss_rad_per_second(x), + MagneticAngularVelocity::from_gauss_rad_per_second(y), + MagneticAngularVelocity::from_gauss_rad_per_second(z), + ), + MagneticAngularVelocityType::MillGaussRadPerSecond => Vector3::new( + MagneticAngularVelocity::from_mill_gauss_rad_per_second(x), + MagneticAngularVelocity::from_mill_gauss_rad_per_second(y), + MagneticAngularVelocity::from_mill_gauss_rad_per_second(z), + ), + MagneticAngularVelocityType::KiloGaussRadPerSecond => Vector3::new( + MagneticAngularVelocity::from_kilo_gauss_rad_per_second(x), + MagneticAngularVelocity::from_kilo_gauss_rad_per_second(y), + MagneticAngularVelocity::from_kilo_gauss_rad_per_second(z), + ), + } + } + // 以标量角动量 k 作为输入:m = k * (B*w) / |B|^2 pub fn to_magnetic_moment( &self, diff --git a/src/physics/basic/vector/magnetic_induction.rs b/src/physics/basic/vector/magnetic_induction.rs index bcb5c1c..8320795 100644 --- a/src/physics/basic/vector/magnetic_induction.rs +++ b/src/physics/basic/vector/magnetic_induction.rs @@ -1,4 +1,20 @@ -use crate::physics::basic::{Coef, MagneticInduction, MagneticInductionType, Vector3}; +use std::ops::{Div, Mul}; +use crate::physics::basic::{AngularVelocity, Coef, MagneticAngularVelocity, MagneticInduction, MagneticInductionType, Vector3}; + +impl Mul for Vector3{ + type Output = Vector3; + + fn mul(self, rhs: AngularVelocity) -> Self::Output { + let x = self.x.as_nano_tesla() * rhs.as_rad_per_second(); + let y = self.y.as_nano_tesla() * rhs.as_rad_per_second(); + let z = self.z.as_nano_tesla() * rhs.as_rad_per_second(); + Vector3::new( + MagneticAngularVelocity::from_nano_tesla_rad_per_second(x), + MagneticAngularVelocity::from_nano_tesla_rad_per_second(y), + MagneticAngularVelocity::from_nano_tesla_rad_per_second(z), + ) + } +} impl Vector3 { pub fn to_vector3_coef(&self, magnetic_induction_type: MagneticInductionType) -> Vector3 { @@ -49,6 +65,23 @@ impl Vector3 { }; Vector3::new(x, y, z) } + + pub fn from_array_with_unit(array: [f64; 3], magnetic_induction_type: MagneticInductionType) -> Vector3 { + let [x, y, z] = array; + let x = MagneticInduction { + v: x, + default_type: magnetic_induction_type, + }; + let y = MagneticInduction { + v: y, + default_type: magnetic_induction_type, + }; + let z = MagneticInduction { + v: z, + default_type: magnetic_induction_type, + }; + Vector3::new(x, y, z) + } } #[cfg(test)] diff --git a/src/physics/basic/vector/magnetic_moment.rs b/src/physics/basic/vector/magnetic_moment.rs index 44639ca..284122c 100644 --- a/src/physics/basic/vector/magnetic_moment.rs +++ b/src/physics/basic/vector/magnetic_moment.rs @@ -101,6 +101,68 @@ impl Vector3 { } } } + + pub fn from_array_with_unit(array: [f64; 3], magnetic_moment_type: MagneticMomentType) -> Vector3 { + let [x, y, z] = array; + match magnetic_moment_type { + MagneticMomentType::AM2 => { + Vector3::new( + MagneticMoment::from_am2(x), + MagneticMoment::from_am2(y), + MagneticMoment::from_am2(z), + ) + } + MagneticMomentType::MillAM2 => { + Vector3::new( + MagneticMoment::from_mill_am2(x), + MagneticMoment::from_mill_am2(y), + MagneticMoment::from_mill_am2(z), + ) + } + MagneticMomentType::MicroAM2 => { + Vector3::new( + MagneticMoment::from_micro_am2(x), + MagneticMoment::from_micro_am2(y), + MagneticMoment::from_micro_am2(z), + ) + } + MagneticMomentType::NanoAM2 => { + Vector3::new( + MagneticMoment::from_nano_am2(x), + MagneticMoment::from_nano_am2(y), + MagneticMoment::from_nano_am2(z), + ) + } + MagneticMomentType::JPerTesla => { + Vector3::new( + MagneticMoment::from_j_per_tesla(x), + MagneticMoment::from_j_per_tesla(y), + MagneticMoment::from_j_per_tesla(z), + ) + } + MagneticMomentType::MillJPerTesla => { + Vector3::new( + MagneticMoment::from_mill_j_per_tesla(x), + MagneticMoment::from_mill_j_per_tesla(y), + MagneticMoment::from_mill_j_per_tesla(z), + ) + } + MagneticMomentType::MicroJPerTesla => { + Vector3::new( + MagneticMoment::from_micro_j_per_tesla(x), + MagneticMoment::from_micro_j_per_tesla(y), + MagneticMoment::from_micro_j_per_tesla(z), + ) + } + MagneticMomentType::NanoJPerTesla => { + Vector3::new( + MagneticMoment::from_nano_j_per_tesla(x), + MagneticMoment::from_nano_j_per_tesla(y), + MagneticMoment::from_nano_j_per_tesla(z), + ) + } + } + } } #[cfg(test)] diff --git a/src/physics/basic/vector/megnetic_induction.rs b/src/physics/basic/vector/megnetic_induction.rs deleted file mode 100644 index 30f5382..0000000 --- a/src/physics/basic/vector/megnetic_induction.rs +++ /dev/null @@ -1,132 +0,0 @@ -use std::ops::{Div, Mul}; -use crate::physics::basic::{AngularVelocity, MagneticAngularVelocity, MagneticInduction, Vector3}; - -impl Mul for Vector3{ - type Output = Vector3; - - fn mul(self, rhs: AngularVelocity) -> Self::Output { - let x = self.x.as_nano_tesla() * rhs.as_rad_per_second(); - let y = self.y.as_nano_tesla() * rhs.as_rad_per_second(); - let z = self.z.as_nano_tesla() * rhs.as_rad_per_second(); - Vector3::new( - MagneticAngularVelocity::from_nano_tesla_rad_per_second(x), - MagneticAngularVelocity::from_nano_tesla_rad_per_second(y), - MagneticAngularVelocity::from_nano_tesla_rad_per_second(z), - ) - } -} - -#[cfg(test)] -mod tests { - use super::*; - use approx::assert_relative_eq; - - #[test] - fn test_vector3_magnetic_induction_mul_angular_velocity() { - // 创建磁感应强度向量 - let b = Vector3::new( - MagneticInduction::from_tesla(1.0), - MagneticInduction::from_gauss(100.0), - MagneticInduction::from_mill_tesla(500.0), - ); - - // 创建角速度 - let omega = AngularVelocity::from_rad_per_second(2.0); - - // 计算 B * ω - let result = b * omega; - - // 验证结果 - // 1 T * 2 rad/s = 2 T·rad/s - assert_relative_eq!(result.x.as_tesla_rad_per_second(), 2.0, epsilon = 1e-12); - // 100 G * 2 rad/s = 100 * 1e-4 T * 2 rad/s = 0.02 T·rad/s - assert_relative_eq!(result.y.as_tesla_rad_per_second(), 0.02, epsilon = 1e-12); - // 500 mT * 2 rad/s = 0.5 T * 2 rad/s = 1.0 T·rad/s - assert_relative_eq!(result.z.as_tesla_rad_per_second(), 1.0, epsilon = 1e-12); - } - - #[test] - fn test_vector3_magnetic_induction_mul_angular_velocity_different_units() { - // 测试不同单位的磁感应强度 - let b = Vector3::new( - MagneticInduction::from_micro_tesla(1000000.0), // 1 T - MagneticInduction::from_kilo_gauss(1.0), // 0.1 T - MagneticInduction::from_nano_tesla(1000000000.0), // 1 T - ); - - let omega = AngularVelocity::from_deg_per_second(180.0); // π rad/s - - let result = b * omega; - - // 验证结果 - // 1 T * π rad/s = π T·rad/s - assert_relative_eq!(result.x.as_tesla_rad_per_second(), std::f64::consts::PI, epsilon = 1e-12); - // 0.1 T * π rad/s = 0.1π T·rad/s - assert_relative_eq!(result.y.as_tesla_rad_per_second(), 0.1 * std::f64::consts::PI, epsilon = 1e-12); - // 1 T * π rad/s = π T·rad/s - assert_relative_eq!(result.z.as_tesla_rad_per_second(), std::f64::consts::PI, epsilon = 1e-12); - } - - #[test] - fn test_vector3_magnetic_induction_mul_angular_velocity_zero() { - // 测试零值 - let b = Vector3::new( - MagneticInduction::from_tesla(0.0), - MagneticInduction::from_tesla(0.0), - MagneticInduction::from_tesla(0.0), - ); - - let omega = AngularVelocity::from_rad_per_second(5.0); - - let result = b * omega; - - // 验证结果为零 - assert_relative_eq!(result.x.as_tesla_rad_per_second(), 0.0, epsilon = 1e-12); - assert_relative_eq!(result.y.as_tesla_rad_per_second(), 0.0, epsilon = 1e-12); - assert_relative_eq!(result.z.as_tesla_rad_per_second(), 0.0, epsilon = 1e-12); - } - - #[test] - fn test_vector3_magnetic_induction_mul_angular_velocity_negative() { - // 测试负值 - let b = Vector3::new( - MagneticInduction::from_tesla(-2.0), - MagneticInduction::from_tesla(3.0), - MagneticInduction::from_tesla(-1.5), - ); - - let omega = AngularVelocity::from_rad_per_second(-1.5); - - let result = b * omega; - - // 验证结果 - // -2 T * (-1.5) rad/s = 3 T·rad/s - assert_relative_eq!(result.x.as_tesla_rad_per_second(), 3.0, epsilon = 1e-12); - // 3 T * (-1.5) rad/s = -4.5 T·rad/s - assert_relative_eq!(result.y.as_tesla_rad_per_second(), -4.5, epsilon = 1e-12); - // -1.5 T * (-1.5) rad/s = 2.25 T·rad/s - assert_relative_eq!(result.z.as_tesla_rad_per_second(), 2.25, epsilon = 1e-12); - } - - #[test] - fn test_vector3_magnetic_induction_mul_angular_velocity_mixed_units() { - // 测试混合单位 - let b = Vector3::new( - MagneticInduction::from_tesla(1.0), - MagneticInduction::from_mill_gauss(1000.0), // 1 G = 1e-3 mG - MagneticInduction::from_micro_tesla(1000000.0), // 1 T - ); - - let omega = AngularVelocity::from_rad_per_hour(3600.0); // 1 rad/s - - let result = b * omega; - - // 验证结果 - // 1 T * 1 rad/s = 1 T·rad/s - assert_relative_eq!(result.x.as_tesla_rad_per_second(), 1.0, epsilon = 1e-12); - // 1000 mG * 1 rad/s = 1 G * 1 rad/s = 1e-4 T * 1 rad/s = 1e-4 T·rad/s - assert_relative_eq!(result.y.as_tesla_rad_per_second(), 1e-4, epsilon = 1e-12); - // 1 T * 1 rad/s = 1 T·rad/s - assert_relative_eq!(result.z.as_tesla_rad_per_second(), 1.0, epsilon = 1e-12); - } -} \ No newline at end of file diff --git a/src/physics/basic/vector/momentum.rs b/src/physics/basic/vector/momentum.rs index 155ff46..ab41697 100644 --- a/src/physics/basic/vector/momentum.rs +++ b/src/physics/basic/vector/momentum.rs @@ -29,6 +29,23 @@ impl Vector3 { }; Vector3::new(x, y, z) } + + pub fn from_array_with_unit(array: [f64; 3], momentum_type: MomentumType) -> Vector3 { + let [x, y, z] = array; + let x = Momentum { + v: x, + default_type: momentum_type, + }; + let y = Momentum { + v: y, + default_type: momentum_type, + }; + let z = Momentum { + v: z, + default_type: momentum_type, + }; + Vector3::new(x, y, z) + } } #[cfg(test)] diff --git a/src/physics/basic/vector/torque.rs b/src/physics/basic/vector/torque.rs index 723bad0..bd02654 100644 --- a/src/physics/basic/vector/torque.rs +++ b/src/physics/basic/vector/torque.rs @@ -79,6 +79,54 @@ impl Vector3 { } } } + + pub fn from_array_with_unit(array: [f64; 3], torque_type: TorqueType) -> Vector3 { + let [x, y, z] = array; + match torque_type { + TorqueType::NM => { + Vector3::new( + Torque::from_nm(x), + Torque::from_nm(y), + Torque::from_nm(z), + ) + } + TorqueType::MillNM => { + Vector3::new( + Torque::from_mill_nm(x), + Torque::from_mill_nm(y), + Torque::from_mill_nm(z), + ) + } + TorqueType::MicroNM => { + Vector3::new( + Torque::from_micro_nm(x), + Torque::from_micro_nm(y), + Torque::from_micro_nm(z), + ) + } + TorqueType::NanoNM => { + Vector3::new( + Torque::from_nano_nm(x), + Torque::from_nano_nm(y), + Torque::from_nano_nm(z), + ) + } + TorqueType::KNM => { + Vector3::new( + Torque::from_knm(x), + Torque::from_knm(y), + Torque::from_knm(z), + ) + } + TorqueType::MNM => { + Vector3::new( + Torque::from_mnm(x), + Torque::from_mnm(y), + Torque::from_mnm(z), + ) + } + } + } } #[cfg(test)] diff --git a/src/physics/basic/vector/velocity.rs b/src/physics/basic/vector/velocity.rs index 04107a2..4bb32f9 100644 --- a/src/physics/basic/vector/velocity.rs +++ b/src/physics/basic/vector/velocity.rs @@ -46,6 +46,23 @@ impl Vector3 { }; Vector3::new(x, y, z) } + + pub fn from_array_with_unit(array: [f64; 3], velocity_type: VelocityType) -> Vector3 { + let [x, y, z] = array; + let x = Velocity { + v: x, + default_type: velocity_type, + }; + let y = Velocity { + v: y, + default_type: velocity_type, + }; + let z = Velocity { + v: z, + default_type: velocity_type, + }; + Vector3::new(x, y, z) + } } #[cfg(test)] From 5a2b30be6f8bac9d2213694ee1e13319905920a6 Mon Sep 17 00:00:00 2001 From: Treagzhao <920866163@qq.com> Date: Tue, 10 Mar 2026 10:19:06 +0800 Subject: [PATCH 3/5] Add unit tests for from_array_with_unit method in all vector files --- src/physics/basic/vector/acceleration.rs | 24 ++++++ src/physics/basic/vector/angular.rs | 18 +++++ .../basic/vector/angular_acceleration.rs | 18 +++++ src/physics/basic/vector/angular_momentum.rs | 42 ++++++++++ src/physics/basic/vector/angular_velocity.rs | 19 +++++ src/physics/basic/vector/distance.rs | 27 +++++++ src/physics/basic/vector/force.rs | 42 ++++++++++ .../basic/vector/magnetic_angular_velocity.rs | 77 ++++++++++++++++++- .../basic/vector/magnetic_induction.rs | 27 +++++++ src/physics/basic/vector/magnetic_moment.rs | 27 +++++++ src/physics/basic/vector/momentum.rs | 19 +++++ src/physics/basic/vector/torque.rs | 27 +++++++ src/physics/basic/vector/velocity.rs | 30 ++++++++ 13 files changed, 394 insertions(+), 3 deletions(-) diff --git a/src/physics/basic/vector/acceleration.rs b/src/physics/basic/vector/acceleration.rs index 720ba86..2d694bd 100644 --- a/src/physics/basic/vector/acceleration.rs +++ b/src/physics/basic/vector/acceleration.rs @@ -242,4 +242,28 @@ mod tests { assert_relative_eq!(coef_vec.y.get_value(), 1e-15); assert_relative_eq!(coef_vec.z.get_value(), 1e-20); } + + #[test] + fn test_from_array_with_unit() { + // 测试 from_array_with_unit 方法 + let array = [9.8, 19.6, 29.4]; + + // 测试 MPerSecond2 单位 + let acceleration_vec = Vector3::::from_array_with_unit(array, AccelerationType::MPerSecond2); + assert_relative_eq!(acceleration_vec.x.as_m_per_s2(), 9.8); + assert_relative_eq!(acceleration_vec.y.as_m_per_s2(), 19.6); + assert_relative_eq!(acceleration_vec.z.as_m_per_s2(), 29.4); + + // 测试 KmPerHour2 单位 + let acceleration_vec_kmh2 = Vector3::::from_array_with_unit(array, AccelerationType::KmPerHour2); + assert_relative_eq!(acceleration_vec_kmh2.x.as_km_per_h_2(), 9.8); + assert_relative_eq!(acceleration_vec_kmh2.y.as_km_per_h_2(), 19.6); + assert_relative_eq!(acceleration_vec_kmh2.z.as_km_per_h_2(), 29.4); + + // 测试 G 单位 + let acceleration_vec_g = Vector3::::from_array_with_unit(array, AccelerationType::G); + assert_relative_eq!(acceleration_vec_g.x.as_g(), 9.8); + assert_relative_eq!(acceleration_vec_g.y.as_g(), 19.6); + assert_relative_eq!(acceleration_vec_g.z.as_g(), 29.4); + } } diff --git a/src/physics/basic/vector/angular.rs b/src/physics/basic/vector/angular.rs index 09002cb..afb5947 100644 --- a/src/physics/basic/vector/angular.rs +++ b/src/physics/basic/vector/angular.rs @@ -1128,4 +1128,22 @@ mod tests { assert_relative_eq!(q2, 0.0, epsilon = 1e-12); assert_relative_eq!(q3, 1.0, epsilon = 1e-12); } + + #[test] + fn test_from_array_with_unit() { + // 测试 from_array_with_unit 方法 + let array = [1.0, 2.0, 3.0]; + + // 测试 Rad 单位 + let angular_vec = Vector3::::from_array_with_unit(array, AngularType::Rad); + assert_relative_eq!(angular_vec.x.as_rad(), 1.0); + assert_relative_eq!(angular_vec.y.as_rad(), 2.0); + assert_relative_eq!(angular_vec.z.as_rad(), 3.0); + + // 测试 Deg 单位 + let angular_vec_deg = Vector3::::from_array_with_unit(array, AngularType::Deg); + assert_relative_eq!(angular_vec_deg.x.as_deg(), 1.0); + assert_relative_eq!(angular_vec_deg.y.as_deg(), 2.0); + assert_relative_eq!(angular_vec_deg.z.as_deg(), 3.0); + } } diff --git a/src/physics/basic/vector/angular_acceleration.rs b/src/physics/basic/vector/angular_acceleration.rs index ab97f87..4ede7ee 100644 --- a/src/physics/basic/vector/angular_acceleration.rs +++ b/src/physics/basic/vector/angular_acceleration.rs @@ -147,4 +147,22 @@ mod test { assert_relative_eq!(original_angular_acceleration_vec.y.as_rad_per_second2(), reconstructed_angular_acceleration_vec.y.as_rad_per_second2()); assert_relative_eq!(original_angular_acceleration_vec.z.as_rad_per_second2(), reconstructed_angular_acceleration_vec.z.as_rad_per_second2()); } + + #[test] + fn test_from_array_with_unit() { + // 测试 from_array_with_unit 方法 + let array = [1.0, 2.0, 3.0]; + + // 测试 RadperSecond2 单位 + let angular_acceleration_vec = Vector3::::from_array_with_unit(array, AngularAccelerationType::RadperSecond2); + assert_relative_eq!(angular_acceleration_vec.x.as_rad_per_second2(), 1.0); + assert_relative_eq!(angular_acceleration_vec.y.as_rad_per_second2(), 2.0); + assert_relative_eq!(angular_acceleration_vec.z.as_rad_per_second2(), 3.0); + + // 测试 DegPerSecond2 单位 + let angular_acceleration_vec_deg = Vector3::::from_array_with_unit(array, AngularAccelerationType::DegPerSecond2); + assert_relative_eq!(angular_acceleration_vec_deg.x.as_deg_per_second2(), 1.0); + assert_relative_eq!(angular_acceleration_vec_deg.y.as_deg_per_second2(), 2.0); + assert_relative_eq!(angular_acceleration_vec_deg.z.as_deg_per_second2(), 3.0); + } } \ No newline at end of file diff --git a/src/physics/basic/vector/angular_momentum.rs b/src/physics/basic/vector/angular_momentum.rs index 834f09b..43c147c 100644 --- a/src/physics/basic/vector/angular_momentum.rs +++ b/src/physics/basic/vector/angular_momentum.rs @@ -275,4 +275,46 @@ mod tests { assert_relative_eq!(coef_from_nano_nms_micro_nms.x.get_value(), 1000000.0, epsilon = 1e-10); assert_relative_eq!(coef_from_nano_nms_nano_nms.x.get_value(), 1000000000.0, epsilon = 1e-10); } + + #[test] + fn test_from_array_with_unit() { + // 测试 from_array_with_unit 方法 + let array = [1.0, 2.0, 3.0]; + + // 测试 KgM2perSecond 单位 + let angular_momentum_vec = Vector3::::from_array_with_unit(array, AngularMomentumType::KgM2perSecond); + assert_relative_eq!(angular_momentum_vec.x.as_kg_m2_per_second(), 1.0); + assert_relative_eq!(angular_momentum_vec.y.as_kg_m2_per_second(), 2.0); + assert_relative_eq!(angular_momentum_vec.z.as_kg_m2_per_second(), 3.0); + + // 测试 KgKm2perSecond 单位 + let angular_momentum_vec_km2 = Vector3::::from_array_with_unit(array, AngularMomentumType::KgKm2perSecond); + assert_relative_eq!(angular_momentum_vec_km2.x.as_kg_km2_per_second(), 1.0); + assert_relative_eq!(angular_momentum_vec_km2.y.as_kg_km2_per_second(), 2.0); + assert_relative_eq!(angular_momentum_vec_km2.z.as_kg_km2_per_second(), 3.0); + + // 测试 Nms 单位 + let angular_momentum_vec_nms = Vector3::::from_array_with_unit(array, AngularMomentumType::Nms); + assert_relative_eq!(angular_momentum_vec_nms.x.as_nms(), 1.0); + assert_relative_eq!(angular_momentum_vec_nms.y.as_nms(), 2.0); + assert_relative_eq!(angular_momentum_vec_nms.z.as_nms(), 3.0); + + // 测试 MillNms 单位 + let angular_momentum_vec_mill_nms = Vector3::::from_array_with_unit(array, AngularMomentumType::MillNms); + assert_relative_eq!(angular_momentum_vec_mill_nms.x.as_mill_nms(), 1.0); + assert_relative_eq!(angular_momentum_vec_mill_nms.y.as_mill_nms(), 2.0); + assert_relative_eq!(angular_momentum_vec_mill_nms.z.as_mill_nms(), 3.0); + + // 测试 MicroNms 单位 + let angular_momentum_vec_micro_nms = Vector3::::from_array_with_unit(array, AngularMomentumType::MicroNms); + assert_relative_eq!(angular_momentum_vec_micro_nms.x.as_micro_nms(), 1.0); + assert_relative_eq!(angular_momentum_vec_micro_nms.y.as_micro_nms(), 2.0); + assert_relative_eq!(angular_momentum_vec_micro_nms.z.as_micro_nms(), 3.0); + + // 测试 NanoNms 单位 + let angular_momentum_vec_nano_nms = Vector3::::from_array_with_unit(array, AngularMomentumType::NanoNms); + assert_relative_eq!(angular_momentum_vec_nano_nms.x.as_nano_nms(), 1.0); + assert_relative_eq!(angular_momentum_vec_nano_nms.y.as_nano_nms(), 2.0); + assert_relative_eq!(angular_momentum_vec_nano_nms.z.as_nano_nms(), 3.0); + } } diff --git a/src/physics/basic/vector/angular_velocity.rs b/src/physics/basic/vector/angular_velocity.rs index 8c5ce8f..610529a 100644 --- a/src/physics/basic/vector/angular_velocity.rs +++ b/src/physics/basic/vector/angular_velocity.rs @@ -387,4 +387,23 @@ mod test { assert_eq!(array[1], -1.0); assert_eq!(array[2], 1e-10); } + + #[test] + fn test_from_array_with_unit() { + // 测试从数组和单位类型创建角速度向量 + let array = [1.0, 2.0, 3.0]; + let angular_velocity_vec = Vector3::::from_array_with_unit(array, AngularVelocityType::RadperSecond); + + assert_relative_eq!(angular_velocity_vec.x.as_rad_per_second(), 1.0); + assert_relative_eq!(angular_velocity_vec.y.as_rad_per_second(), 2.0); + assert_relative_eq!(angular_velocity_vec.z.as_rad_per_second(), 3.0); + + // 测试不同单位类型 + let array = [57.2958, 114.5916, 171.8873]; + let angular_velocity_vec = Vector3::::from_array_with_unit(array, AngularVelocityType::DegPerSecond); + + assert_relative_eq!(angular_velocity_vec.x.as_deg_per_second(), 57.2958); + assert_relative_eq!(angular_velocity_vec.y.as_deg_per_second(), 114.5916); + assert_relative_eq!(angular_velocity_vec.z.as_deg_per_second(), 171.8873); + } } \ No newline at end of file diff --git a/src/physics/basic/vector/distance.rs b/src/physics/basic/vector/distance.rs index 581c67f..625a499 100644 --- a/src/physics/basic/vector/distance.rs +++ b/src/physics/basic/vector/distance.rs @@ -406,4 +406,31 @@ mod tests { assert_relative_eq!(distance_ly.y.as_light_year(), 2.0); assert_relative_eq!(distance_ly.z.as_light_year(), 3.0); } + + #[test] + fn test_from_array_with_unit() { + // 测试从数组和单位类型创建距离向量 + let array = [1000.0, 2000.0, 3000.0]; + let distance_vec = Vector3::::from_array_with_unit(array, DistanceType::M); + + assert_relative_eq!(distance_vec.x.as_m(), 1000.0); + assert_relative_eq!(distance_vec.y.as_m(), 2000.0); + assert_relative_eq!(distance_vec.z.as_m(), 3000.0); + + // 测试不同单位类型 + let array = [1.5, 2.5, 3.5]; + let distance_vec = Vector3::::from_array_with_unit(array, DistanceType::KM); + + assert_relative_eq!(distance_vec.x.as_km(), 1.5); + assert_relative_eq!(distance_vec.y.as_km(), 2.5); + assert_relative_eq!(distance_vec.z.as_km(), 3.5); + + // 测试光年单位 + let array = [1.0, 2.0, 3.0]; + let distance_vec = Vector3::::from_array_with_unit(array, DistanceType::LightYear); + + assert_relative_eq!(distance_vec.x.as_light_year(), 1.0); + assert_relative_eq!(distance_vec.y.as_light_year(), 2.0); + assert_relative_eq!(distance_vec.z.as_light_year(), 3.0); + } } diff --git a/src/physics/basic/vector/force.rs b/src/physics/basic/vector/force.rs index 331f973..ec70d56 100644 --- a/src/physics/basic/vector/force.rs +++ b/src/physics/basic/vector/force.rs @@ -331,4 +331,46 @@ mod tests { assert_relative_eq!(coef_from_mega_newton_kilo.x.get_value(), 0.001, epsilon = 1e-10); assert_relative_eq!(coef_from_mega_newton_mega.x.get_value(), 0.000001, epsilon = 1e-10); } + + #[test] + fn test_from_array_with_unit() { + // 测试 from_array_with_unit 方法 + let array = [1.0, 2.0, 3.0]; + + // 测试 Newton 单位 + let force_vec = Vector3::::from_array_with_unit(array, ForceType::Newton); + assert_relative_eq!(force_vec.x.as_newton(), 1.0, epsilon = 1e-10); + assert_relative_eq!(force_vec.y.as_newton(), 2.0, epsilon = 1e-10); + assert_relative_eq!(force_vec.z.as_newton(), 3.0, epsilon = 1e-10); + + // 测试 MillNewton 单位 + let force_vec_mill = Vector3::::from_array_with_unit(array, ForceType::MillNewton); + assert_relative_eq!(force_vec_mill.x.as_mill_newton(), 1.0, epsilon = 1e-10); + assert_relative_eq!(force_vec_mill.y.as_mill_newton(), 2.0, epsilon = 1e-10); + assert_relative_eq!(force_vec_mill.z.as_mill_newton(), 3.0, epsilon = 1e-10); + + // 测试 MicroNewton 单位 + let force_vec_micro = Vector3::::from_array_with_unit(array, ForceType::MicroNewton); + assert_relative_eq!(force_vec_micro.x.as_micro_newton(), 1.0, epsilon = 1e-10); + assert_relative_eq!(force_vec_micro.y.as_micro_newton(), 2.0, epsilon = 1e-10); + assert_relative_eq!(force_vec_micro.z.as_micro_newton(), 3.0, epsilon = 1e-10); + + // 测试 NanoNewton 单位 + let force_vec_nano = Vector3::::from_array_with_unit(array, ForceType::NanoNewton); + assert_relative_eq!(force_vec_nano.x.as_nano_newton(), 1.0, epsilon = 1e-10); + assert_relative_eq!(force_vec_nano.y.as_nano_newton(), 2.0, epsilon = 1e-10); + assert_relative_eq!(force_vec_nano.z.as_nano_newton(), 3.0, epsilon = 1e-10); + + // 测试 KiloNewton 单位 + let force_vec_kilo = Vector3::::from_array_with_unit(array, ForceType::KiloNewton); + assert_relative_eq!(force_vec_kilo.x.as_kilo_newton(), 1.0, epsilon = 1e-10); + assert_relative_eq!(force_vec_kilo.y.as_kilo_newton(), 2.0, epsilon = 1e-10); + assert_relative_eq!(force_vec_kilo.z.as_kilo_newton(), 3.0, epsilon = 1e-10); + + // 测试 MegaNewton 单位 + let force_vec_mega = Vector3::::from_array_with_unit(array, ForceType::MegaNewton); + assert_relative_eq!(force_vec_mega.x.as_mega_newton(), 1.0, epsilon = 1e-10); + assert_relative_eq!(force_vec_mega.y.as_mega_newton(), 2.0, epsilon = 1e-10); + assert_relative_eq!(force_vec_mega.z.as_mega_newton(), 3.0, epsilon = 1e-10); + } } diff --git a/src/physics/basic/vector/magnetic_angular_velocity.rs b/src/physics/basic/vector/magnetic_angular_velocity.rs index 9449728..b7da1a2 100644 --- a/src/physics/basic/vector/magnetic_angular_velocity.rs +++ b/src/physics/basic/vector/magnetic_angular_velocity.rs @@ -1624,9 +1624,80 @@ mod tests { let angular_momentum = AngularMomentum::from_nms(0.3); let result = cross.to_magnetic_moment(&angular_momentum, &b); println!("输出结果(μT级入参): {:?}", result.to_array()); - assert_relative_eq!(-12931.0344827,result.x.as_am2(),epsilon = 1e-4); - assert_relative_eq!(-12931.0344827,result.y.as_am2(),epsilon = 1e-4); - assert_relative_eq!(-12931.0344827,result.z.as_am2(),epsilon = 1e-4); + assert_relative_eq!(-12931.0344827, result.x.as_am2(), epsilon = 1e-4); + assert_relative_eq!(-12931.0344827, result.y.as_am2(), epsilon = 1e-4); + assert_relative_eq!(-12931.0344827, result.z.as_am2(), epsilon = 1e-4); + } + + #[test] + fn test_from_array_with_unit() { + // 测试从数组和单位类型创建磁角速度向量 + let array = [1.0, 2.0, 3.0]; + let magnetic_angular_velocity_vec = + Vector3::::from_array_with_unit( + array, + MagneticAngularVelocityType::TeslaRadPerSecond, + ); + + assert_relative_eq!( + magnetic_angular_velocity_vec.x.as_tesla_rad_per_second(), + 1.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec.y.as_tesla_rad_per_second(), + 2.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec.z.as_tesla_rad_per_second(), + 3.0 + ); + + // 测试不同单位类型 + let array = [1000.0, 2000.0, 3000.0]; + let magnetic_angular_velocity_vec = + Vector3::::from_array_with_unit( + array, + MagneticAngularVelocityType::MillTeslaRadPerSecond, + ); + + assert_relative_eq!( + magnetic_angular_velocity_vec + .x + .as_mill_tesla_rad_per_second(), + 1000.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec + .y + .as_mill_tesla_rad_per_second(), + 2000.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec + .z + .as_mill_tesla_rad_per_second(), + 3000.0 + ); + // 测试高斯单位 + let array = [10000.0, 20000.0, 30000.0]; + let magnetic_angular_velocity_vec = + Vector3::::from_array_with_unit( + array, + MagneticAngularVelocityType::GaussRadPerSecond, + ); + + assert_relative_eq!( + magnetic_angular_velocity_vec.x.as_gauss_rad_per_second(), + 10000.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec.y.as_gauss_rad_per_second(), + 20000.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec.z.as_gauss_rad_per_second(), + 30000.0 + ); } } diff --git a/src/physics/basic/vector/magnetic_induction.rs b/src/physics/basic/vector/magnetic_induction.rs index 8320795..92d4139 100644 --- a/src/physics/basic/vector/magnetic_induction.rs +++ b/src/physics/basic/vector/magnetic_induction.rs @@ -417,4 +417,31 @@ mod tests { assert_relative_eq!(coef_vec.y.get_value(), 1e-6); // 1e-15 T = 1e-6 nT assert_relative_eq!(coef_vec.z.get_value(), 1e-11); // 1e-20 T = 1e-11 nT } + + #[test] + fn test_from_array_with_unit() { + // 测试从数组和单位类型创建磁感应向量 + let array = [1.0, 2.0, 3.0]; + let magnetic_induction_vec = Vector3::::from_array_with_unit(array, MagneticInductionType::Tesla); + + assert_relative_eq!(magnetic_induction_vec.x.as_tesla(), 1.0); + assert_relative_eq!(magnetic_induction_vec.y.as_tesla(), 2.0); + assert_relative_eq!(magnetic_induction_vec.z.as_tesla(), 3.0); + + // 测试不同单位类型 + let array = [10000.0, 20000.0, 30000.0]; + let magnetic_induction_vec = Vector3::::from_array_with_unit(array, MagneticInductionType::Gauss); + + assert_relative_eq!(magnetic_induction_vec.x.as_gauss(), 10000.0); + assert_relative_eq!(magnetic_induction_vec.y.as_gauss(), 20000.0); + assert_relative_eq!(magnetic_induction_vec.z.as_gauss(), 30000.0); + + // 测试毫特斯拉单位 + let array = [1000.0, 2000.0, 3000.0]; + let magnetic_induction_vec = Vector3::::from_array_with_unit(array, MagneticInductionType::MillTesla); + + assert_relative_eq!(magnetic_induction_vec.x.as_milli_tesla(), 1000.0); + assert_relative_eq!(magnetic_induction_vec.y.as_milli_tesla(), 2000.0); + assert_relative_eq!(magnetic_induction_vec.z.as_milli_tesla(), 3000.0); + } } diff --git a/src/physics/basic/vector/magnetic_moment.rs b/src/physics/basic/vector/magnetic_moment.rs index 284122c..68a57c7 100644 --- a/src/physics/basic/vector/magnetic_moment.rs +++ b/src/physics/basic/vector/magnetic_moment.rs @@ -459,4 +459,31 @@ mod tests { assert_relative_eq!(coef_from_nano_j_per_tesla_micro_j_per_tesla.x.get_value(), 1000000.0, epsilon = 1e-10); assert_relative_eq!(coef_from_nano_j_per_tesla_nano_j_per_tesla.x.get_value(), 1000000000.0, epsilon = 1e-10); } + + #[test] + fn test_from_array_with_unit() { + // 测试从数组和单位类型创建磁矩向量 + let array = [1.0, 2.0, 3.0]; + let magnetic_moment_vec = Vector3::::from_array_with_unit(array, MagneticMomentType::AM2); + + assert_relative_eq!(magnetic_moment_vec.x.as_am2(), 1.0); + assert_relative_eq!(magnetic_moment_vec.y.as_am2(), 2.0); + assert_relative_eq!(magnetic_moment_vec.z.as_am2(), 3.0); + + // 测试不同单位类型 + let array = [1000.0, 2000.0, 3000.0]; + let magnetic_moment_vec = Vector3::::from_array_with_unit(array, MagneticMomentType::MillAM2); + + assert_relative_eq!(magnetic_moment_vec.x.as_mill_am2(), 1000.0); + assert_relative_eq!(magnetic_moment_vec.y.as_mill_am2(), 2000.0); + assert_relative_eq!(magnetic_moment_vec.z.as_mill_am2(), 3000.0); + + // 测试焦耳每特斯拉单位 + let array = [1.0, 2.0, 3.0]; + let magnetic_moment_vec = Vector3::::from_array_with_unit(array, MagneticMomentType::JPerTesla); + + assert_relative_eq!(magnetic_moment_vec.x.as_j_per_tesla(), 1.0); + assert_relative_eq!(magnetic_moment_vec.y.as_j_per_tesla(), 2.0); + assert_relative_eq!(magnetic_moment_vec.z.as_j_per_tesla(), 3.0); + } } diff --git a/src/physics/basic/vector/momentum.rs b/src/physics/basic/vector/momentum.rs index ab41697..9eeb552 100644 --- a/src/physics/basic/vector/momentum.rs +++ b/src/physics/basic/vector/momentum.rs @@ -128,4 +128,23 @@ mod tests { assert_relative_eq!(original_momentum_vec.y.as_kg_m_s(), reconstructed_momentum_vec.y.as_kg_m_s()); assert_relative_eq!(original_momentum_vec.z.as_kg_m_s(), reconstructed_momentum_vec.z.as_kg_m_s()); } + + #[test] + fn test_from_array_with_unit() { + // 测试从数组和单位类型创建动量向量 + let array = [10.0, 20.0, 30.0]; + let momentum_vec = Vector3::::from_array_with_unit(array, MomentumType::KgMperSecond); + + assert_relative_eq!(momentum_vec.x.as_kg_m_s(), 10.0); + assert_relative_eq!(momentum_vec.y.as_kg_m_s(), 20.0); + assert_relative_eq!(momentum_vec.z.as_kg_m_s(), 30.0); + + // 测试不同单位类型 + let array = [1.0, 2.0, 3.0]; + let momentum_vec = Vector3::::from_array_with_unit(array, MomentumType::KgKmperSecond); + + assert_relative_eq!(momentum_vec.x.as_kg_km_s(), 1.0); + assert_relative_eq!(momentum_vec.y.as_kg_km_s(), 2.0); + assert_relative_eq!(momentum_vec.z.as_kg_km_s(), 3.0); + } } diff --git a/src/physics/basic/vector/torque.rs b/src/physics/basic/vector/torque.rs index bd02654..8ce21da 100644 --- a/src/physics/basic/vector/torque.rs +++ b/src/physics/basic/vector/torque.rs @@ -331,4 +331,31 @@ mod tests { assert_relative_eq!(coef_from_mnm_knm.x.get_value(), 0.001, epsilon = 1e-10); assert_relative_eq!(coef_from_mnm_mnm.x.get_value(), 0.000001, epsilon = 1e-10); } + + #[test] + fn test_from_array_with_unit() { + // 测试从数组和单位类型创建力矩向量 + let array = [1.0, 2.0, 3.0]; + let torque_vec = Vector3::::from_array_with_unit(array, TorqueType::NM); + + assert_relative_eq!(torque_vec.x.as_nm(), 1.0); + assert_relative_eq!(torque_vec.y.as_nm(), 2.0); + assert_relative_eq!(torque_vec.z.as_nm(), 3.0); + + // 测试不同单位类型 + let array = [1000.0, 2000.0, 3000.0]; + let torque_vec = Vector3::::from_array_with_unit(array, TorqueType::MillNM); + + assert_relative_eq!(torque_vec.x.as_mill_nm(), 1000.0); + assert_relative_eq!(torque_vec.y.as_mill_nm(), 2000.0); + assert_relative_eq!(torque_vec.z.as_mill_nm(), 3000.0); + + // 测试千牛米单位 + let array = [0.001, 0.002, 0.003]; + let torque_vec = Vector3::::from_array_with_unit(array, TorqueType::KNM); + + assert_relative_eq!(torque_vec.x.as_knm(), 0.001); + assert_relative_eq!(torque_vec.y.as_knm(), 0.002); + assert_relative_eq!(torque_vec.z.as_knm(), 0.003); + } } diff --git a/src/physics/basic/vector/velocity.rs b/src/physics/basic/vector/velocity.rs index 4bb32f9..e2e8402 100644 --- a/src/physics/basic/vector/velocity.rs +++ b/src/physics/basic/vector/velocity.rs @@ -299,4 +299,34 @@ mod tests { assert_relative_eq!(coef_vec.y.get_value(), 1e-15); assert_relative_eq!(coef_vec.z.get_value(), 1e-20); } + + #[test] + fn test_from_array_with_unit() { + // 测试 from_array_with_unit 方法 + let array = [10.0, 20.0, 30.0]; + + // 测试 MPerSecond 单位 + let velocity_vec = Vector3::::from_array_with_unit(array, VelocityType::MPerSecond); + assert_relative_eq!(velocity_vec.x.as_m_per_sec(), 10.0); + assert_relative_eq!(velocity_vec.y.as_m_per_sec(), 20.0); + assert_relative_eq!(velocity_vec.z.as_m_per_sec(), 30.0); + + // 测试 KmPerHour 单位 + let velocity_vec_kmh = Vector3::::from_array_with_unit(array, VelocityType::KmPerHour); + assert_relative_eq!(velocity_vec_kmh.x.as_km_per_h(), 10.0); + assert_relative_eq!(velocity_vec_kmh.y.as_km_per_h(), 20.0); + assert_relative_eq!(velocity_vec_kmh.z.as_km_per_h(), 30.0); + + // 测试 KmPerSecond 单位 + let velocity_vec_kms = Vector3::::from_array_with_unit(array, VelocityType::KmPerSecond); + assert_relative_eq!(velocity_vec_kms.x.as_km_per_sec(), 10.0); + assert_relative_eq!(velocity_vec_kms.y.as_km_per_sec(), 20.0); + assert_relative_eq!(velocity_vec_kms.z.as_km_per_sec(), 30.0); + + // 测试 LightSpeed 单位 + let velocity_vec_light = Vector3::::from_array_with_unit(array, VelocityType::LightSpeed); + assert_relative_eq!(velocity_vec_light.x.as_light_speed(), 10.0); + assert_relative_eq!(velocity_vec_light.y.as_light_speed(), 20.0); + assert_relative_eq!(velocity_vec_light.z.as_light_speed(), 30.0); + } } \ No newline at end of file From 6d6e2780ee4a06df56e9b3153ee8d7ff241aeb9b Mon Sep 17 00:00:00 2001 From: Treagzhao <920866163@qq.com> Date: Tue, 10 Mar 2026 10:39:46 +0800 Subject: [PATCH 4/5] Complete test coverage for magnetic_moment.rs and other vector files --- 1.txt | 112 +++++++-------- src/physics/basic/vector/angular_velocity.rs | 25 +++- .../basic/vector/magnetic_angular_velocity.rs | 114 ++++++++++++++- .../basic/vector/magnetic_induction.rs | 37 ++++- src/physics/basic/vector/magnetic_moment.rs | 131 ++++++++++++++++++ 5 files changed, 349 insertions(+), 70 deletions(-) diff --git a/1.txt b/1.txt index 9ba472e..6a8725c 100644 --- a/1.txt +++ b/1.txt @@ -345,31 +345,13 @@ warning: method `T` should have a snake case name = note: `#[warn(non_snake_case)]` on by default warning: `zmatrix` (lib) generated 53 warnings (run `cargo fix --lib -p zmatrix` to apply 39 suggestions) -warning: unused import: `Area` - --> src/physics/basic/magnetic_moment.rs:342:52 - | -342 | use crate::physics::basic::{MagneticInduction, Area}; - | ^^^^ - -warning: duplicated attribute - --> src/physics/basic/vector/angular_velocity.rs:95:5 - | -95 | #[test] - | ^^^^^^^ - | - = note: `#[warn(duplicate_macro_attributes)]` on by default - -warning: unused import: `std::any::TypeId` - --> src/physics/basic/velocity.rs:318:9 - | -318 | use std::any::TypeId; - | ^^^^^^^^^^^^^^^^ - -warning: duplicated attribute - --> src/utils/float.rs:51:5 - | -51 | #[test] - | ^^^^^^^ +warning: unused imports: `Energy`, `MagneticInduction`, `Mass`, `Power`, `Torque`, `VectorQuantity`, and `Volume` + --> examples/example_vector_quantity_restriction.rs:1:31 + | +1 | use zmatrix::physics::basic::{VectorQuantity, Distance, Velocity, Force, Torque, MagneticInduction, Vector3, Mass, Energy, Power, Volume}; + | ^^^^^^^^^^^^^^ ^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^ ^^^^^ ^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default warning: unused import: `Energy` --> examples/example_magnetic_moment.rs:1:66 @@ -379,14 +361,6 @@ warning: unused import: `Energy` | = note: `#[warn(unused_imports)]` on by default -warning: unused import: `Acceleration` - --> examples/example_energy.rs:1:65 - | -1 | use zmatrix::physics::basic::{Energy, Distance, Mass, Velocity, Acceleration, PhysicalQuantity}; - | ^^^^^^^^^^^^ - | - = note: `#[warn(unused_imports)]` on by default - warning: unused variable: `acc` --> examples/example_physics.rs:20:9 | @@ -427,6 +401,40 @@ warning: function `exmples_vector3` is never used 32 | fn exmples_vector3(){ | ^^^^^^^^^^^^^^^ +warning: unused import: `Energy` + --> examples/example_torque.rs:1:49 + | +1 | use zmatrix::physics::basic::{Torque, Distance, Energy, PhysicalQuantity}; + | ^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: unused import: `Area` + --> src/physics/basic/magnetic_moment.rs:342:52 + | +342 | use crate::physics::basic::{MagneticInduction, Area}; + | ^^^^ + +warning: duplicated attribute + --> src/physics/basic/vector/angular_velocity.rs:95:5 + | +95 | #[test] + | ^^^^^^^ + | + = note: `#[warn(duplicate_macro_attributes)]` on by default + +warning: unused import: `std::any::TypeId` + --> src/physics/basic/velocity.rs:318:9 + | +318 | use std::any::TypeId; + | ^^^^^^^^^^^^^^^^ + +warning: duplicated attribute + --> src/utils/float.rs:51:5 + | +51 | #[test] + | ^^^^^^^ + warning: unused import: `zmatrix::dense` --> examples/examples_dense.rs:1:5 | @@ -448,28 +456,6 @@ help: use `let _ = ...` to ignore the resulting value 61 | let _ = m1.set(1, 1, 12); | +++++++ -warning: `zmatrix` (example "example_magnetic_moment") generated 1 warning (run `cargo fix --example "example_magnetic_moment"` to apply 1 suggestion) -warning: `zmatrix` (example "example_physics") generated 6 warnings -warning: `zmatrix` (example "examples_dense") generated 2 warnings (run `cargo fix --example "examples_dense"` to apply 1 suggestion) -warning: `zmatrix` (example "example_energy") generated 1 warning (run `cargo fix --example "example_energy"` to apply 1 suggestion) -warning: unused import: `Energy` - --> examples/example_torque.rs:1:49 - | -1 | use zmatrix::physics::basic::{Torque, Distance, Energy, PhysicalQuantity}; - | ^^^^^^ - | - = note: `#[warn(unused_imports)]` on by default - -warning: unused imports: `Energy`, `MagneticInduction`, `Mass`, `Power`, `Torque`, `VectorQuantity`, and `Volume` - --> examples/example_vector_quantity_restriction.rs:1:31 - | -1 | use zmatrix::physics::basic::{VectorQuantity, Distance, Velocity, Force, Torque, MagneticInduction, Vector3, Mass, Energy, Power, Volume}; - | ^^^^^^^^^^^^^^ ^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^ ^^^^^ ^^^^^^ - | - = note: `#[warn(unused_imports)]` on by default - -warning: `zmatrix` (example "example_vector_quantity_restriction") generated 1 warning (run `cargo fix --example "example_vector_quantity_restriction"` to apply 1 suggestion) -warning: `zmatrix` (example "example_torque") generated 1 warning (run `cargo fix --example "example_torque"` to apply 1 suggestion) warning: unused import: `rayon::prelude` --> src/dense/operation.rs:5:5 | @@ -642,6 +628,19 @@ warning: unused variable: `d` 618 | let d = g.as_any().downcast_ref::().unwrap(); | ^ help: if this is intentional, prefix it with an underscore: `_d` +warning: `zmatrix` (example "examples_dense") generated 2 warnings (run `cargo fix --example "examples_dense"` to apply 1 suggestion) +warning: `zmatrix` (example "example_magnetic_moment") generated 1 warning (run `cargo fix --example "example_magnetic_moment"` to apply 1 suggestion) +warning: `zmatrix` (example "example_vector_quantity_restriction") generated 1 warning (run `cargo fix --example "example_vector_quantity_restriction"` to apply 1 suggestion) +warning: `zmatrix` (example "example_torque") generated 1 warning (run `cargo fix --example "example_torque"` to apply 1 suggestion) +warning: `zmatrix` (example "example_physics") generated 6 warnings +warning: unused import: `Acceleration` + --> examples/example_energy.rs:1:65 + | +1 | use zmatrix::physics::basic::{Energy, Distance, Mass, Velocity, Acceleration, PhysicalQuantity}; + | ^^^^^^^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + warning: function `test_norm_square_basic` is never used --> src/physics/basic/vector.rs:1057:8 | @@ -660,8 +659,9 @@ warning: variable `delta_B` should have a snake case name 1622 | let delta_B = b - b_prev; | ^^^^^^^ help: convert the identifier to snake case: `delta_b` +warning: `zmatrix` (example "example_energy") generated 1 warning (run `cargo fix --example "example_energy"` to apply 1 suggestion) warning: `zmatrix` (lib test) generated 75 warnings (40 duplicates) (run `cargo fix --lib -p zmatrix --tests` to apply 3 suggestions) - Finished `test` profile [unoptimized + debuginfo] target(s) in 1.80s + Finished `test` profile [unoptimized + debuginfo] target(s) in 1.47s Running unittests src/lib.rs (target/debug/deps/zmatrix-0317ef656e62916a) Doc-tests zmatrix warning: variant `g` should have an upper camel case name diff --git a/src/physics/basic/vector/angular_velocity.rs b/src/physics/basic/vector/angular_velocity.rs index 610529a..0eb2d81 100644 --- a/src/physics/basic/vector/angular_velocity.rs +++ b/src/physics/basic/vector/angular_velocity.rs @@ -392,18 +392,29 @@ mod test { fn test_from_array_with_unit() { // 测试从数组和单位类型创建角速度向量 let array = [1.0, 2.0, 3.0]; - let angular_velocity_vec = Vector3::::from_array_with_unit(array, AngularVelocityType::RadperSecond); + // 测试 RadperSecond 单位 + let angular_velocity_vec = Vector3::::from_array_with_unit(array, AngularVelocityType::RadperSecond); assert_relative_eq!(angular_velocity_vec.x.as_rad_per_second(), 1.0); assert_relative_eq!(angular_velocity_vec.y.as_rad_per_second(), 2.0); assert_relative_eq!(angular_velocity_vec.z.as_rad_per_second(), 3.0); - // 测试不同单位类型 - let array = [57.2958, 114.5916, 171.8873]; - let angular_velocity_vec = Vector3::::from_array_with_unit(array, AngularVelocityType::DegPerSecond); + // 测试 DegPerSecond 单位 + let angular_velocity_vec_deg = Vector3::::from_array_with_unit(array, AngularVelocityType::DegPerSecond); + assert_relative_eq!(angular_velocity_vec_deg.x.as_deg_per_second(), 1.0); + assert_relative_eq!(angular_velocity_vec_deg.y.as_deg_per_second(), 2.0); + assert_relative_eq!(angular_velocity_vec_deg.z.as_deg_per_second(), 3.0); - assert_relative_eq!(angular_velocity_vec.x.as_deg_per_second(), 57.2958); - assert_relative_eq!(angular_velocity_vec.y.as_deg_per_second(), 114.5916); - assert_relative_eq!(angular_velocity_vec.z.as_deg_per_second(), 171.8873); + // 测试 RadperHour 单位 + let angular_velocity_vec_rad_hour = Vector3::::from_array_with_unit(array, AngularVelocityType::RadperHour); + assert_relative_eq!(angular_velocity_vec_rad_hour.x.as_rad_per_hour(), 1.0); + assert_relative_eq!(angular_velocity_vec_rad_hour.y.as_rad_per_hour(), 2.0); + assert_relative_eq!(angular_velocity_vec_rad_hour.z.as_rad_per_hour(), 3.0); + + // 测试 DegperHour 单位 + let angular_velocity_vec_deg_hour = Vector3::::from_array_with_unit(array, AngularVelocityType::DegperHour); + assert_relative_eq!(angular_velocity_vec_deg_hour.x.as_deg_per_hour(), 1.0); + assert_relative_eq!(angular_velocity_vec_deg_hour.y.as_deg_per_hour(), 2.0); + assert_relative_eq!(angular_velocity_vec_deg_hour.z.as_deg_per_hour(), 3.0); } } \ No newline at end of file diff --git a/src/physics/basic/vector/magnetic_angular_velocity.rs b/src/physics/basic/vector/magnetic_angular_velocity.rs index b7da1a2..b0af5da 100644 --- a/src/physics/basic/vector/magnetic_angular_velocity.rs +++ b/src/physics/basic/vector/magnetic_angular_velocity.rs @@ -1633,6 +1633,8 @@ mod tests { fn test_from_array_with_unit() { // 测试从数组和单位类型创建磁角速度向量 let array = [1.0, 2.0, 3.0]; + + // 测试 TeslaRadPerSecond 单位 let magnetic_angular_velocity_vec = Vector3::::from_array_with_unit( array, @@ -1652,7 +1654,7 @@ mod tests { 3.0 ); - // 测试不同单位类型 + // 测试 MillTeslaRadPerSecond 单位 let array = [1000.0, 2000.0, 3000.0]; let magnetic_angular_velocity_vec = Vector3::::from_array_with_unit( @@ -1679,7 +1681,61 @@ mod tests { 3000.0 ); - // 测试高斯单位 + // 测试 MicroTeslaRadPerSecond 单位 + let array = [1000000.0, 2000000.0, 3000000.0]; + let magnetic_angular_velocity_vec = + Vector3::::from_array_with_unit( + array, + MagneticAngularVelocityType::MicroTeslaRadPerSecond, + ); + + assert_relative_eq!( + magnetic_angular_velocity_vec + .x + .as_micro_tesla_rad_per_second(), + 1000000.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec + .y + .as_micro_tesla_rad_per_second(), + 2000000.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec + .z + .as_micro_tesla_rad_per_second(), + 3000000.0 + ); + + // 测试 NanoTeslaRadPerSecond 单位 + let array = [1000000000.0, 2000000000.0, 3000000000.0]; + let magnetic_angular_velocity_vec = + Vector3::::from_array_with_unit( + array, + MagneticAngularVelocityType::NanoTeslaRadPerSecond, + ); + + assert_relative_eq!( + magnetic_angular_velocity_vec + .x + .as_nano_tesla_rad_per_second(), + 1000000000.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec + .y + .as_nano_tesla_rad_per_second(), + 2000000000.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec + .z + .as_nano_tesla_rad_per_second(), + 3000000000.0 + ); + + // 测试 GaussRadPerSecond 单位 let array = [10000.0, 20000.0, 30000.0]; let magnetic_angular_velocity_vec = Vector3::::from_array_with_unit( @@ -1699,5 +1755,59 @@ mod tests { magnetic_angular_velocity_vec.z.as_gauss_rad_per_second(), 30000.0 ); + + // 测试 MillGaussRadPerSecond 单位 + let array = [10000000.0, 20000000.0, 30000000.0]; + let magnetic_angular_velocity_vec = + Vector3::::from_array_with_unit( + array, + MagneticAngularVelocityType::MillGaussRadPerSecond, + ); + + assert_relative_eq!( + magnetic_angular_velocity_vec + .x + .as_mill_gauss_rad_per_second(), + 10000000.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec + .y + .as_mill_gauss_rad_per_second(), + 20000000.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec + .z + .as_mill_gauss_rad_per_second(), + 30000000.0 + ); + + // 测试 KiloGaussRadPerSecond 单位 + let array = [10.0, 20.0, 30.0]; + let magnetic_angular_velocity_vec = + Vector3::::from_array_with_unit( + array, + MagneticAngularVelocityType::KiloGaussRadPerSecond, + ); + + assert_relative_eq!( + magnetic_angular_velocity_vec + .x + .as_kilo_gauss_rad_per_second(), + 10.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec + .y + .as_kilo_gauss_rad_per_second(), + 20.0 + ); + assert_relative_eq!( + magnetic_angular_velocity_vec + .z + .as_kilo_gauss_rad_per_second(), + 30.0 + ); } } diff --git a/src/physics/basic/vector/magnetic_induction.rs b/src/physics/basic/vector/magnetic_induction.rs index 92d4139..ab018cf 100644 --- a/src/physics/basic/vector/magnetic_induction.rs +++ b/src/physics/basic/vector/magnetic_induction.rs @@ -422,26 +422,53 @@ mod tests { fn test_from_array_with_unit() { // 测试从数组和单位类型创建磁感应向量 let array = [1.0, 2.0, 3.0]; - let magnetic_induction_vec = Vector3::::from_array_with_unit(array, MagneticInductionType::Tesla); + // 测试 Tesla 单位 + let magnetic_induction_vec = Vector3::::from_array_with_unit(array, MagneticInductionType::Tesla); assert_relative_eq!(magnetic_induction_vec.x.as_tesla(), 1.0); assert_relative_eq!(magnetic_induction_vec.y.as_tesla(), 2.0); assert_relative_eq!(magnetic_induction_vec.z.as_tesla(), 3.0); - // 测试不同单位类型 + // 测试 Gauss 单位 let array = [10000.0, 20000.0, 30000.0]; let magnetic_induction_vec = Vector3::::from_array_with_unit(array, MagneticInductionType::Gauss); - assert_relative_eq!(magnetic_induction_vec.x.as_gauss(), 10000.0); assert_relative_eq!(magnetic_induction_vec.y.as_gauss(), 20000.0); assert_relative_eq!(magnetic_induction_vec.z.as_gauss(), 30000.0); - // 测试毫特斯拉单位 + // 测试 MillTesla 单位 let array = [1000.0, 2000.0, 3000.0]; let magnetic_induction_vec = Vector3::::from_array_with_unit(array, MagneticInductionType::MillTesla); - assert_relative_eq!(magnetic_induction_vec.x.as_milli_tesla(), 1000.0); assert_relative_eq!(magnetic_induction_vec.y.as_milli_tesla(), 2000.0); assert_relative_eq!(magnetic_induction_vec.z.as_milli_tesla(), 3000.0); + + // 测试 MicroTesla 单位 + let array = [1000000.0, 2000000.0, 3000000.0]; + let magnetic_induction_vec = Vector3::::from_array_with_unit(array, MagneticInductionType::MicroTesla); + assert_relative_eq!(magnetic_induction_vec.x.as_micro_tesla(), 1000000.0); + assert_relative_eq!(magnetic_induction_vec.y.as_micro_tesla(), 2000000.0); + assert_relative_eq!(magnetic_induction_vec.z.as_micro_tesla(), 3000000.0); + + // 测试 NanoTesla 单位 + let array = [1000000000.0, 2000000000.0, 3000000000.0]; + let magnetic_induction_vec = Vector3::::from_array_with_unit(array, MagneticInductionType::NanoTesla); + assert_relative_eq!(magnetic_induction_vec.x.as_nano_tesla(), 1000000000.0); + assert_relative_eq!(magnetic_induction_vec.y.as_nano_tesla(), 2000000000.0); + assert_relative_eq!(magnetic_induction_vec.z.as_nano_tesla(), 3000000000.0); + + // 测试 MillGauss 单位 + let array = [10000000.0, 20000000.0, 30000000.0]; + let magnetic_induction_vec = Vector3::::from_array_with_unit(array, MagneticInductionType::MillGauss); + assert_relative_eq!(magnetic_induction_vec.x.as_mill_gauss(), 10000000.0); + assert_relative_eq!(magnetic_induction_vec.y.as_mill_gauss(), 20000000.0); + assert_relative_eq!(magnetic_induction_vec.z.as_mill_gauss(), 30000000.0); + + // 测试 KiloGauss 单位 + let array = [10.0, 20.0, 30.0]; + let magnetic_induction_vec = Vector3::::from_array_with_unit(array, MagneticInductionType::KiloGauss); + assert_relative_eq!(magnetic_induction_vec.x.as_kilo_gauss(), 10.0); + assert_relative_eq!(magnetic_induction_vec.y.as_kilo_gauss(), 20.0); + assert_relative_eq!(magnetic_induction_vec.z.as_kilo_gauss(), 30.0); } } diff --git a/src/physics/basic/vector/magnetic_moment.rs b/src/physics/basic/vector/magnetic_moment.rs index 68a57c7..e3ed392 100644 --- a/src/physics/basic/vector/magnetic_moment.rs +++ b/src/physics/basic/vector/magnetic_moment.rs @@ -183,6 +183,97 @@ mod tests { assert_relative_eq!(coef_vec.z.get_value(), 3.0, epsilon = 1e-10); } + #[test] + fn test_to_vector3_coef_mill_am2() { + let magnetic_moment_vec = Vector3::new( + MagneticMoment::from_mill_am2(1000.0), + MagneticMoment::from_mill_am2(2000.0), + MagneticMoment::from_mill_am2(3000.0), + ); + let coef_vec = magnetic_moment_vec.to_vector3_coef(MagneticMomentType::MillAM2); + assert_relative_eq!(coef_vec.x.get_value(), 1000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.y.get_value(), 2000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.z.get_value(), 3000.0, epsilon = 1e-10); + } + + #[test] + fn test_to_vector3_coef_micro_am2() { + let magnetic_moment_vec = Vector3::new( + MagneticMoment::from_micro_am2(1000000.0), + MagneticMoment::from_micro_am2(2000000.0), + MagneticMoment::from_micro_am2(3000000.0), + ); + let coef_vec = magnetic_moment_vec.to_vector3_coef(MagneticMomentType::MicroAM2); + assert_relative_eq!(coef_vec.x.get_value(), 1000000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.y.get_value(), 2000000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.z.get_value(), 3000000.0, epsilon = 1e-10); + } + + #[test] + fn test_to_vector3_coef_nano_am2() { + let magnetic_moment_vec = Vector3::new( + MagneticMoment::from_nano_am2(1000000000.0), + MagneticMoment::from_nano_am2(2000000000.0), + MagneticMoment::from_nano_am2(3000000000.0), + ); + let coef_vec = magnetic_moment_vec.to_vector3_coef(MagneticMomentType::NanoAM2); + assert_relative_eq!(coef_vec.x.get_value(), 1000000000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.y.get_value(), 2000000000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.z.get_value(), 3000000000.0, epsilon = 1e-10); + } + + #[test] + fn test_to_vector3_coef_j_per_tesla() { + let magnetic_moment_vec = Vector3::new( + MagneticMoment::from_j_per_tesla(1.0), + MagneticMoment::from_j_per_tesla(2.0), + MagneticMoment::from_j_per_tesla(3.0), + ); + let coef_vec = magnetic_moment_vec.to_vector3_coef(MagneticMomentType::JPerTesla); + assert_relative_eq!(coef_vec.x.get_value(), 1.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.y.get_value(), 2.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.z.get_value(), 3.0, epsilon = 1e-10); + } + + #[test] + fn test_to_vector3_coef_mill_j_per_tesla() { + let magnetic_moment_vec = Vector3::new( + MagneticMoment::from_mill_j_per_tesla(1000.0), + MagneticMoment::from_mill_j_per_tesla(2000.0), + MagneticMoment::from_mill_j_per_tesla(3000.0), + ); + let coef_vec = magnetic_moment_vec.to_vector3_coef(MagneticMomentType::MillJPerTesla); + assert_relative_eq!(coef_vec.x.get_value(), 1000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.y.get_value(), 2000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.z.get_value(), 3000.0, epsilon = 1e-10); + } + + #[test] + fn test_to_vector3_coef_micro_j_per_tesla() { + let magnetic_moment_vec = Vector3::new( + MagneticMoment::from_micro_j_per_tesla(1000000.0), + MagneticMoment::from_micro_j_per_tesla(2000000.0), + MagneticMoment::from_micro_j_per_tesla(3000000.0), + ); + let coef_vec = magnetic_moment_vec.to_vector3_coef(MagneticMomentType::MicroJPerTesla); + assert_relative_eq!(coef_vec.x.get_value(), 1000000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.y.get_value(), 2000000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.z.get_value(), 3000000.0, epsilon = 1e-10); + } + + #[test] + fn test_to_vector3_coef_nano_j_per_tesla() { + let magnetic_moment_vec = Vector3::new( + MagneticMoment::from_nano_j_per_tesla(1000000000.0), + MagneticMoment::from_nano_j_per_tesla(2000000000.0), + MagneticMoment::from_nano_j_per_tesla(3000000000.0), + ); + let coef_vec = magnetic_moment_vec.to_vector3_coef(MagneticMomentType::NanoJPerTesla); + assert_relative_eq!(coef_vec.x.get_value(), 1000000000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.y.get_value(), 2000000000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.z.get_value(), 3000000000.0, epsilon = 1e-10); + } + #[test] fn test_from_vector_coef_am2() { let coef_vec = Vector3::new(Coef::new(1.0), Coef::new(2.0), Coef::new(3.0)); @@ -478,6 +569,22 @@ mod tests { assert_relative_eq!(magnetic_moment_vec.y.as_mill_am2(), 2000.0); assert_relative_eq!(magnetic_moment_vec.z.as_mill_am2(), 3000.0); + // 测试微安平方米单位 + let array = [1000000.0, 2000000.0, 3000000.0]; + let magnetic_moment_vec = Vector3::::from_array_with_unit(array, MagneticMomentType::MicroAM2); + + assert_relative_eq!(magnetic_moment_vec.x.as_micro_am2(), 1000000.0); + assert_relative_eq!(magnetic_moment_vec.y.as_micro_am2(), 2000000.0); + assert_relative_eq!(magnetic_moment_vec.z.as_micro_am2(), 3000000.0); + + // 测试纳安平方米单位 + let array = [1000000000.0, 2000000000.0, 3000000000.0]; + let magnetic_moment_vec = Vector3::::from_array_with_unit(array, MagneticMomentType::NanoAM2); + + assert_relative_eq!(magnetic_moment_vec.x.as_nano_am2(), 1000000000.0); + assert_relative_eq!(magnetic_moment_vec.y.as_nano_am2(), 2000000000.0); + assert_relative_eq!(magnetic_moment_vec.z.as_nano_am2(), 3000000000.0); + // 测试焦耳每特斯拉单位 let array = [1.0, 2.0, 3.0]; let magnetic_moment_vec = Vector3::::from_array_with_unit(array, MagneticMomentType::JPerTesla); @@ -485,5 +592,29 @@ mod tests { assert_relative_eq!(magnetic_moment_vec.x.as_j_per_tesla(), 1.0); assert_relative_eq!(magnetic_moment_vec.y.as_j_per_tesla(), 2.0); assert_relative_eq!(magnetic_moment_vec.z.as_j_per_tesla(), 3.0); + + // 测试毫焦耳每特斯拉单位 + let array = [1000.0, 2000.0, 3000.0]; + let magnetic_moment_vec = Vector3::::from_array_with_unit(array, MagneticMomentType::MillJPerTesla); + + assert_relative_eq!(magnetic_moment_vec.x.as_mill_j_per_tesla(), 1000.0); + assert_relative_eq!(magnetic_moment_vec.y.as_mill_j_per_tesla(), 2000.0); + assert_relative_eq!(magnetic_moment_vec.z.as_mill_j_per_tesla(), 3000.0); + + // 测试微焦耳每特斯拉单位 + let array = [1000000.0, 2000000.0, 3000000.0]; + let magnetic_moment_vec = Vector3::::from_array_with_unit(array, MagneticMomentType::MicroJPerTesla); + + assert_relative_eq!(magnetic_moment_vec.x.as_micro_j_per_tesla(), 1000000.0); + assert_relative_eq!(magnetic_moment_vec.y.as_micro_j_per_tesla(), 2000000.0); + assert_relative_eq!(magnetic_moment_vec.z.as_micro_j_per_tesla(), 3000000.0); + + // 测试纳焦耳每特斯拉单位 + let array = [1000000000.0, 2000000000.0, 3000000000.0]; + let magnetic_moment_vec = Vector3::::from_array_with_unit(array, MagneticMomentType::NanoJPerTesla); + + assert_relative_eq!(magnetic_moment_vec.x.as_nano_j_per_tesla(), 1000000000.0); + assert_relative_eq!(magnetic_moment_vec.y.as_nano_j_per_tesla(), 2000000000.0); + assert_relative_eq!(magnetic_moment_vec.z.as_nano_j_per_tesla(), 3000000000.0); } } From 3f4eaa2e5882709d289b79ed34de63f12280f64f Mon Sep 17 00:00:00 2001 From: Treagzhao <920866163@qq.com> Date: Tue, 10 Mar 2026 10:53:16 +0800 Subject: [PATCH 5/5] Complete test coverage for torque.rs --- 1.txt | 90 +++++++++++++++--------------- src/physics/basic/vector/torque.rs | 89 +++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 45 deletions(-) diff --git a/1.txt b/1.txt index 6a8725c..7644796 100644 --- a/1.txt +++ b/1.txt @@ -345,11 +345,19 @@ warning: method `T` should have a snake case name = note: `#[warn(non_snake_case)]` on by default warning: `zmatrix` (lib) generated 53 warnings (run `cargo fix --lib -p zmatrix` to apply 39 suggestions) -warning: unused imports: `Energy`, `MagneticInduction`, `Mass`, `Power`, `Torque`, `VectorQuantity`, and `Volume` - --> examples/example_vector_quantity_restriction.rs:1:31 +warning: unused import: `Energy` + --> examples/example_torque.rs:1:49 | -1 | use zmatrix::physics::basic::{VectorQuantity, Distance, Velocity, Force, Torque, MagneticInduction, Vector3, Mass, Energy, Power, Volume}; - | ^^^^^^^^^^^^^^ ^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^ ^^^^^ ^^^^^^ +1 | use zmatrix::physics::basic::{Torque, Distance, Energy, PhysicalQuantity}; + | ^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: unused import: `Acceleration` + --> examples/example_energy.rs:1:65 + | +1 | use zmatrix::physics::basic::{Energy, Distance, Mass, Velocity, Acceleration, PhysicalQuantity}; + | ^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default @@ -401,14 +409,6 @@ warning: function `exmples_vector3` is never used 32 | fn exmples_vector3(){ | ^^^^^^^^^^^^^^^ -warning: unused import: `Energy` - --> examples/example_torque.rs:1:49 - | -1 | use zmatrix::physics::basic::{Torque, Distance, Energy, PhysicalQuantity}; - | ^^^^^^ - | - = note: `#[warn(unused_imports)]` on by default - warning: unused import: `Area` --> src/physics/basic/magnetic_moment.rs:342:52 | @@ -435,27 +435,6 @@ warning: duplicated attribute 51 | #[test] | ^^^^^^^ -warning: unused import: `zmatrix::dense` - --> examples/examples_dense.rs:1:5 - | -1 | use zmatrix::dense; - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(unused_imports)]` on by default - -warning: unused `Result` that must be used - --> examples/examples_dense.rs:61:5 - | -61 | m1.set(1, 1, 12); - | ^^^^^^^^^^^^^^^^ - | - = note: this `Result` may be an `Err` variant, which should be handled - = note: `#[warn(unused_must_use)]` on by default -help: use `let _ = ...` to ignore the resulting value - | -61 | let _ = m1.set(1, 1, 12); - | +++++++ - warning: unused import: `rayon::prelude` --> src/dense/operation.rs:5:5 | @@ -628,40 +607,61 @@ warning: unused variable: `d` 618 | let d = g.as_any().downcast_ref::().unwrap(); | ^ help: if this is intentional, prefix it with an underscore: `_d` -warning: `zmatrix` (example "examples_dense") generated 2 warnings (run `cargo fix --example "examples_dense"` to apply 1 suggestion) warning: `zmatrix` (example "example_magnetic_moment") generated 1 warning (run `cargo fix --example "example_magnetic_moment"` to apply 1 suggestion) -warning: `zmatrix` (example "example_vector_quantity_restriction") generated 1 warning (run `cargo fix --example "example_vector_quantity_restriction"` to apply 1 suggestion) +warning: `zmatrix` (example "example_energy") generated 1 warning (run `cargo fix --example "example_energy"` to apply 1 suggestion) warning: `zmatrix` (example "example_torque") generated 1 warning (run `cargo fix --example "example_torque"` to apply 1 suggestion) warning: `zmatrix` (example "example_physics") generated 6 warnings -warning: unused import: `Acceleration` - --> examples/example_energy.rs:1:65 - | -1 | use zmatrix::physics::basic::{Energy, Distance, Mass, Velocity, Acceleration, PhysicalQuantity}; - | ^^^^^^^^^^^^ - | - = note: `#[warn(unused_imports)]` on by default - warning: function `test_norm_square_basic` is never used --> src/physics/basic/vector.rs:1057:8 | 1057 | fn test_norm_square_basic() { | ^^^^^^^^^^^^^^^^^^^^^^ +warning: unused imports: `Energy`, `MagneticInduction`, `Mass`, `Power`, `Torque`, `VectorQuantity`, and `Volume` + --> examples/example_vector_quantity_restriction.rs:1:31 + | +1 | use zmatrix::physics::basic::{VectorQuantity, Distance, Velocity, Force, Torque, MagneticInduction, Vector3, Mass, Energy, Power, Volume}; + | ^^^^^^^^^^^^^^ ^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^ ^^^^^ ^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + warning: function `test_T` should have a snake case name --> src/dense/shape.rs:110:8 | 110 | fn test_T() { | ^^^^^^ help: convert the identifier to snake case: `test_t` +warning: unused import: `zmatrix::dense` + --> examples/examples_dense.rs:1:5 + | +1 | use zmatrix::dense; + | ^^^^^^^^^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: unused `Result` that must be used + --> examples/examples_dense.rs:61:5 + | +61 | m1.set(1, 1, 12); + | ^^^^^^^^^^^^^^^^ + | + = note: this `Result` may be an `Err` variant, which should be handled + = note: `#[warn(unused_must_use)]` on by default +help: use `let _ = ...` to ignore the resulting value + | +61 | let _ = m1.set(1, 1, 12); + | +++++++ + warning: variable `delta_B` should have a snake case name --> src/physics/basic/vector/magnetic_angular_velocity.rs:1622:13 | 1622 | let delta_B = b - b_prev; | ^^^^^^^ help: convert the identifier to snake case: `delta_b` -warning: `zmatrix` (example "example_energy") generated 1 warning (run `cargo fix --example "example_energy"` to apply 1 suggestion) +warning: `zmatrix` (example "example_vector_quantity_restriction") generated 1 warning (run `cargo fix --example "example_vector_quantity_restriction"` to apply 1 suggestion) +warning: `zmatrix` (example "examples_dense") generated 2 warnings (run `cargo fix --example "examples_dense"` to apply 1 suggestion) warning: `zmatrix` (lib test) generated 75 warnings (40 duplicates) (run `cargo fix --lib -p zmatrix --tests` to apply 3 suggestions) - Finished `test` profile [unoptimized + debuginfo] target(s) in 1.47s + Finished `test` profile [unoptimized + debuginfo] target(s) in 1.33s Running unittests src/lib.rs (target/debug/deps/zmatrix-0317ef656e62916a) Doc-tests zmatrix warning: variant `g` should have an upper camel case name diff --git a/src/physics/basic/vector/torque.rs b/src/physics/basic/vector/torque.rs index 8ce21da..260880e 100644 --- a/src/physics/basic/vector/torque.rs +++ b/src/physics/basic/vector/torque.rs @@ -147,6 +147,71 @@ mod tests { assert_relative_eq!(coef_vec.z.get_value(), 3.0, epsilon = 1e-10); } + #[test] + fn test_to_vector3_coef_mill_nm() { + let torque_vec = Vector3::new( + Torque::from_mill_nm(1000.0), + Torque::from_mill_nm(2000.0), + Torque::from_mill_nm(3000.0), + ); + let coef_vec = torque_vec.to_vector3_coef(TorqueType::MillNM); + assert_relative_eq!(coef_vec.x.get_value(), 1000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.y.get_value(), 2000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.z.get_value(), 3000.0, epsilon = 1e-10); + } + + #[test] + fn test_to_vector3_coef_micro_nm() { + let torque_vec = Vector3::new( + Torque::from_micro_nm(1000000.0), + Torque::from_micro_nm(2000000.0), + Torque::from_micro_nm(3000000.0), + ); + let coef_vec = torque_vec.to_vector3_coef(TorqueType::MicroNM); + assert_relative_eq!(coef_vec.x.get_value(), 1000000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.y.get_value(), 2000000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.z.get_value(), 3000000.0, epsilon = 1e-10); + } + + #[test] + fn test_to_vector3_coef_nano_nm() { + let torque_vec = Vector3::new( + Torque::from_nano_nm(1000000000.0), + Torque::from_nano_nm(2000000000.0), + Torque::from_nano_nm(3000000000.0), + ); + let coef_vec = torque_vec.to_vector3_coef(TorqueType::NanoNM); + assert_relative_eq!(coef_vec.x.get_value(), 1000000000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.y.get_value(), 2000000000.0, epsilon = 1e-10); + assert_relative_eq!(coef_vec.z.get_value(), 3000000000.0, epsilon = 1e-10); + } + + #[test] + fn test_to_vector3_coef_knm() { + let torque_vec = Vector3::new( + Torque::from_knm(0.001), + Torque::from_knm(0.002), + Torque::from_knm(0.003), + ); + let coef_vec = torque_vec.to_vector3_coef(TorqueType::KNM); + assert_relative_eq!(coef_vec.x.get_value(), 0.001, epsilon = 1e-10); + assert_relative_eq!(coef_vec.y.get_value(), 0.002, epsilon = 1e-10); + assert_relative_eq!(coef_vec.z.get_value(), 0.003, epsilon = 1e-10); + } + + #[test] + fn test_to_vector3_coef_mnm() { + let torque_vec = Vector3::new( + Torque::from_mnm(0.000001), + Torque::from_mnm(0.000002), + Torque::from_mnm(0.000003), + ); + let coef_vec = torque_vec.to_vector3_coef(TorqueType::MNM); + assert_relative_eq!(coef_vec.x.get_value(), 0.000001, epsilon = 1e-10); + assert_relative_eq!(coef_vec.y.get_value(), 0.000002, epsilon = 1e-10); + assert_relative_eq!(coef_vec.z.get_value(), 0.000003, epsilon = 1e-10); + } + #[test] fn test_from_vector_coef_nm() { let coef_vec = Vector3::new(Coef::new(1.0), Coef::new(2.0), Coef::new(3.0)); @@ -350,6 +415,22 @@ mod tests { assert_relative_eq!(torque_vec.y.as_mill_nm(), 2000.0); assert_relative_eq!(torque_vec.z.as_mill_nm(), 3000.0); + // 测试微牛米单位 + let array = [1000000.0, 2000000.0, 3000000.0]; + let torque_vec = Vector3::::from_array_with_unit(array, TorqueType::MicroNM); + + assert_relative_eq!(torque_vec.x.as_micro_nm(), 1000000.0); + assert_relative_eq!(torque_vec.y.as_micro_nm(), 2000000.0); + assert_relative_eq!(torque_vec.z.as_micro_nm(), 3000000.0); + + // 测试纳牛米单位 + let array = [1000000000.0, 2000000000.0, 3000000000.0]; + let torque_vec = Vector3::::from_array_with_unit(array, TorqueType::NanoNM); + + assert_relative_eq!(torque_vec.x.as_nano_nm(), 1000000000.0); + assert_relative_eq!(torque_vec.y.as_nano_nm(), 2000000000.0); + assert_relative_eq!(torque_vec.z.as_nano_nm(), 3000000000.0); + // 测试千牛米单位 let array = [0.001, 0.002, 0.003]; let torque_vec = Vector3::::from_array_with_unit(array, TorqueType::KNM); @@ -357,5 +438,13 @@ mod tests { assert_relative_eq!(torque_vec.x.as_knm(), 0.001); assert_relative_eq!(torque_vec.y.as_knm(), 0.002); assert_relative_eq!(torque_vec.z.as_knm(), 0.003); + + // 测试兆牛米单位 + let array = [0.000001, 0.000002, 0.000003]; + let torque_vec = Vector3::::from_array_with_unit(array, TorqueType::MNM); + + assert_relative_eq!(torque_vec.x.as_mnm(), 0.000001); + assert_relative_eq!(torque_vec.y.as_mnm(), 0.000002); + assert_relative_eq!(torque_vec.z.as_mnm(), 0.000003); } }