Compare commits
4 Commits
wide_len
...
partialord
| Author | SHA1 | Date | |
|---|---|---|---|
| 17d43852d3 | |||
| 12b825bb15 | |||
| cd70967c08 | |||
| 626eb7e9e2 |
@@ -1,7 +1,19 @@
|
||||
use std::ops::{Add,Mul};
|
||||
use std::cmp::Ordering;
|
||||
use crate::ratio::Ratio;
|
||||
use fixed_wide_traits::wide::{WideMul,WideDiv};
|
||||
|
||||
impl<Num,Den,T> PartialOrd<T> for Ratio<Num,Den>
|
||||
{
|
||||
fn partial_cmp(&self,other:&T)->Option<Ordering>{
|
||||
//a < c*b
|
||||
match self.den.cmp(0){
|
||||
Ordering::Less=>Some(self.num.partial_cmp(self.den.mul(other))),
|
||||
Ordering::Equal=>None,//divide by zero
|
||||
Ordering::Greater=>Some(self.num.partial_cmp(self.den.mul(other)).reverse()),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<Num,Den:Copy> Ratio<Num,Den>
|
||||
{
|
||||
pub fn rational_add<T>(self,rhs:T)->Ratio<<Num as Add<<Den as Mul<T>>::Output>>::Output,Den>
|
||||
|
||||
@@ -8,12 +8,6 @@ pub struct Fixed<const CHUNKS:usize,Frac>{
|
||||
pub(crate)frac:PhantomData<Frac>,
|
||||
}
|
||||
|
||||
impl<const CHUNKS:usize,Frac:Unsigned> Fixed<CHUNKS,Frac>{
|
||||
pub const ZERO:Self=Self{bits:BInt::<CHUNKS>::ZERO,frac:PhantomData};
|
||||
pub const ONE:Self=Self{bits:BInt::<CHUNKS>::ONE.shl(Frac::U32),frac:PhantomData};
|
||||
pub const NEG_ONE:Self=Self{bits:BInt::<CHUNKS>::NEG_ONE.shl(Frac::U32),frac:PhantomData};
|
||||
}
|
||||
|
||||
impl<const CHUNKS:usize,FracDst:Unsigned,T> From<T> for Fixed<CHUNKS,FracDst>
|
||||
where
|
||||
BInt<CHUNKS>:From<T>
|
||||
@@ -33,17 +27,6 @@ impl<const CHUNKS:usize,Frac> PartialEq for Fixed<CHUNKS,Frac>{
|
||||
}
|
||||
impl<const CHUNKS:usize,Frac> Eq for Fixed<CHUNKS,Frac>{}
|
||||
|
||||
impl<const CHUNKS:usize,Frac> PartialOrd for Fixed<CHUNKS,Frac>{
|
||||
fn partial_cmp(&self,other:&Self)->Option<std::cmp::Ordering>{
|
||||
self.bits.partial_cmp(&other.bits)
|
||||
}
|
||||
}
|
||||
impl<const CHUNKS:usize,Frac> Ord for Fixed<CHUNKS,Frac>{
|
||||
fn cmp(&self,other:&Self)->std::cmp::Ordering{
|
||||
self.bits.cmp(&other.bits)
|
||||
}
|
||||
}
|
||||
|
||||
impl<const CHUNKS:usize,Frac> std::ops::Neg for Fixed<CHUNKS,Frac>{
|
||||
type Output=Self;
|
||||
fn neg(self)->Self{
|
||||
@@ -56,7 +39,7 @@ impl<const CHUNKS:usize,Frac> std::ops::Neg for Fixed<CHUNKS,Frac>{
|
||||
|
||||
macro_rules! impl_operator {
|
||||
( $struct: ident, $trait: ident, $method: ident, $output: ty ) => {
|
||||
impl<const CHUNKS:usize,Frac> core::ops::$trait for $struct<CHUNKS,Frac>{
|
||||
impl<const CHUNKS:usize,Frac> core::ops::$trait<$struct<CHUNKS,Frac>> for $struct<CHUNKS,Frac>{
|
||||
type Output = $output;
|
||||
|
||||
fn $method(self, other: Self) -> Self::Output {
|
||||
@@ -70,7 +53,7 @@ macro_rules! impl_operator {
|
||||
}
|
||||
macro_rules! impl_assign_operator {
|
||||
( $struct: ident, $trait: ident, $method: ident ) => {
|
||||
impl<const CHUNKS:usize,Frac> core::ops::$trait for $struct<CHUNKS,Frac>{
|
||||
impl<const CHUNKS:usize,Frac> core::ops::$trait<$struct<CHUNKS,Frac>> for $struct<CHUNKS,Frac>{
|
||||
fn $method(&mut self, other: Self) {
|
||||
self.bits.$method(other.bits);
|
||||
}
|
||||
@@ -97,31 +80,3 @@ impl_assign_operator!( Fixed, BitOrAssign, bitor_assign );
|
||||
impl_operator!( Fixed, BitOr, bitor, Self );
|
||||
impl_assign_operator!( Fixed, BitXorAssign, bitxor_assign );
|
||||
impl_operator!( Fixed, BitXor, bitxor, Self );
|
||||
|
||||
macro_rules! impl_shift_operator {
|
||||
( $struct: ident, $trait: ident, $method: ident, $output: ty ) => {
|
||||
impl<const CHUNKS:usize,Frac> core::ops::$trait<u32> for $struct<CHUNKS,Frac>{
|
||||
type Output = $output;
|
||||
|
||||
fn $method(self, other: u32) -> Self::Output {
|
||||
Self {
|
||||
bits:self.bits.$method(other),
|
||||
frac:PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
macro_rules! impl_shift_assign_operator {
|
||||
( $struct: ident, $trait: ident, $method: ident ) => {
|
||||
impl<const CHUNKS:usize,Frac> core::ops::$trait<u32> for $struct<CHUNKS,Frac>{
|
||||
fn $method(&mut self, other: u32) {
|
||||
self.bits.$method(other);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
impl_shift_assign_operator!( Fixed, ShlAssign, shl_assign );
|
||||
impl_shift_operator!( Fixed, Shl, shl, Self );
|
||||
impl_shift_assign_operator!( Fixed, ShrAssign, shr_assign );
|
||||
impl_shift_operator!( Fixed, Shr, shr, Self );
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
pub mod fixed;
|
||||
pub mod types;
|
||||
|
||||
pub mod typenum{
|
||||
pub use typenum::Unsigned;
|
||||
}
|
||||
|
||||
#[cfg(feature="fixed_wide_traits")]
|
||||
mod fixed_wide_traits;
|
||||
#[cfg(feature="fixed_wide_traits")]
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
use std::ops::Add;
|
||||
use fixed_wide_traits::wide::WideDot;
|
||||
|
||||
pub struct Affine<M,T>{
|
||||
pub matrix:M,
|
||||
pub offset:T,
|
||||
}
|
||||
|
||||
impl<M:Copy,T:Copy> Affine<M,T>{
|
||||
pub fn wide_transform<X>(&self,input:X)-><<M as WideDot<X>>::Output as Add<T>>::Output
|
||||
where
|
||||
M:WideDot<X>,
|
||||
<M as WideDot<X>>::Output:Add<T>,
|
||||
{
|
||||
self.matrix.wide_dot(input)+self.offset
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
mod macros;
|
||||
mod vector;
|
||||
|
||||
#[cfg(feature="fixed_wide_traits")]
|
||||
pub mod affine;
|
||||
|
||||
pub use vector::Vector2;
|
||||
pub use vector::Vector3;
|
||||
pub use vector::Vector4;
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#[doc(hidden)]
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! impl_length_operations {
|
||||
( $struct: ident { $($field: ident), + }, $size: expr ) => {
|
||||
impl<U,T:Copy+fixed_wide_traits::wide::WideMul<Output=U>> $struct<T> {
|
||||
type Output=$struct<U>;
|
||||
#[inline]
|
||||
fn wide_with_length(self, rhs: Self) -> Self::Output {
|
||||
let len=self.wide_length();
|
||||
let ratio=rhs.ratio(len);
|
||||
self.wide_mul(ratio)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
#[cfg(feature="fixed_wide_traits")]
|
||||
pub mod wide;
|
||||
#[cfg(all(feature="fixed_wide_traits",feature="deferred_division"))]
|
||||
pub mod length;
|
||||
|
||||
// Stolen from https://github.com/c1m50c/fixed-vectors (MIT license)
|
||||
#[doc(hidden)]
|
||||
@@ -168,44 +166,6 @@ macro_rules! impl_vector {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Ord> $struct<T> {
|
||||
pub fn min(self, rhs: Self) -> $struct<T> {
|
||||
$struct{
|
||||
$( $field: self.$field.min(rhs.$field) ), +
|
||||
}
|
||||
}
|
||||
pub fn max(self, rhs: Self) -> $struct<T> {
|
||||
$struct{
|
||||
$( $field: self.$field.max(rhs.$field) ), +
|
||||
}
|
||||
}
|
||||
pub fn cmp(self, rhs: Self) -> $struct<core::cmp::Ordering> {
|
||||
$struct{
|
||||
$( $field: self.$field.cmp(&rhs.$field) ), +
|
||||
}
|
||||
}
|
||||
pub fn lt(self, rhs: Self) -> $struct<bool> {
|
||||
$struct{
|
||||
$( $field: self.$field.lt(&rhs.$field) ), +
|
||||
}
|
||||
}
|
||||
pub fn gt(self, rhs: Self) -> $struct<bool> {
|
||||
$struct{
|
||||
$( $field: self.$field.gt(&rhs.$field) ), +
|
||||
}
|
||||
}
|
||||
pub fn ge(self, rhs: Self) -> $struct<bool> {
|
||||
$struct{
|
||||
$( $field: self.$field.ge(&rhs.$field) ), +
|
||||
}
|
||||
}
|
||||
pub fn le(self, rhs: Self) -> $struct<bool> {
|
||||
$struct{
|
||||
$( $field: self.$field.le(&rhs.$field) ), +
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: core::ops::Neg<Output = T>> core::ops::Neg for $struct<T> {
|
||||
type Output = Self;
|
||||
|
||||
|
||||
@@ -25,12 +25,6 @@ fn you_can_add_numbers(){
|
||||
assert_eq!(a+a,Planar64Wide3::from((3i128*2).pow(4)*2))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn you_can_shr_numbers(){
|
||||
let a=Planar64::from(4);
|
||||
assert_eq!(a>>1,Planar64::from(2))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wide_vec3(){
|
||||
let v=Vector3::from_value(Planar64::from(3));
|
||||
|
||||
Reference in New Issue
Block a user