|
45 | 45 | unsafe_code
|
46 | 46 | )]
|
47 | 47 |
|
| 48 | +use alloc::{vec, vec::Vec}; |
48 | 49 | use core::ptr::{self, null_mut};
|
49 | 50 |
|
50 | 51 | use glam::Vec3;
|
@@ -211,7 +212,7 @@ pub unsafe fn genTangSpace<I: Geometry>(geometry: &mut I, fAngularThreshold: f32
|
211 | 212 | let mut index = 0;
|
212 | 213 | let iNrFaces = geometry.num_faces();
|
213 | 214 | let mut bRes: bool = false;
|
214 |
| - let fThresCos = fAngularThreshold.to_radians().cos(); |
| 215 | + let fThresCos = cos(fAngularThreshold.to_radians()); |
215 | 216 | f = 0;
|
216 | 217 | while f < iNrFaces {
|
217 | 218 | let verts = geometry.num_vertices_of_face(f);
|
@@ -630,7 +631,7 @@ unsafe fn VNotZero(v: Vec3) -> bool {
|
630 | 631 | }
|
631 | 632 |
|
632 | 633 | unsafe fn NotZero(fX: f32) -> bool {
|
633 |
| - fX.abs() > 1.17549435e-38f32 |
| 634 | + abs(fX) > 1.17549435e-38f32 |
634 | 635 | }
|
635 | 636 |
|
636 | 637 | unsafe fn EvalTspace<I: Geometry>(
|
@@ -724,7 +725,7 @@ unsafe fn EvalTspace<I: Geometry>(
|
724 | 725 | } else {
|
725 | 726 | fCos
|
726 | 727 | };
|
727 |
| - fAngle = (fCos as f64).acos() as f32; |
| 728 | + fAngle = acosf64(fCos as f64) as f32; |
728 | 729 | fMagS = (*pTriInfos.offset(f as isize)).fMagS;
|
729 | 730 | fMagT = (*pTriInfos.offset(f as isize)).fMagT;
|
730 | 731 | res.vOs = res.vOs + (fAngle * vOs);
|
@@ -1010,7 +1011,7 @@ unsafe fn InitTriInfo<I: Geometry>(
|
1010 | 1011 | 0i32
|
1011 | 1012 | };
|
1012 | 1013 | if NotZero(fSignedAreaSTx2) {
|
1013 |
| - let fAbsArea: f32 = fSignedAreaSTx2.abs(); |
| 1014 | + let fAbsArea: f32 = abs(fSignedAreaSTx2); |
1014 | 1015 | let fLenOs: f32 = vOs.length();
|
1015 | 1016 | let fLenOt: f32 = vOt.length();
|
1016 | 1017 | let fS: f32 = if (*pTriInfos.offset(f as isize)).iFlag & 8i32 == 0i32 {
|
@@ -1808,3 +1809,63 @@ unsafe fn GenerateInitialVerticesIndexList<I: Geometry>(
|
1808 | 1809 | }
|
1809 | 1810 | return iTSpacesOffs;
|
1810 | 1811 | }
|
| 1812 | + |
| 1813 | +fn cos(value: f32) -> f32 { |
| 1814 | + #[cfg(feature = "std")] |
| 1815 | + { |
| 1816 | + value.cos() |
| 1817 | + } |
| 1818 | + #[cfg(all(not(feature = "std"), feature = "libm"))] |
| 1819 | + { |
| 1820 | + libm::cosf(value) |
| 1821 | + } |
| 1822 | + #[cfg(all(not(feature = "std"), not(feature = "libm")))] |
| 1823 | + { |
| 1824 | + compile_error!("Require either 'libm' or 'std' for `cos`") |
| 1825 | + } |
| 1826 | +} |
| 1827 | + |
| 1828 | +fn acos(value: f32) -> f32 { |
| 1829 | + #[cfg(feature = "std")] |
| 1830 | + { |
| 1831 | + value.acos() |
| 1832 | + } |
| 1833 | + #[cfg(all(not(feature = "std"), feature = "libm"))] |
| 1834 | + { |
| 1835 | + libm::acosf(value) |
| 1836 | + } |
| 1837 | + #[cfg(all(not(feature = "std"), not(feature = "libm")))] |
| 1838 | + { |
| 1839 | + compile_error!("Require either 'libm' or 'std' for `acos`") |
| 1840 | + } |
| 1841 | +} |
| 1842 | + |
| 1843 | +fn abs(value: f32) -> f32 { |
| 1844 | + #[cfg(feature = "std")] |
| 1845 | + { |
| 1846 | + value.abs() |
| 1847 | + } |
| 1848 | + #[cfg(all(not(feature = "std"), feature = "libm"))] |
| 1849 | + { |
| 1850 | + libm::fabsf(value) |
| 1851 | + } |
| 1852 | + #[cfg(all(not(feature = "std"), not(feature = "libm")))] |
| 1853 | + { |
| 1854 | + compile_error!("Require either 'libm' or 'std' for `abs`") |
| 1855 | + } |
| 1856 | +} |
| 1857 | + |
| 1858 | +fn acosf64(value: f64) -> f64 { |
| 1859 | + #[cfg(feature = "std")] |
| 1860 | + { |
| 1861 | + value.acos() |
| 1862 | + } |
| 1863 | + #[cfg(all(not(feature = "std"), feature = "libm"))] |
| 1864 | + { |
| 1865 | + libm::acos(value) |
| 1866 | + } |
| 1867 | + #[cfg(all(not(feature = "std"), not(feature = "libm")))] |
| 1868 | + { |
| 1869 | + compile_error!("Require either 'libm' or 'std' for `acos`") |
| 1870 | + } |
| 1871 | +} |
0 commit comments