the replacement of all time

This commit is contained in:
Quaternions 2024-08-27 13:51:20 -07:00
parent 585d6c8a92
commit 8a13307d98

View File

@ -427,650 +427,10 @@ impl TryFrom<[f32;3]> for Unit32Vec3{
}
*/
///[-1.0,1.0] = [-2^32,2^32]
#[derive(Clone,Copy,Debug,Hash,Eq,Ord,PartialEq,PartialOrd)]
pub struct Planar64(i64);
impl Planar64{
pub const ZERO:Self=Self(0);
pub const ONE:Self=Self(1<<32);
pub const MAX:Self=Self(i64::MAX);
pub const MIN:Self=Self(i64::MIN);
#[inline]
pub const fn int(num:i32)->Self{
Self(Self::ONE.0*num as i64)
}
#[inline]
pub const fn raw(num:i64)->Self{
Self(num)
}
#[inline]
pub const fn get(&self)->i64{
self.0
}
#[inline]
pub const fn abs(self)->Self{
Self(self.0.abs())
}
#[inline]
pub fn sqrt(&self)->Self{
Planar64(unsafe{(((self.0 as i128)<<32) as f64).sqrt().to_int_unchecked()})
}
#[inline]
pub const fn signum_i64(&self)->i64{
((self.0&(1<<63)!=0) as i64)*2-1
}
}
const PLANAR64_ONE_FLOAT32:f32=(1u64<<32) as f32;
const PLANAR64_CONVERT_TO_FLOAT32:f32=1.0/PLANAR64_ONE_FLOAT32;
const PLANAR64_ONE_FLOAT64:f64=(1u64<<32) as f64;
impl Into<f32> for Planar64{
#[inline]
fn into(self)->f32{
self.0 as f32*PLANAR64_CONVERT_TO_FLOAT32
}
}
impl From<Ratio64> for Planar64{
#[inline]
fn from(ratio:Ratio64)->Self{
Self((((ratio.num as i128)<<32)/(ratio.den as i128)) as i64)
}
}
#[derive(Debug)]
pub enum Planar64TryFromFloatError{
Nan,
Infinite,
Subnormal,
HighlyNegativeExponent,
HighlyPositiveExponent,
}
impl TryFrom<f32> for Planar64{
type Error=Planar64TryFromFloatError;
#[inline]
fn try_from(value:f32)->Result<Self,Self::Error>{
match value.classify(){
std::num::FpCategory::Nan=>Err(Self::Error::Nan),
std::num::FpCategory::Infinite=>Err(Self::Error::Infinite),
std::num::FpCategory::Zero=>Ok(Self::ZERO),
std::num::FpCategory::Subnormal
|std::num::FpCategory::Normal=>{
let planar=value*PLANAR64_ONE_FLOAT32;
if planar<(i64::MIN as f32)||(i64::MAX as f32)<planar{
Err(Self::Error::HighlyPositiveExponent)
}else{
Ok(Planar64(unsafe{planar.to_int_unchecked()}))
}
}
}
}
}
impl TryFrom<f64> for Planar64{
type Error=Planar64TryFromFloatError;
#[inline]
fn try_from(value:f64)->Result<Self,Self::Error>{
match value.classify(){
std::num::FpCategory::Nan=>Err(Self::Error::Nan),
std::num::FpCategory::Infinite=>Err(Self::Error::Infinite),
std::num::FpCategory::Zero=>Ok(Self::ZERO),
std::num::FpCategory::Subnormal
|std::num::FpCategory::Normal=>{
let planar=value*PLANAR64_ONE_FLOAT64;
if planar<(i64::MIN as f64)||(i64::MAX as f64)<planar{
Err(Self::Error::HighlyPositiveExponent)
}else{
Ok(Planar64(unsafe{planar.to_int_unchecked()}))
}
}
}
}
}
impl std::fmt::Display for Planar64{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{:.3}",
Into::<f32>::into(*self),
)
}
}
impl std::ops::Neg for Planar64{
type Output=Planar64;
#[inline]
fn neg(self)->Self::Output{
Planar64(-self.0)
}
}
impl std::ops::Add<Planar64> for Planar64{
type Output=Planar64;
#[inline]
fn add(self, rhs: Self) -> Self::Output {
Planar64(self.0+rhs.0)
}
}
impl std::ops::AddAssign<Planar64> for Planar64{
#[inline]
fn add_assign(&mut self,rhs:Self){
*self=*self+rhs;
}
}
impl std::ops::Sub<Planar64> for Planar64{
type Output=Planar64;
#[inline]
fn sub(self, rhs: Self) -> Self::Output {
Planar64(self.0-rhs.0)
}
}
impl std::ops::Mul<i64> for Planar64{
type Output=Planar64;
#[inline]
fn mul(self, rhs: i64) -> Self::Output {
Planar64(self.0*rhs)
}
}
impl std::ops::Mul<Planar64> for Planar64{
type Output=Planar64;
#[inline]
fn mul(self, rhs: Self) -> Self::Output {
Planar64(((self.0 as i128*rhs.0 as i128)>>32) as i64)
}
}
impl std::ops::Mul<Time> for Planar64{
type Output=Planar64;
#[inline]
fn mul(self,rhs:Time)->Self::Output{
Planar64(((self.0 as i128*rhs.0 as i128)/1_000_000_000) as i64)
}
}
impl std::ops::Div<i64> for Planar64{
type Output=Planar64;
#[inline]
fn div(self, rhs: i64) -> Self::Output {
Planar64(self.0/rhs)
}
}
impl std::ops::Div<Planar64> for Planar64{
type Output=Planar64;
#[inline]
fn div(self, rhs: Planar64) -> Self::Output {
Planar64((((self.0 as i128)<<32)/(rhs.0 as i128)) as i64)
}
}
// impl PartialOrd<i64> for Planar64{
// fn partial_cmp(&self, other: &i64) -> Option<std::cmp::Ordering> {
// self.0.partial_cmp(other)
// }
// }
///[-1.0,1.0] = [-2^32,2^32]
#[derive(Clone,Copy,Debug,Default,Hash,Eq,PartialEq)]
pub struct Planar64Vec3(glam::I64Vec3);
impl Planar64Vec3{
pub const ZERO:Self=Planar64Vec3(glam::I64Vec3::ZERO);
pub const ONE:Self=Self::int(1,1,1);
pub const X:Self=Self::int(1,0,0);
pub const Y:Self=Self::int(0,1,0);
pub const Z:Self=Self::int(0,0,1);
pub const NEG_X:Self=Self::int(-1,0,0);
pub const NEG_Y:Self=Self::int(0,-1,0);
pub const NEG_Z:Self=Self::int(0,0,-1);
pub const MIN:Self=Planar64Vec3(glam::I64Vec3::MIN);
pub const MAX:Self=Planar64Vec3(glam::I64Vec3::MAX);
#[inline]
pub const fn new(x:Planar64,y:Planar64,z:Planar64)->Self{
Self(glam::i64vec3(x.0,y.0,z.0))
}
#[inline]
pub const fn get(self)->glam::I64Vec3{
self.0
}
#[inline]
pub const fn int(x:i32,y:i32,z:i32)->Self{
Self(glam::i64vec3((x as i64)<<32,(y as i64)<<32,(z as i64)<<32))
}
#[inline]
pub const fn raw_xyz(x:i64,y:i64,z:i64)->Self{
Self(glam::i64vec3(x,y,z))
}
#[inline]
pub const fn raw_array(xyz:[i64;3])->Self{
Self(glam::I64Vec3::from_array(xyz))
}
#[inline]
pub const fn raw(xyz:glam::I64Vec3)->Self{
Self(xyz)
}
#[inline]
pub const fn x(&self)->Planar64{
Planar64(self.0.x)
}
#[inline]
pub const fn y(&self)->Planar64{
Planar64(self.0.y)
}
#[inline]
pub const fn z(&self)->Planar64{
Planar64(self.0.z)
}
#[inline]
pub fn min(&self,rhs:Self)->Self{
Self(glam::i64vec3(
self.0.x.min(rhs.0.x),
self.0.y.min(rhs.0.y),
self.0.z.min(rhs.0.z),
))
}
#[inline]
pub fn max(&self,rhs:Self)->Self{
Self(glam::i64vec3(
self.0.x.max(rhs.0.x),
self.0.y.max(rhs.0.y),
self.0.z.max(rhs.0.z),
))
}
#[inline]
pub fn midpoint(&self,rhs:Self)->Self{
Self((self.0+rhs.0)/2)
}
#[inline]
pub fn cmplt(&self,rhs:Self)->glam::BVec3{
self.0.cmplt(rhs.0)
}
#[inline]
pub const fn dot(&self,rhs:Self)->Planar64{
Planar64(((
(self.0.x as i128)*(rhs.0.x as i128)+
(self.0.y as i128)*(rhs.0.y as i128)+
(self.0.z as i128)*(rhs.0.z as i128)
)>>32) as i64)
}
#[inline]
pub const fn dot128(&self,rhs:Self)->i128{
(self.0.x as i128)*(rhs.0.x as i128)+
(self.0.y as i128)*(rhs.0.y as i128)+
(self.0.z as i128)*(rhs.0.z as i128)
}
#[inline]
pub const fn cross(&self,rhs:Self)->Planar64Vec3{
Planar64Vec3(glam::i64vec3(
(((self.0.y as i128)*(rhs.0.z as i128)-(self.0.z as i128)*(rhs.0.y as i128))>>32) as i64,
(((self.0.z as i128)*(rhs.0.x as i128)-(self.0.x as i128)*(rhs.0.z as i128))>>32) as i64,
(((self.0.x as i128)*(rhs.0.y as i128)-(self.0.y as i128)*(rhs.0.x as i128))>>32) as i64,
))
}
#[inline]
pub fn length(&self)->Planar64{
let radicand=(self.0.x as i128)*(self.0.x as i128)+(self.0.y as i128)*(self.0.y as i128)+(self.0.z as i128)*(self.0.z as i128);
Planar64(unsafe{(radicand as f64).sqrt().to_int_unchecked()})
}
#[inline]
pub fn with_length(&self,length:Planar64)->Self{
let radicand=(self.0.x as i128)*(self.0.x as i128)+(self.0.y as i128)*(self.0.y as i128)+(self.0.z as i128)*(self.0.z as i128);
let self_length:i128=unsafe{(radicand as f64).sqrt().to_int_unchecked()};
//self.0*length/self_length
Planar64Vec3(
glam::i64vec3(
((self.0.x as i128)*(length.0 as i128)/self_length) as i64,
((self.0.y as i128)*(length.0 as i128)/self_length) as i64,
((self.0.z as i128)*(length.0 as i128)/self_length) as i64,
)
)
}
}
impl Into<glam::Vec3> for Planar64Vec3{
#[inline]
fn into(self)->glam::Vec3{
glam::vec3(
self.0.x as f32,
self.0.y as f32,
self.0.z as f32,
)*PLANAR64_CONVERT_TO_FLOAT32
}
}
impl TryFrom<[f32;3]> for Planar64Vec3{
type Error=Planar64TryFromFloatError;
#[inline]
fn try_from(value:[f32;3])->Result<Self,Self::Error>{
Ok(Self(glam::i64vec3(
Planar64::try_from(value[0])?.0,
Planar64::try_from(value[1])?.0,
Planar64::try_from(value[2])?.0,
)))
}
}
impl TryFrom<glam::Vec3A> for Planar64Vec3{
type Error=Planar64TryFromFloatError;
#[inline]
fn try_from(value:glam::Vec3A)->Result<Self,Self::Error>{
Ok(Self(glam::i64vec3(
Planar64::try_from(value.x)?.0,
Planar64::try_from(value.y)?.0,
Planar64::try_from(value.z)?.0,
)))
}
}
impl std::fmt::Display for Planar64Vec3{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{:.3},{:.3},{:.3}",
Into::<f32>::into(self.x()),Into::<f32>::into(self.y()),Into::<f32>::into(self.z()),
)
}
}
impl std::ops::Neg for Planar64Vec3{
type Output=Planar64Vec3;
#[inline]
fn neg(self)->Self::Output{
Planar64Vec3(-self.0)
}
}
impl std::ops::Add<Planar64Vec3> for Planar64Vec3{
type Output=Planar64Vec3;
#[inline]
fn add(self,rhs:Planar64Vec3) -> Self::Output {
Planar64Vec3(self.0+rhs.0)
}
}
impl std::ops::AddAssign<Planar64Vec3> for Planar64Vec3{
#[inline]
fn add_assign(&mut self,rhs:Planar64Vec3){
*self=*self+rhs
}
}
impl std::ops::Sub<Planar64Vec3> for Planar64Vec3{
type Output=Planar64Vec3;
#[inline]
fn sub(self,rhs:Planar64Vec3) -> Self::Output {
Planar64Vec3(self.0-rhs.0)
}
}
impl std::ops::SubAssign<Planar64Vec3> for Planar64Vec3{
#[inline]
fn sub_assign(&mut self,rhs:Planar64Vec3){
*self=*self-rhs
}
}
impl std::ops::Mul<Planar64Vec3> for Planar64Vec3{
type Output=Planar64Vec3;
#[inline]
fn mul(self, rhs: Planar64Vec3) -> Self::Output {
Planar64Vec3(glam::i64vec3(
(((self.0.x as i128)*(rhs.0.x as i128))>>32) as i64,
(((self.0.y as i128)*(rhs.0.y as i128))>>32) as i64,
(((self.0.z as i128)*(rhs.0.z as i128))>>32) as i64
))
}
}
impl std::ops::Mul<Planar64> for Planar64Vec3{
type Output=Planar64Vec3;
#[inline]
fn mul(self, rhs: Planar64) -> Self::Output {
Planar64Vec3(glam::i64vec3(
(((self.0.x as i128)*(rhs.0 as i128))>>32) as i64,
(((self.0.y as i128)*(rhs.0 as i128))>>32) as i64,
(((self.0.z as i128)*(rhs.0 as i128))>>32) as i64
))
}
}
impl std::ops::Mul<i64> for Planar64Vec3{
type Output=Planar64Vec3;
#[inline]
fn mul(self,rhs:i64)->Self::Output {
Planar64Vec3(glam::i64vec3(
self.0.x*rhs,
self.0.y*rhs,
self.0.z*rhs
))
}
}
impl std::ops::Mul<Time> for Planar64Vec3{
type Output=Planar64Vec3;
#[inline]
fn mul(self,rhs:Time)->Self::Output{
Planar64Vec3(glam::i64vec3(
(((self.0.x as i128)*(rhs.0 as i128))/1_000_000_000) as i64,
(((self.0.y as i128)*(rhs.0 as i128))/1_000_000_000) as i64,
(((self.0.z as i128)*(rhs.0 as i128))/1_000_000_000) as i64
))
}
}
impl std::ops::Div<Planar64> for Planar64Vec3{
type Output=Planar64Vec3;
#[inline]
fn div(self,rhs:Planar64)->Self::Output{
Planar64Vec3(glam::i64vec3(
(((self.0.x as i128)<<32)/(rhs.0 as i128)) as i64,
(((self.0.y as i128)<<32)/(rhs.0 as i128)) as i64,
(((self.0.z as i128)<<32)/(rhs.0 as i128)) as i64,
))
}
}
impl std::ops::Div<i64> for Planar64Vec3{
type Output=Planar64Vec3;
#[inline]
fn div(self,rhs:i64)->Self::Output{
Planar64Vec3(glam::i64vec3(
self.0.x/rhs,
self.0.y/rhs,
self.0.z/rhs,
))
}
}
///[-1.0,1.0] = [-2^32,2^32]
#[derive(Clone,Copy,Hash,Eq,PartialEq)]
pub struct Planar64Mat3{
pub x_axis:Planar64Vec3,
pub y_axis:Planar64Vec3,
pub z_axis:Planar64Vec3,
}
impl Default for Planar64Mat3{
#[inline]
fn default() -> Self {
Self{
x_axis:Planar64Vec3::X,
y_axis:Planar64Vec3::Y,
z_axis:Planar64Vec3::Z,
}
}
}
impl Planar64Mat3{
#[inline]
pub const fn from_cols(x_axis:Planar64Vec3,y_axis:Planar64Vec3,z_axis:Planar64Vec3)->Self{
Self{
x_axis,
y_axis,
z_axis,
}
}
pub const fn int_from_cols_array(array:[i32;9])->Self{
Self{
x_axis:Planar64Vec3::int(array[0],array[1],array[2]),
y_axis:Planar64Vec3::int(array[3],array[4],array[5]),
z_axis:Planar64Vec3::int(array[6],array[7],array[8]),
}
}
#[inline]
pub const fn from_diagonal(diagonal:Planar64Vec3)->Self{
Self{
x_axis:Planar64Vec3::raw_xyz(diagonal.0.x,0,0),
y_axis:Planar64Vec3::raw_xyz(0,diagonal.0.y,0),
z_axis:Planar64Vec3::raw_xyz(0,0,diagonal.0.z),
}
}
#[inline]
pub fn from_rotation_yx(yaw:Angle32,pitch:Angle32)->Self{
let xtheta=yaw.0 as f64*ANGLE32_TO_FLOAT64_RADIANS;
let (xs,xc)=xtheta.sin_cos();
let (xc,xs)=(xc*PLANAR64_ONE_FLOAT64,xs*PLANAR64_ONE_FLOAT64);
let ytheta=pitch.0 as f64*ANGLE32_TO_FLOAT64_RADIANS;
let (ys,yc)=ytheta.sin_cos();
let (yc,ys)=(yc*PLANAR64_ONE_FLOAT64,ys*PLANAR64_ONE_FLOAT64);
//TODO: fix this rounding towards 0
let (xc,xs):(i64,i64)=(unsafe{xc.to_int_unchecked()},unsafe{xs.to_int_unchecked()});
let (yc,ys):(i64,i64)=(unsafe{yc.to_int_unchecked()},unsafe{ys.to_int_unchecked()});
Self::from_cols(
Planar64Vec3(glam::i64vec3(xc,0,-xs)),
Planar64Vec3(glam::i64vec3(((xs as i128*ys as i128)>>32) as i64,yc,((xc as i128*ys as i128)>>32) as i64)),
Planar64Vec3(glam::i64vec3(((xs as i128*yc as i128)>>32) as i64,-ys,((xc as i128*yc as i128)>>32) as i64)),
)
}
#[inline]
pub fn from_rotation_y(angle:Angle32)->Self{
let theta=angle.0 as f64*ANGLE32_TO_FLOAT64_RADIANS;
let (s,c)=theta.sin_cos();
let (c,s)=(c*PLANAR64_ONE_FLOAT64,s*PLANAR64_ONE_FLOAT64);
//TODO: fix this rounding towards 0
let (c,s):(i64,i64)=(unsafe{c.to_int_unchecked()},unsafe{s.to_int_unchecked()});
Self::from_cols(
Planar64Vec3(glam::i64vec3(c,0,-s)),
Planar64Vec3::Y,
Planar64Vec3(glam::i64vec3(s,0,c)),
)
}
#[inline]
pub const fn inverse(&self)->Self{
let det=(
-self.x_axis.0.z as i128*self.y_axis.0.y as i128*self.z_axis.0.x as i128
+self.x_axis.0.y as i128*self.y_axis.0.z as i128*self.z_axis.0.x as i128
+self.x_axis.0.z as i128*self.y_axis.0.x as i128*self.z_axis.0.y as i128
-self.x_axis.0.x as i128*self.y_axis.0.z as i128*self.z_axis.0.y as i128
-self.x_axis.0.y as i128*self.y_axis.0.x as i128*self.z_axis.0.z as i128
+self.x_axis.0.x as i128*self.y_axis.0.y as i128*self.z_axis.0.z as i128
)>>32;
Self{
x_axis:Planar64Vec3::raw_xyz((((-(self.y_axis.0.z as i128*self.z_axis.0.y as i128)+self.y_axis.0.y as i128*self.z_axis.0.z as i128)<<32)/det) as i64,(((self.x_axis.0.z as i128*self.z_axis.0.y as i128-self.x_axis.0.y as i128*self.z_axis.0.z as i128)<<32)/det) as i64,(((-(self.x_axis.0.z as i128*self.y_axis.0.y as i128)+self.x_axis.0.y as i128*self.y_axis.0.z as i128)<<32)/det) as i64),
y_axis:Planar64Vec3::raw_xyz((((self.y_axis.0.z as i128*self.z_axis.0.x as i128-self.y_axis.0.x as i128*self.z_axis.0.z as i128)<<32)/det) as i64,(((-(self.x_axis.0.z as i128*self.z_axis.0.x as i128)+self.x_axis.0.x as i128*self.z_axis.0.z as i128)<<32)/det) as i64,(((self.x_axis.0.z as i128*self.y_axis.0.x as i128-self.x_axis.0.x as i128*self.y_axis.0.z as i128)<<32)/det) as i64),
z_axis:Planar64Vec3::raw_xyz((((-(self.y_axis.0.y as i128*self.z_axis.0.x as i128)+self.y_axis.0.x as i128*self.z_axis.0.y as i128)<<32)/det) as i64,(((self.x_axis.0.y as i128*self.z_axis.0.x as i128-self.x_axis.0.x as i128*self.z_axis.0.y as i128)<<32)/det) as i64,(((-(self.x_axis.0.y as i128*self.y_axis.0.x as i128)+self.x_axis.0.x as i128*self.y_axis.0.y as i128)<<32)/det) as i64),
}
}
#[inline]
pub const fn inverse_times_det(&self)->Self{
Self{
x_axis:Planar64Vec3::raw_xyz(((-(self.y_axis.0.z as i128*self.z_axis.0.y as i128)+self.y_axis.0.y as i128*self.z_axis.0.z as i128)>>32) as i64,((self.x_axis.0.z as i128*self.z_axis.0.y as i128-self.x_axis.0.y as i128*self.z_axis.0.z as i128)>>32) as i64,((-(self.x_axis.0.z as i128*self.y_axis.0.y as i128)+self.x_axis.0.y as i128*self.y_axis.0.z as i128)>>32) as i64),
y_axis:Planar64Vec3::raw_xyz(((self.y_axis.0.z as i128*self.z_axis.0.x as i128-self.y_axis.0.x as i128*self.z_axis.0.z as i128)>>32) as i64,((-(self.x_axis.0.z as i128*self.z_axis.0.x as i128)+self.x_axis.0.x as i128*self.z_axis.0.z as i128)>>32) as i64,((self.x_axis.0.z as i128*self.y_axis.0.x as i128-self.x_axis.0.x as i128*self.y_axis.0.z as i128)>>32) as i64),
z_axis:Planar64Vec3::raw_xyz(((-(self.y_axis.0.y as i128*self.z_axis.0.x as i128)+self.y_axis.0.x as i128*self.z_axis.0.y as i128)>>32) as i64,((self.x_axis.0.y as i128*self.z_axis.0.x as i128-self.x_axis.0.x as i128*self.z_axis.0.y as i128)>>32) as i64,((-(self.x_axis.0.y as i128*self.y_axis.0.x as i128)+self.x_axis.0.x as i128*self.y_axis.0.y as i128)>>32) as i64),
}
}
#[inline]
pub const fn transpose(&self)->Self{
Self{
x_axis:Planar64Vec3::raw_xyz(self.x_axis.0.x,self.y_axis.0.x,self.z_axis.0.x),
y_axis:Planar64Vec3::raw_xyz(self.x_axis.0.y,self.y_axis.0.y,self.z_axis.0.y),
z_axis:Planar64Vec3::raw_xyz(self.x_axis.0.z,self.y_axis.0.z,self.z_axis.0.z),
}
}
#[inline]
pub const fn determinant(&self)->Planar64{
Planar64(((
-self.x_axis.0.z as i128*self.y_axis.0.y as i128*self.z_axis.0.x as i128
+self.x_axis.0.y as i128*self.y_axis.0.z as i128*self.z_axis.0.x as i128
+self.x_axis.0.z as i128*self.y_axis.0.x as i128*self.z_axis.0.y as i128
-self.x_axis.0.x as i128*self.y_axis.0.z as i128*self.z_axis.0.y as i128
-self.x_axis.0.y as i128*self.y_axis.0.x as i128*self.z_axis.0.z as i128
+self.x_axis.0.x as i128*self.y_axis.0.y as i128*self.z_axis.0.z as i128
)>>64) as i64)
}
}
impl Into<glam::Mat3> for Planar64Mat3{
#[inline]
fn into(self)->glam::Mat3{
glam::Mat3::from_cols(
self.x_axis.into(),
self.y_axis.into(),
self.z_axis.into(),
)
}
}
impl TryFrom<glam::Mat3A> for Planar64Mat3{
type Error=Planar64TryFromFloatError;
#[inline]
fn try_from(value:glam::Mat3A)->Result<Self,Self::Error>{
Ok(Self{
x_axis:Planar64Vec3::try_from(value.x_axis)?,
y_axis:Planar64Vec3::try_from(value.y_axis)?,
z_axis:Planar64Vec3::try_from(value.z_axis)?,
})
}
}
impl std::fmt::Display for Planar64Mat3{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"\n{:.3},{:.3},{:.3}\n{:.3},{:.3},{:.3}\n{:.3},{:.3},{:.3}",
Into::<f32>::into(self.x_axis.x()),Into::<f32>::into(self.x_axis.y()),Into::<f32>::into(self.x_axis.z()),
Into::<f32>::into(self.y_axis.x()),Into::<f32>::into(self.y_axis.y()),Into::<f32>::into(self.y_axis.z()),
Into::<f32>::into(self.z_axis.x()),Into::<f32>::into(self.z_axis.y()),Into::<f32>::into(self.z_axis.z()),
)
}
}
impl std::ops::Mul<Planar64Vec3> for Planar64Mat3{
type Output=Planar64Vec3;
#[inline]
fn mul(self,rhs:Planar64Vec3) -> Self::Output {
self.x_axis*rhs.x()
+self.y_axis*rhs.y()
+self.z_axis*rhs.z()
}
}
impl std::ops::Div<i64> for Planar64Mat3{
type Output=Planar64Mat3;
#[inline]
fn div(self,rhs:i64)->Self::Output{
Planar64Mat3{
x_axis:self.x_axis/rhs,
y_axis:self.y_axis/rhs,
z_axis:self.z_axis/rhs,
}
}
}
///[-1.0,1.0] = [-2^32,2^32]
#[derive(Clone,Copy,Default,Hash,Eq,PartialEq)]
pub struct Planar64Affine3{
pub matrix3:Planar64Mat3,//includes scale above 1
pub translation:Planar64Vec3,
}
impl Planar64Affine3{
#[inline]
pub fn new(matrix3:Planar64Mat3,translation:Planar64Vec3)->Self{
Self{matrix3,translation}
}
#[inline]
pub fn transform_point3(&self,point:Planar64Vec3) -> Planar64Vec3{
Planar64Vec3(
self.translation.0
+(self.matrix3.x_axis*point.x()).0
+(self.matrix3.y_axis*point.y()).0
+(self.matrix3.z_axis*point.z()).0
)
}
}
impl Into<glam::Mat4> for Planar64Affine3{
#[inline]
fn into(self)->glam::Mat4{
glam::Mat4::from_cols_array(&[
self.matrix3.x_axis.0.x as f32,self.matrix3.x_axis.0.y as f32,self.matrix3.x_axis.0.z as f32,0.0,
self.matrix3.y_axis.0.x as f32,self.matrix3.y_axis.0.y as f32,self.matrix3.y_axis.0.z as f32,0.0,
self.matrix3.z_axis.0.x as f32,self.matrix3.z_axis.0.y as f32,self.matrix3.z_axis.0.z as f32,0.0,
self.translation.0.x as f32,self.translation.0.y as f32,self.translation.0.z as f32,PLANAR64_ONE_FLOAT32
])*PLANAR64_CONVERT_TO_FLOAT32
}
}
impl TryFrom<glam::Affine3A> for Planar64Affine3{
type Error=Planar64TryFromFloatError;
fn try_from(value: glam::Affine3A)->Result<Self, Self::Error> {
Ok(Self{
matrix3:Planar64Mat3::try_from(value.matrix3)?,
translation:Planar64Vec3::try_from(value.translation)?
})
}
}
impl std::fmt::Display for Planar64Affine3{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"translation: {:.3},{:.3},{:.3}\nmatrix3:\n{:.3},{:.3},{:.3}\n{:.3},{:.3},{:.3}\n{:.3},{:.3},{:.3}",
Into::<f32>::into(self.translation.x()),Into::<f32>::into(self.translation.y()),Into::<f32>::into(self.translation.z()),
Into::<f32>::into(self.matrix3.x_axis.x()),Into::<f32>::into(self.matrix3.x_axis.y()),Into::<f32>::into(self.matrix3.x_axis.z()),
Into::<f32>::into(self.matrix3.y_axis.x()),Into::<f32>::into(self.matrix3.y_axis.y()),Into::<f32>::into(self.matrix3.y_axis.z()),
Into::<f32>::into(self.matrix3.z_axis.x()),Into::<f32>::into(self.matrix3.z_axis.y()),Into::<f32>::into(self.matrix3.z_axis.z()),
)
}
}
pub type Planar64=fixed_wide::types::I32F32;
pub type Planar64Vec3=fixed_wide_vectors::Vector3<Planar64>;
pub type Planar64Mat3=fixed_wide_vectors::Vector3<Planar64Vec3>;
pub type Planar64Affine3=fixed_wide_vectors::affine::Affine<Planar64Mat3,Planar64Vec3>;
#[test]
fn test_sqrt(){