integer from float
This commit is contained in:
parent
b419f2a321
commit
ed78807a9f
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -22,9 +22,9 @@ checksum = "50202def95bf36cb7d1d7a7962cea1c36a3f8ad42425e5d2b71d7acb8041b5b8"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fixed_wide"
|
name = "fixed_wide"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
||||||
checksum = "7a8d6e10c51c9df39ead915c62288afbc41d13e00368e526037e530ee5c58e13"
|
checksum = "d9c2cf115b3785ede870fada07e8b1aeba3378345b4ca86fe3c772ecabc05c0f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"bnum",
|
"bnum",
|
||||||
|
@ -12,7 +12,7 @@ authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
arrayvec = "0.7.4"
|
arrayvec = "0.7.4"
|
||||||
bitflags = "2.6.0"
|
bitflags = "2.6.0"
|
||||||
fixed_wide = { version = "0.1.0", registry = "strafesnet", features = ["deferred-division","zeroes","wide-mul"] }
|
fixed_wide = { version = "0.1.1", registry = "strafesnet", features = ["deferred-division","zeroes","wide-mul"] }
|
||||||
linear_ops = { version = "0.1.0", registry = "strafesnet", features = ["deferred-division","named-fields"] }
|
linear_ops = { version = "0.1.0", registry = "strafesnet", features = ["deferred-division","named-fields"] }
|
||||||
ratio_ops = { version = "0.1.0", registry = "strafesnet" }
|
ratio_ops = { version = "0.1.0", registry = "strafesnet" }
|
||||||
glam = "0.28.0"
|
glam = "0.28.0"
|
||||||
|
@ -525,6 +525,7 @@ impl TryFrom<[f32;3]> for Unit32Vec3{
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
pub type Planar64TryFromFloatError=fixed_wide::fixed::FixedFromFloatError;
|
||||||
pub type Planar64=fixed_wide::types::I32F32;
|
pub type Planar64=fixed_wide::types::I32F32;
|
||||||
pub type Planar64Vec3=linear_ops::types::Vector3<Planar64>;
|
pub type Planar64Vec3=linear_ops::types::Vector3<Planar64>;
|
||||||
pub type Planar64Mat3=linear_ops::types::Matrix3<Planar64>;
|
pub type Planar64Mat3=linear_ops::types::Matrix3<Planar64>;
|
||||||
@ -543,23 +544,52 @@ pub mod vec3{
|
|||||||
pub const NEG_Y:Planar64Vec3=Planar64Vec3::new([Planar64::ZERO,Planar64::NEG_ONE,Planar64::ZERO]);
|
pub const NEG_Y:Planar64Vec3=Planar64Vec3::new([Planar64::ZERO,Planar64::NEG_ONE,Planar64::ZERO]);
|
||||||
pub const NEG_Z:Planar64Vec3=Planar64Vec3::new([Planar64::ZERO,Planar64::ZERO,Planar64::NEG_ONE]);
|
pub const NEG_Z:Planar64Vec3=Planar64Vec3::new([Planar64::ZERO,Planar64::ZERO,Planar64::NEG_ONE]);
|
||||||
pub const NEG_ONE:Planar64Vec3=Planar64Vec3::new([Planar64::NEG_ONE,Planar64::NEG_ONE,Planar64::NEG_ONE]);
|
pub const NEG_ONE:Planar64Vec3=Planar64Vec3::new([Planar64::NEG_ONE,Planar64::NEG_ONE,Planar64::NEG_ONE]);
|
||||||
pub fn int(x:i32,y:i32,z:i32)->Planar64Vec3{
|
#[inline]
|
||||||
Planar64Vec3::new([Planar64::from(x),Planar64::from(y),Planar64::from(z)])
|
pub const fn int(x:i32,y:i32,z:i32)->Planar64Vec3{
|
||||||
|
Planar64Vec3::new([Planar64::raw((x as i64)<<32),Planar64::raw((y as i64)<<32),Planar64::raw((z as i64)<<32)])
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
pub fn raw_array(array:[i64;3])->Planar64Vec3{
|
pub fn raw_array(array:[i64;3])->Planar64Vec3{
|
||||||
Planar64Vec3::new(array.map(Planar64::raw))
|
Planar64Vec3::new(array.map(Planar64::raw))
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
pub fn raw_xyz(x:i64,y:i64,z:i64)->Planar64Vec3{
|
pub fn raw_xyz(x:i64,y:i64,z:i64)->Planar64Vec3{
|
||||||
Planar64Vec3::new([Planar64::raw(x),Planar64::raw(y),Planar64::raw(z)])
|
Planar64Vec3::new([Planar64::raw(x),Planar64::raw(y),Planar64::raw(z)])
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn try_from_f32_array([x,y,z]:[f32;3])->Result<Planar64Vec3,Planar64TryFromFloatError>{
|
||||||
|
Ok(Planar64Vec3::new([
|
||||||
|
try_from_f32(x)?,
|
||||||
|
try_from_f32(y)?,
|
||||||
|
try_from_f32(z)?,
|
||||||
|
]))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn int(value:i32)->Planar64{
|
pub fn int(value:i32)->Planar64{
|
||||||
Planar64::from(value)
|
Planar64::from(value)
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn try_from_f32(value:f32)->Result<Planar64,Planar64TryFromFloatError>{
|
||||||
|
let result:Result<Planar64,_>=value.try_into();
|
||||||
|
match result{
|
||||||
|
Ok(ok)=>Ok(ok),
|
||||||
|
Err(e)=>e.underflow_to_zero(),
|
||||||
|
}
|
||||||
|
}
|
||||||
pub mod mat3{
|
pub mod mat3{
|
||||||
use super::*;
|
use super::*;
|
||||||
pub use linear_ops::types::Matrix3;
|
pub use linear_ops::types::Matrix3;
|
||||||
|
#[inline]
|
||||||
|
pub const fn identity()->Planar64Mat3{
|
||||||
|
Planar64Mat3::new([
|
||||||
|
[Planar64::ONE,Planar64::ZERO,Planar64::ZERO],
|
||||||
|
[Planar64::ZERO,Planar64::ONE,Planar64::ZERO],
|
||||||
|
[Planar64::ZERO,Planar64::ZERO,Planar64::ONE],
|
||||||
|
])
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
pub fn from_diagonal(diag:Planar64Vec3)->Planar64Mat3{
|
pub fn from_diagonal(diag:Planar64Vec3)->Planar64Mat3{
|
||||||
Planar64Mat3::new([
|
Planar64Mat3::new([
|
||||||
[diag.x,Planar64::ZERO,Planar64::ZERO],
|
[diag.x,Planar64::ZERO,Planar64::ZERO],
|
||||||
@ -586,6 +616,14 @@ pub mod mat3{
|
|||||||
Planar64Vec3::new([s,Planar64::ZERO,c]),
|
Planar64Vec3::new([s,Planar64::ZERO,c]),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn try_from_f32_array_2d([x_axis,y_axis,z_axis]:[[f32;3];3])->Result<Planar64Mat3,Planar64TryFromFloatError>{
|
||||||
|
Ok(Planar64Mat3::new([
|
||||||
|
vec3::try_from_f32_array(x_axis)?.to_array(),
|
||||||
|
vec3::try_from_f32_array(y_axis)?.to_array(),
|
||||||
|
vec3::try_from_f32_array(z_axis)?.to_array(),
|
||||||
|
]))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone,Copy,Default,Hash,Eq,PartialEq)]
|
#[derive(Clone,Copy,Default,Hash,Eq,PartialEq)]
|
||||||
|
Loading…
Reference in New Issue
Block a user