Skip to main content

cad_cs/libs/cs/
abstracts.rs

1// 📃 ./src/libs/cs/abstracts.rs
2
3use std::ops::{Add, Div, Mul, Neg, Sub};
4
5use crate::libs::{angle::AngleFmt, cs::model::Cs};
6
7/// 📚 【 POL】: Kontrakt gwarantujący implementację podstawowych rzutowań 2D.
8/// 📚 【 ENG】: Contract guaranteeing the implementation of basic 2D projections.
9pub trait AbstractProjectionsCs2 {
10	fn new_from_rf(r: f64, phi_rad: f64) -> Self;
11	fn new_as_xy(&self) -> Cs<3>;
12	fn new_as_xz(&self) -> Cs<3>;
13	fn new_as_yz(&self) -> Cs<3>;
14	fn new_as_xy_from_rf(&self) -> Self;
15	fn new_as_xyz_from_rf_with_z(&self, z: f64) -> Cs<3>;
16	fn new_as_xyz_from_rf_with_y(&self, y: f64) -> Cs<3>;
17	fn new_as_xyz_from_rf_with_x(&self, x: f64) -> Cs<3>;
18}
19
20/// 📚 【 POL】: Kontrakt gwarantujący implementację podstawowych rzutowań 3D.
21/// 📚 【 ENG】: Contract guaranteeing the implementation of basic 3D projections.
22pub trait AbstractProjectionsCs3 {
23	fn new_from_rft(r: f64, phi_rad: f64, theta_rad: f64) -> Self;
24	fn new_from_rfz(r_d2: f64, phi_rad: f64, z: f64) -> Self;
25	fn new_from_rfx(r_d2: f64, phi_rad: f64, x: f64) -> Self;
26	fn new_from_rfy(r_d2: f64, phi_rad: f64, y: f64) -> Self;
27	fn new_as_xyz_from_rft(&self) -> Cs<3>;
28}
29
30/// 📚 【 POL】: Kontrakt generyczny dla uniwersalnej matematyki wektorowej (np. dodawanie).
31/// 📚 【 ENG】: Generic contract for universal vector mathematics.
32pub trait AbstractMathCsGeneric {
33	fn sub(&self, other: &Self) -> Self;
34	fn add(&self, other: &Self) -> Self;
35	fn dot(&self, other: &Self) -> f64;
36	fn r_sq(&self) -> f64;
37	fn r(&self) -> f64;
38	fn normalize_r_projection(&self) -> Self;
39	fn angle_between(&self, other: &Self) -> f64;
40}
41
42/// 📚 【 POL】: Kontrakt dla operacji matematycznych specyficznych dla 2D.
43/// 📚 【 ENG】: Contract for 2D-specific mathematical operations.
44pub trait AbstractMathCs2 {
45	fn rxy(&self) -> f64;
46	fn arctan_y_x(&self) -> f64;
47	fn arctan_x_y(&self) -> f64;
48	fn to_rf_from_xy(&self) -> Cs<2>;
49	fn to_ecef_from_rad_sn_we(&self, r: f64) -> Cs<3>;
50	fn q(&self) -> u8;
51	fn q_sign(&self) -> [&'static str; 2];
52	fn rxy_sq(&self) -> f64;
53	fn cross(&self, other: &Cs<2>) -> f64;
54	fn perp(&self) -> Cs<2>;
55}
56
57/// 📚 【 POL】: Kontrakt dla operacji matematycznych specyficznych dla 3D.
58/// 📚 【 ENG】: Contract for 3D-specific mathematical operations.
59pub trait AbstractMathCs3 {
60	fn rxy(&self) -> f64;
61	fn rxz(&self) -> f64;
62	fn ryz(&self) -> f64;
63	fn rxyz(&self) -> f64;
64	fn arctan_y_x(&self) -> f64;
65	fn arctan_z_x(&self) -> f64;
66	fn arctan_z_y(&self) -> f64;
67	fn arctan_x_y(&self) -> f64;
68	fn arctan_x_z(&self) -> f64;
69	fn arctan_y_z(&self) -> f64;
70	fn arccos_x_rxyz(&self) -> f64;
71	fn arccos_y_rxyz(&self) -> f64;
72	fn arccos_z_rxyz(&self) -> f64;
73	fn to_rf_from_xy(&self) -> Cs<2>;
74	fn to_rf_from_xz(&self) -> Cs<2>;
75	fn to_rf_from_yz(&self) -> Cs<2>;
76	fn to_rfx_from_xyz(&self) -> Cs<3>;
77	fn to_rfy_from_xyz(&self) -> Cs<3>;
78	fn to_rfz_from_xyz(&self) -> Cs<3>;
79	fn to_rft_from_xyz(&self) -> Cs<3>;
80	fn to_ecef_from_dms_sn_we(
81		sn_d: i16,
82		sn_m: u8,
83		sn_s: f32,
84		we_d: i16,
85		we_m: u8,
86		we_s: f32,
87		r: f64,
88	) -> Self;
89	fn to_dms_sn_we_from_xyz(&self) -> crate::libs::cs::model::CoordsSphericalEcefSnWeDms;
90	fn q(&self) -> u8;
91	fn q_sign(&self) -> [&'static str; 3];
92	fn rxyz_sq(&self) -> f64;
93	fn rxy_sq(&self) -> f64;
94	fn rxz_sq(&self) -> f64;
95	fn ryz_sq(&self) -> f64;
96	fn normalize_rxy_projection(&self) -> Cs<3>;
97	fn normalize_rxz_projection(&self) -> Cs<3>;
98	fn normalize_ryz_projection(&self) -> Cs<3>;
99	fn cross(&self, other: &Cs<3>) -> Cs<3>;
100}
101
102/// 📚 【 POL】: Kontrakt generyczny dla fundamentalnych operacji modelu` Cs<N>`.
103/// 📚 【 ENG】: Generic contract for fundamental `Cs<N>` model operations.
104pub trait AbstractModelCsGeneric<const N: usize> {
105	fn new(data: [f64; N]) -> Self;
106	fn origin() -> Self;
107	fn as_slice(&self) -> &[f64];
108}
109
110/// 📚 【 POL】: Kontrakt dla pomocniczych funkcji diagnostycznych 2D.
111/// 📚 【 ENG】: Contract for 2D diagnostic helper functions.
112/// 📚 【 POL】: Trait rozszerzający dla `Cs<2>`, umożliwiający formatowanie danych wyjściowych do konsoli.
113/// 📚 【 ENG】: Extension trait for `Cs<2>`, enabling output formatting to the console.
114pub trait AbstractHelperCs2 {
115	/// 📚 【 POL】: Wyświetla informację o ćwiartce i znakach składowych.
116	/// 📚 【 ENG】: Displays quadrant information and component signs.
117	fn print_q(&self, name: &str);
118
119	/// 📚 【 POL】: Wyświetla współrzędne kartezjańskie (X, Y).
120	/// 📚 【 ENG】: Displays Cartesian coordinates (X, Y).
121	fn print_xy(&self, name: &str);
122
123	/// 📚 【 POL】: Wyświetla współrzędne biegunowe (R, Φ).
124	/// 📚 【 ENG】: Displays polar coordinates (R, Φ).
125	fn print_rf(&self, name: &str, fmt: AngleFmt);
126
127	/// 📚 【 POL】: Wyświetla zbiorczy raport debugowania dla wektora 2D.
128	/// 📚 【 ENG】: Displays a summary debug report for the 2D vector.
129	fn print(&self, name: &str, fmt: AngleFmt);
130}
131
132/// 📚 【 POL】: Kontrakt dla pomocniczych funkcji diagnostycznych 3D.
133/// 📚 【 ENG】: Contract for 3D diagnostic helper functions.
134/// 📚 【 POL】: Trait rozszerzający dla `Cs<3>`, umożliwiający zaawansowane formatowanie rzutów i geodezji.
135/// 📚 【 ENG】: Extension trait for `Cs<3>`, enabling advanced formatting for projections and geodesy.
136pub trait AbstractHelperCs3 {
137	fn print_q(&self, name: &str);
138	fn print_xyz(&self, name: &str);
139	fn print_rft(&self, name: &str, fmt: AngleFmt);
140	fn print_rfx(&self, name: &str, fmt: AngleFmt);
141	fn print_rfy(&self, name: &str, fmt: AngleFmt);
142	fn print_rfz(&self, name: &str, fmt: AngleFmt);
143	fn print_dms_sn_we(&self, name: &str);
144	fn print(&self, name: &str, fmt: AngleFmt);
145}
146
147pub trait AbstractArithmeticCsGeneric:
148	Add<Output = Self>
149	+ Sub<Output = Self>
150	+ Neg<Output = Self>
151	+ Mul<f64, Output = Self>
152	+ Div<f64, Output = Self>
153	+ Sized // Zapewnia, że rozmiar jest znany w czasie kompilacji
154{
155	// Deklarujemy metody, które potem implementujesz w math.rs
156	fn add_cs(&self, rhs: &Self) -> Self;
157	fn sub_cs(&self, rhs: &Self) -> Self;
158	fn neg_cs(&self) -> Self;
159	fn mul_scalar(&self, rhs: f64) -> Self;
160	fn div_scalar(&self, rhs: f64) -> Self;
161}
162
163/// 📚 【 POL】: Trait rozszerzający dla typów liczbowych, ułatwiający prezentację znaków kierunkowych.
164/// 📚 【 ENG】: Extension trait for numerical types, facilitating the presentation of directional signs.
165pub trait AbstractSignStrExt {
166	/// 📚 【 POL】: Zwraca "+" dla wartości nieujemnych oraz "-" dla ujemnych.
167	/// 📚 【 ENG】: Returns "+" for non-negative values and "-" for negative ones.
168	fn sign_str(self) -> &'static str;
169
170	/// 📚 【 POL】: Zwraca "N" (Północ) dla wartości nieujemnych oraz "S" (Południe) dla ujemnych.
171	/// 📚 【 ENG】: Returns "N" (North) for non-negative values and "S" (South) for negative ones.
172	fn sign_sn(self) -> &'static str;
173
174	/// 📚 【 POL】: Zwraca "E" (Wschód) dla wartości nieujemnych oraz "W" (Zachód) dla ujemnych.
175	/// 📚 【 ENG】: Returns "E" (East) for non-negative values and "W" (West) for negative ones.
176	fn sign_we(self) -> &'static str;
177}