-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.rs
2031 lines (1816 loc) · 66.3 KB
/
vector.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use super::*;
use super::Clamp;
use r3d::*;
pub use ::std::f32::consts::PI;
/*
// Vec3*scalar
impl<A,B,C> Mul<B> for Vec3<A>
where
A:Mul<B,Output=C>,B:Float
{
type Output=Vec3<C>;
fn mul(self,rhs:B)->Vec3<C> {
Vec3(self.x*rhs , self.y*rhs, self.z*rhs)
}
}
*/
pub trait NumElements {
fn num_elements(&self)->usize;
}
impl<T:VElem> NumElements for Vec2<T>{ fn num_elements(&self)->usize{2}}
impl<T:VElem> NumElements for Vec3<T>{ fn num_elements(&self)->usize{3}}
impl<T:VElem> NumElements for Vec4<T>{ fn num_elements(&self)->usize{4}}
/// a
pub trait ArrayDimensions {
fn array_dimensions(&self)->usize;
}
impl<T> ArrayDimensions for Vec<T>{
fn array_dimensions(&self)->usize{1}
}
impl ArrayDimensions for f32 {
fn array_dimensions(&self)->usize{0}
}
impl ArrayDimensions for f64{
fn array_dimensions(&self)->usize{0}
}
// TODO.. should this recurse inward,
// e.g. 1+ T::array_dimensions..
impl<T:VElem> ArrayDimensions for Vec3<T> {
fn array_dimensions(&self)->usize{1}
}
// Generic maths classes
// member functions prefixed with 'v' for easier life without code-completion, and to distinguish from operator overloads (official langauge level "add") etc
// using vec_xyzw Vec1,Vec2,Vec3,Vec4 types
/*
/// 1D vector - sounds dumb, but symetrical with declaring channels with n-dimensions . Symetry for 'vector transpose' as Matrix1<Scalar>
#[derive(Clone,Copy,Debug)]
#[repr(C)]
pub struct Vec1<X:Sized=f32> {pub x:X}
/// 2D vector type; seperate types for X,Y,Z. not yet utilized, goal is to allow pluging in 'Zero/One' types to make scalars as axis vectors, etc.
/// for texcoords, 2d rendering
#[derive(Clone,Debug,Copy,Default)]
#[repr(C)]
pub struct Vec2<X:Sized=f32,Y:Sized=X> {pub x:X, pub y:Y}
/// 3D vector type; seperate types for X,Y,Z. not yet utilized, goal is to allow pluging in 'Zero/One' types to make scalars as axis vectors, etc.
/// for 3d points/vectors, rgb
#[derive(Clone,Debug,Copy,Default)]
#[repr(C)]
pub struct Vec3<X:Sized=f32,Y:Sized=X,Z:Sized=Y> {pub x:X, pub y:Y, pub z:Z}
/// 4D vector type; seperate types for X,Y,Z. not yet utilized, goal is to allow pluging in 'Zero/One' types to make scalars as axis vectors, etc.
/// for homogeneous points, rgba, quaternions
#[derive(Clone,Debug,Copy,Default)]
#[repr(C)]
pub struct Vec4<X:Sized=f32,Y:Sized=X,Z:Sized=Y,W:Sized=Z> {pub x:X, pub y:Y,pub z:Z, pub w:W}
*/
/// '8 element vector' written for completeness e.g. if we allow using these vectors to represent in-register SIMD operations with component-wise operations
/// todo.. at this level are we better off saying [T;8] etc.
#[derive(Clone,Debug,Copy)]
#[repr(C)]
pub struct Vec8<T=f32>(pub T,pub T,pub T,pub T, pub T,pub T,pub T,pub T);
/// '16 element vector' written for completeness e.g. if we allow using these vectors for componentwise SIMD
#[derive(Clone,Debug,Copy)]
#[repr(C)]
pub struct Vec16<T=f32>(pub T,pub T,pub T,pub T, pub T,pub T,pub T,pub T, pub T,pub T,pub T,pub T, pub T,pub T,pub T,pub T);
// constructors
pub fn vec4<X:VElem,Y:VElem,Z:VElem,W:VElem>(x:X,y:Y,z:Z,w:W)->Vec4<X,Y,Z,W> { Vec4{x:x,y:y,z:z,w:w}}
pub fn vec3<X:VElem,Y:VElem,Z:VElem>(x:X,y:Y,z:Z)->Vec3<X,Y,Z> { Vec3{x:x,y:y,z:z}}
pub fn vec2<X:VElem,Y:VElem>(x:X,y:Y)->Vec2<X,Y> { Vec2{x:x,y:y}}
pub fn vec1<X:VElem>(x:X)->Vec1<X> { Vec1{x:x}}
impl<T:VElem> HasElem for Vec1<T>{
type Elem=T;
fn vget(&self,i:i32)->T{
match i{
0=>self.x,
_=>panic!()
}
}
}
impl Vec3<f32>{
pub fn to_vec3i(&self)->Vec3<i32>{
vec3(self.x as i32, self.y as i32, self.z as i32)
}
}
/// map integers to vector with given 0-1 range
impl Vec3<i32>{
pub fn to_vec3f(&self, zero_val:i32,one_val:i32)->Vec3<f32> {
let diff=(one_val-zero_val) as f32;
let conv = |x|((x-zero_val) as f32)/diff;
vec3(conv(self.x), conv(self.y), conv(self.z))
}
}
impl Vec4<f32>{
pub fn to_vec4i(&self)->Vec4<i32>{
vec4(self.x as i32, self.y as i32, self.z as i32,self.w as i32)
}
}
/// map integers to vector with given 0-1 range
impl Vec4<i32>{
pub fn to_vec4f(&self, zero_val:i32,one_val:i32)->Vec4<f32> {
let diff=(one_val-zero_val) as f32;
let conv = |x|((x-zero_val) as f32)/diff;
vec4(conv(self.x), conv(self.y), conv(self.z), conv(self.w))
}
}
impl<T:VElem> HasElem for Vec2<T>{
type Elem=T;
fn vget(&self,i:i32)->T{
match i{
0=>self.x,
1=>self.y,
_=>panic!()
}
}
}
impl<T:VElem> HasElem for Vec3<T>{
type Elem=T;
fn vget(&self,i:i32)->T{
match i{
0=>self.x,
1=>self.y,
2=>self.z,
_=>panic!()
}
}
}
impl<T:VElem> HasElem for Vec4<T>{
type Elem=T;
fn vget(&self,i:i32)->T{
match i{
0=>self.x,
1=>self.y,
2=>self.z,
3=>self.w,
_=>panic!()
}
}
}
// TODO half-precision type for GL..
// TODO: Packed normal 10:10:10
// TODO: 565 colors
/*
pub struct Vec3f {x:float,y:float,z:float}
impl Vec3f {
pub fn new2(x:float,y:float)->Vec3f { Vec3f{x:x,y:y,z:0.0} }
}
*/
pub trait VSplat<T>{
fn vsplat(v:T)->Self;
unsafe fn raw_ptr(&self)->*const T;
}
impl<T:VElem> VSplat<T> for Vec2<T> {
// pub fn new(x:T,y:T)->Vec2<T> {vec2(x,y)}
fn vsplat(v:T)->Vec2<T> { vec2(v.clone(),v)}
unsafe fn raw_ptr(&self)->*const T{&self.x as *const T}
}
pub trait CrossZ<T>{
fn vcross_z(&self,other:&Self)->T;
}
impl<T:Num+VElem> CrossZ<T> for Vec2<T> {
// 'cross_z' computes the z component of a 3d cross product, i.e. uses x/y
fn vcross_z(&self,other:&Vec2<T>)->T {self.x*other.y-self.y*other.x}
}
impl<T:VElem> VSplat<T> for Vec3<T> {
fn vsplat(v:T)->Vec3<T> { vec3(v,v,v)}
unsafe fn raw_ptr(&self)->*const T{&self.x as *const T}
}
impl<T:VElem> VSplat<T> for Vec4<T> {
fn vsplat(v:T)->Vec4<T> { vec4(v.clone(),v.clone(),v.clone(),v.clone())} // todo -move to elsewhere
unsafe fn raw_ptr(&self)->*const T{&self.x as *const T}
}
/*
impl<T:Clone> Vec4<T> {
pub fn new(x:T,y:T,z:T,w:T)->Vec4<T> {vec4(x.clone(),y.clone(),z.clone(),w.clone())}
pub fn vfromake_vec3(xyz:Vec3<T>,w:T)->Vec4<T> {vec4(xyz.x.clone(),xyz.y.clone(),xyz.z.clone(),w.clone())}
pub fn vfromake_vec2(xy:Vec2<T>,z:T,w:T)->Vec4<T> {vec4(xy.x.clone(),xy.y.clone(),z.clone(),w.clone())}
pub fn vfromake_vec2vec2(xy:Vec2<T>,zw:Vec2<T>)->Vec4<T> {vec4(xy.x.clone(),xy.y.clone(),zw.x.clone(),zw.y.clone())}
}
*/
impl<T:Clone> Vec8<T> {
pub fn clone_ref(a:&T,b:&T,c:&T,d:&T,e:&T,f:&T,g:&T,h:&T)->Vec8<T> {Vec8(a.clone(),b.clone(),c.clone(),d.clone(),e.clone(),f.clone(),g.clone(),h.clone())}
}
// this is getting silly.. needs macro..
impl<T:Clone> Vec16<T> {
pub fn clone_ref(a:&T,b:&T,c:&T,d:&T,e:&T,f:&T,g:&T,h:&T,
i:&T,j:&T,k:&T,l:&T,m:&T,n:&T,o:&T,p:&T)
->Vec16<T>
{Vec16(a.clone(),b.clone(),c.clone(),d.clone(),e.clone(),f.clone(),g.clone(),h.clone(),
i.clone(),j.clone(),k.clone(),l.clone(),m.clone(),n.clone(),o.clone(),p.clone())}
}
// vector constants should include 'zero','one' functions.
// 'origin' can mean something other than 'zero'.
pub trait VecConsts : Zero
{
fn origin()->Self;
fn vaxis(i:int)->Self;
fn one()->Self;
}
/// vectorized bitwise operations for SIMD
/// todo .. componentwise shifts, aswell..
pub trait VecBitOps :Sized{
fn vand(&self,b:&Self)->Self;
fn vor(&self,b:&Self)->Self;
fn vxor(&self,b:&Self)->Self;
fn vnot(&self)->Self;
fn vnor(&self,b:&Self)->Self{ self.vor(b).vnot() }
fn vnand(&self,b:&Self)->Self{ self.vand(b).vnot() }
}
pub trait VSelect<X>{
fn vselect(&self,a:&X,b:&X)->X;
}
impl<B:VElem,T:BitSel<B>+VElem> VSelect<Vec4<B>> for Vec4<T> {
fn vselect(&self,a:&Vec4<B>,b:&Vec4<B>)->Vec4<B>{ vec4(self.x.bitsel(&a.x,&b.x),self.y.bitsel(&a.y,&b.y), self.z.bitsel(&a.z,&b.z), self.w.bitsel(&a.w,&b.w)) }
}
macro_rules! impl_vec_bit_ops{
(struct $VecN:ident<T>{$($elem:ident :T),*})=>{
impl<T:VElem+Sized+BitAnd<T,Output=T>+BitOr<T,Output=T>+Not<Output=T> +BitXor<T,Output=T>> VecBitOps for $VecN<T> {
fn vand(&self,b:&Self)->Self{
$VecN{ $( $elem:(self.$elem & b.$elem) ),* }
}
fn vnand(&self,b:&Self)->Self{
$VecN{ $( $elem:!(self.$elem & b.$elem) ),* }
}
fn vor(&self,b:&Self)->Self{
$VecN{ $( $elem:(self.$elem | b.$elem) ),* }
}
fn vnor(&self,b:&Self)->Self{
$VecN{ $( $elem:!(self.$elem | b.$elem) ),* }
}
fn vxor(&self,b:&Self)->Self{
$VecN{ $( $elem:(self.$elem ^ b.$elem) ),* }
}
fn vnot(&self)->Self{
$VecN{ $( $elem:!self.$elem ),* }
}
}
}
}
impl_vec_bit_ops!(struct Vec2<T>{x:T,y:T});
impl_vec_bit_ops!(struct Vec3<T>{x:T,y:T,z:T});
impl_vec_bit_ops!(struct Vec4<T>{x:T,y:T,z:T,w:T});
impl<X:VElem,T:BitSel<X>+VElem> VSelect<Vec3<X>> for Vec3<T> {
fn vselect(&self,a:&Vec3<X>,b:&Vec3<X>)->Vec3<X>{ vec3(self.x.bitsel(&a.x,&b.x),self.y.bitsel(&a.y,&b.y), self.z.bitsel(&a.z,&b.z)) }
}
trait AllBitOps :ops::BitAnd+ops::BitOr+ops::Not+ops::BitXor+Sized{type Output;}
impl<T:ops::BitAnd<Output=T>+ops::BitOr<Output=T>+ops::BitXor<Output=T>+ops::Not<Output=T>+ops::Not<Output=T>+Sized> AllBitOps for T{
type Output=T;
}
pub trait ToVec3z<T:VElem>{
fn to_vec3_z(&self,z:T)->Vec3<T>;
}
pub trait ToVec4<T:VElem>{
fn to_vec4(&self)->Vec4<T>;
}
pub trait ToVec4w<T:VElem>{
fn to_vec4_w(&self,w:T)->Vec4<T>;
}
pub trait ToVec4zw<T:VElem>{
fn to_vec4_zw(&self,z:T,w:T)->Vec4<T>;
}
pub trait ToVec2w<T:VElem>{
fn to_vec2(&self)->Vec2<T>;
}
impl<T:VElem> ToVec4w<T> for Vec3<T>{
fn to_vec4_w(&self, w:T)->Vec4<T>{vec4(self.x.clone(),self.y.clone(),self.z.clone(),w)}
}
impl<T:VElem> ToVec2<T> for Vec3<T>{
fn to_vec2(&self)->Vec2<T>{vec2(self.x.clone(),self.y.clone())}
}
impl<T:VElem> ToVec3<T> for Vec4<T>{
fn to_vec3(&self)->Vec3<T>{vec3(self.x.clone(),self.y.clone(),self.z.clone())}
}
impl<T:VElem> ToVec2<T> for Vec4<T>{
fn to_vec2(&self)->Vec2<T>{vec2(self.x.clone(),self.y.clone())}
}
impl<T:VElem> ToVec3z<T> for Vec2<T>{
fn to_vec3_z(&self, z:T)->Vec3<T>{vec3(self.x.clone(),self.y.clone(),z)}
}
impl<T:VElem> ToVec4zw<T> for Vec2<T>{
fn to_vec4_zw(&self, z:T,w:T)->Vec4<T>{vec4(self.x.clone(),self.y.clone(),z,w)}
}
// float/int conversions
pub trait VecConv {
type OUT_I32;
type OUT_U32;
type OUT_USIZE;
type OUT_ISIZE;
type OUT_F32;
type OUT_F64;
fn vto_i32(&self)->Self::OUT_I32;
fn vto_u32(&self)->Self::OUT_U32;
fn vto_isize(&self)->Self::OUT_ISIZE;
fn vto_usize(&self)->Self::OUT_USIZE;
fn vto_f32(&self)->Self::OUT_F32;
fn vto_f64(&self)->Self::OUT_F64;
}
macro_rules! impl_vec_conv{
($t:ty)=>{
impl VecConv for Vec3<$t>{
type OUT_I32=Vec3<i32>;
type OUT_U32=Vec3<u32>;
type OUT_F32=Vec3<f32>;
type OUT_F64=Vec3<f64>;
type OUT_ISIZE=Vec3<isize>;
type OUT_USIZE=Vec3<usize>;
fn vto_i32(&self)->Vec3<i32>{
vec3(self.x as i32,self.y as i32,self.z as i32)
}
fn vto_u32(&self)->Vec3<u32>{
vec3(self.x as u32,self.y as u32,self.z as u32)
}
fn vto_isize(&self)->Vec3<isize>{
vec3(self.x as isize,self.y as isize,self.z as isize)
}
fn vto_usize(&self)->Vec3<usize>{
vec3(self.x as usize,self.y as usize,self.z as usize)
}
fn vto_f32(&self)->Vec3<f32>{
vec3(self.x as f32,self.y as f32,self.z as f32)
}
fn vto_f64(&self)->Vec3<f64>{
vec3(self.x as f64,self.y as f64,self.z as f64)
}
}
}
}
impl_vec_conv!(f32);
impl_vec_conv!(i32);
impl_vec_conv!(u32);
impl_vec_conv!(usize);
impl_vec_conv!(f64);
impl_vec_conv!(isize);
impl<X:VElem,T:BitSel<X>+VElem> VSelect<Vec2<X>> for Vec2<T> {
fn vselect(&self,a:&Vec2<X>,b:&Vec2<X>)->Vec2<X>{ vec2(self.x.bitsel(&a.x,&b.x),self.y.bitsel(&a.y,&b.y)) }
}
pub trait BitSel<X>{
fn bitsel(&self,a:&X,b:&X)->X;
}
impl<X:VElem> BitSel<X> for bool {
fn bitsel(&self,a:&X,b:&X)->X{ if *self{*a}else{*b} }
}
impl BitSel<f32> for u32 {
fn bitsel(&self,a:&f32,b:&f32)->f32{ unimplemented!() /*mask malarky*/ }
}
/// concatenation/interleave/split operations,
/// 'treating vectors as fixed size collections' rather than just maths types,
/// Could be used to represent certain SIMD operations?
pub trait Concat {
type Elem;
type Output;
type Append;
type Pop;
type Split;
fn concat(&self,&Self)->Self::Output;
fn interleave(&self,&Self)->Self::Output;
fn split(&self)->(Self::Split,Self::Split);
fn append(&self,&Self::Elem)->Self::Append; // eg generic 'to homogeneous'
fn pop(&self)->(Self::Pop,Self::Elem); // eg generic 'from homogeneous'
}
impl<T:VElem> Concat for Vec1<T>{
type Elem=T;
type Output=Vec2<T>;
type Append=Vec2<T>;
type Pop=(); //'Vec0<T' to propogate typeinfo? might be silly.
type Split=();
fn concat(&self,rhs:&Self)->Self::Output{
unimplemented!()
// Vec2::clone_ref(&self.x,&rhs.x)
}
fn interleave(&self,rhs:&Self)->Self::Output{
unimplemented!()
// Vec2::clone_ref(&self.x,&rhs.x)
}
fn append(&self,v:&T)->Self::Append{
unimplemented!()
// Vec2::clone_ref(&self.x, v)
}
fn pop(&self)->(Self::Pop,T){
((), self.x.clone())
}
fn split(&self)->(Self::Split,Self::Split){
unimplemented!()
}
}
impl<T:VElem> Concat for Vec2<T>{
type Elem=T;
type Output=Vec4<T>;
type Append=Vec3<T>;
type Pop=Vec1<T>;
type Split=Vec1<T>;
fn concat(&self,rhs:&Self)->Self::Output{
unimplemented!()
// Vec4::clone_ref(&self.x,&self.y, &rhs.x,&rhs.y)
}
fn interleave(&self,rhs:&Self)->Self::Output{
unimplemented!()
// Vec4::clone_ref(&self.x,&rhs.x, &self.y,&rhs.y)
}
fn append(&self,v:&T)->Self::Append{
unimplemented!()
// Vec3::clone_ref(&self.x,&self.y, v)
}
fn pop(&self)->(Self::Pop,T){
unimplemented!()
// (Vec1::clone_ref(&self.x), self.y.clone())
}
fn split(&self)->(Self::Split,Self::Split){
unimplemented!()
// (Vec1::clone_ref(&self.x),Vec1::clone_ref(&self.y))
}
}
impl<T:VElem> Concat for Vec4<T>{
type Elem=T;
type Output=Vec8<T>;
type Append=Vec4<T>;
type Pop=Vec3<T>;
type Split=Vec2<T>;
fn concat(&self,rhs:&Self)->Self::Output{
Vec8::clone_ref(&self.x,&self.y,&self.z,&self.w, &rhs.x,&rhs.y,&rhs.z,&rhs.w)
}
fn interleave(&self,rhs:&Self)->Self::Output{
Vec8::clone_ref(&self.x,&rhs.x, &self.y,&rhs.y , &self.z,&rhs.z , &self.w,&rhs.w)
}
fn append(&self,v:&T)->Self::Append{
unimplemented!()
}
fn pop(&self)->(Self::Pop,T){
unimplemented!()
// (Vec3::clone_ref(&self.x,&self.y,&self.z),self.w.clone())
}
fn split(&self)->(Self::Split,Self::Split){
unimplemented!()
// (Vec2::clone_ref(&self.x,&self.y),Vec2::clone_ref(&self.z,&self.w))
}
}
impl<T:VElem> Concat for Vec8<T>{
type Elem=T;
type Output=Vec16<T>;
type Append=();
type Pop=();
type Split=Vec4<T>;
fn concat(&self,rhs:&Self)->Self::Output{
Vec16::clone_ref(
&self.0,&self.1,&self.2,&self.3,
&self.4,&self.5,&self.6,&self.7,
&rhs.0,&rhs.1,&rhs.2,&rhs.3,
&rhs.4,&rhs.5,&rhs.6,&rhs.7
)
}
fn interleave(&self,rhs:&Self)->Self::Output{
Vec16::clone_ref(
&self.0,&rhs.0,
&self.1,&rhs.1,
&self.2,&rhs.2,
&self.3,&rhs.3,
&self.4,&rhs.4,
&self.5,&rhs.5,
&self.6,&rhs.6,
&self.7,&rhs.7,
)
}
fn append(&self,v:&T)->Self::Append{
unimplemented!()
}
fn pop(&self)->(Self::Pop,T){
unimplemented!()
}
fn split(&self)->(Self::Split,Self::Split){
unimplemented!()
// (Vec4::clone_ref(
// &self.0,&self.1,&self.2,&self.3),
// Vec4::clone_ref(
// &self.4,&self.5,&self.6,&self.7))
}
}
impl<T:Clone> Concat for Vec16<T>{
type Elem=T;
type Output=();
type Append=();
type Pop=();
type Split=Vec8<T>;
fn interleave(&self,rhs:&Self)->Self::Output{unimplemented!()}
fn concat(&self,rhs:&Self)->Self::Output{unimplemented!()}
fn append(&self,v:&T)->Self::Append{
unimplemented!()
}
fn pop(&self)->(Self::Pop,T){
unimplemented!()
}
fn split(&self)->(Self::Split,Self::Split){
(Vec8::clone_ref(
&self.0,&self.1,&self.2,&self.3,
&self.4,&self.5,&self.6,&self.7),
Vec8::clone_ref(
&self.8,&self.9,&self.10,&self.11,
&self.12,&self.13,&self.14,&self.15))
}
}
impl<T:VElem> Concat for Vec3<T>{
type Elem=T;
type Output=Vec8<T>;
type Append=Vec4<T>;
type Pop=Vec2<T>;
type Split=();
fn concat(&self,rhs:&Self)->Self::Output{
unimplemented!()
}
fn interleave(&self,rhs:&Self)->Self::Output{
unimplemented!()
}
fn append(&self,v:&T)->Self::Append{
unimplemented!()
// Vec4::clone_ref(&self.x, &self.y, &self.z, v)
}
fn pop(&self)->(Self::Pop,T){
unimplemented!()
// (Vec2::clone_ref(&self.x, &self.y), self.z.clone())
}
fn split(&self)->(Self::Split,Self::Split){
unimplemented!()
}
}
// fn rsub(&self,&b:Self)->Self { b.sub(self)}
/// splat operations aka vector broadcast.
/// May be simpler than full permutes,
/// does not require acess to the float type
pub trait PermuteXYZ {
}
pub trait Permute :Siblings {
// default implementation of permutes,
// can be over-ridden with platform-specific SIMD..
fn permute_x(&self)->Self::V1;
fn permute_y(&self)->Self::V1;
fn permute_z(&self)->Self::V1;
fn permute_w(&self)->Self::V1;
fn permute_xy(&self)->Self::V2;
fn permute_yx(&self)->Self::V2;
fn permute_xz(&self)->Self::V2;//Vec2<Self::ElemF>;
fn permute_yz(&self)->Self::V2;//Vec2<Self::ElemF>;
fn permute_zw(&self)->Self::V2;//Vec2<Self::ElemF>;
fn permute_xyz(&self)->Self::V3;//Vec3<Self::ElemF>;
fn permute_xyz0(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_xyz1(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_xyzw(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_wzyx(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_zyx(&self)->Self::V3;//Vec3<Self::ElemF>;
fn permute_xzy(&self)->Self::V3;//Vec3<Self::ElemF>;
fn to_vec4_pad0000(&self)->Self::V4;//Vec4<Self::ElemF>;
fn to_vec4_pad0001(&self)->Self::V4;//Vec4<Self::ElemF>;
// permutes for cross-product eval
// i j k
// ax ay az
// bx by bz
//
// plus
// x'=ay*bz-az*by
// y'=az*bx-ax*bz
// z'=ax*by-ay*bx
fn permute_yzx(&self)->Self::V3;//Vec3<Self::ElemF>;
fn permute_zxy(&self)->Self::V3;//Vec3<Self::ElemF>;
// cros product =
// a.yzx* b.zxy - a.zxy * b.yzx
fn permute_yzxw(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_zxyw(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_yzx0(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_zxy0(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_xx(&self)->Self::V2;//Vec2<Self::ElemF>;
fn permute_yy(&self)->Self::V2;//Vec2<Self::ElemF>;
fn permute_xxx(&self)->Self::V3;//Vec3<Self::ElemF>;
fn permute_yyy(&self)->Self::V3;//Vec3<Self::ElemF>;
fn permute_zzz(&self)->Self::V3;//Vec3<Self::ElemF>;
fn permute_xxxx(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_yyyy(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_zzzz(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_wwww(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_0(&self)->Self::V1;//Vec2<Self::ElemF>;
fn permute_00(&self)->Self::V2;//Vec2<Self::ElemF>;
fn permute_000(&self)->Self::V3;//Vec3<Self::ElemF>;
fn permute_0000(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_1000(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_0100(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_0010(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_0001(&self)->Self::V4;//Vec4<Self::ElemF>;
fn permute_1(&self)->Self::V1;//Vec2<Self::ElemF>;
fn permute_11(&self)->Self::V2;//Vec2<Self::ElemF>;
fn permute_111(&self)->Self::V3;//Vec3<Self::ElemF>;
fn permute_1111(&self)->Self::V4;//;Vec4<Self::ElemF>;
// transpose, pad with zeros most useful for 4 elements.
// verious ways to do this efficiently on SIMD machines..
// TODO , this should be a freefunction?
fn transpose4x4(ax:&Self,ay:&Self,az:&Self,aw:&Self)->(Self::V4,Self::V4,Self::V4,Self::V4);
}
/// interface for constructing siblings from components
/// note some vector types may deliberately hide per-component access.
pub trait ConstructSiblings: Siblings+HasElem{
fn make_vec1(x:Self::Elem)-> Self::V1;
fn make_vec2(x:Self::Elem,y:Self::Elem)->Self::V2;
fn make_vec3(x:Self::Elem,y:Self::Elem,z:Self::Elem)->Self::V3;
fn make_vec4(x:Self::Elem,y:Self::Elem,z:Self::Elem,w:Self::Elem)->Self::V4;
fn make_vec1_splat(x:Self::Elem)->Self::V1 { Self::make_vec1(x) }
fn make_vec2_splat(x:Self::Elem)->Self::V2 { Self::make_vec2(x.clone(),x) }
fn make_vec3_splat(x:Self::Elem)->Self::V3 { Self::make_vec3(x.clone(),x.clone(),x) }
fn make_vec4_splat(x:Self::Elem)->Self::V4 { Self::make_vec4(x.clone(),x.clone(),x.clone(),x) }
}
pub trait VecN : Siblings {} //'VecN family'
impl<T:VElem> VecN for Vec1<T>{}
impl<T:VElem> VecN for Vec2<T>{}
impl<T:VElem> VecN for Vec3<T>{}
impl<T:VElem> VecN for Vec4<T>{}
trait TupledVector {} //'VecN family'
impl<T:VElem> TupledVector for (T,){}
impl<T:VElem> TupledVector for (T,T){}
impl<T:VElem> TupledVector for (T,T,T){}
impl<T:VElem> TupledVector for (T,T,T,T){}
impl<V:VElem,T:VElem> ConstructSiblings for V
where
V:HasElem<Elem=T>,
V: HasElem+VecN
+Siblings<
V1=Vec1<T>,
V2=Vec2<T>,
V3=Vec3<T>,
V4=Vec4<T>
>
{
fn make_vec1(x:Self::Elem)->Vec1<V::Elem> { vec1(x) }
fn make_vec2(x:Self::Elem,y:Self::Elem)->Self::V2 {vec2(x,y)}
fn make_vec3(x:Self::Elem,y:Self::Elem,z:Self::Elem)->Self::V3{vec3(x,y,z)}
fn make_vec4(x:Self::Elem,y:Self::Elem,z:Self::Elem,w:Self::Elem)->Self::V4{vec4(x,y,z,w)}
}
/*
impl<V:VecSiblings+HasFloatElem+TupledVector> VecConstructSiblings for V{
fn make_vec1(x:Self::ElemF)->Self::V1{ (x,) }
fn make_vec2(x:Self::ElemF,y:Self::ElemF)->Self::V2{(x,y,)}
fn make_vec3(x:Self::ElemF,y:Self::ElemF,z:Self::ElemF)->Self::V3{(x,y,z,)}
fn make_vec4(x:Self::ElemF,y:Self::ElemF,z:Self::ElemF,w:Self::ElemF)->Self::V4{(x,y,z,w,)}
}
*/
/// Implement VecPermute for default case with 'VecFLoatAccessors'
/// note that permute interface should allow an impl WITHOUT use of a scalar type.
/// TODO decouple from specifc 'V2,V3 ,V4 versions' to allow impl on tuples,[T;N]
impl<T:Zero+One+Clone,V:VecAccessors+ConstructSiblings+HasElem<Elem=T>> Permute for V {
// default implementation of permutes,
// can be over-ridden with platform-specific SIMD..
fn permute_x(&self)->Self::V1 { Self::make_vec1(self.vx())}
fn permute_y(&self)->Self::V1 { Self::make_vec1(self.vy())}
fn permute_z(&self)->Self::V1 { Self::make_vec1(self.vz())}
fn permute_w(&self)->Self::V1 { Self::make_vec1(self.vw())}
fn permute_xy(&self)->Self::V2 { Self::make_vec2(self.vx(),self.vy())}
fn permute_yx(&self)->Self::V2 { Self::make_vec2(self.vy(),self.vx())}
fn permute_xz(&self)->Self::V2 { Self::make_vec2(self.vx(),self.vz())}
fn permute_yz(&self)->Self::V2 { Self::make_vec2(self.vy(),self.vz())}
fn permute_zw(&self)->Self::V2 { Self::make_vec2(self.vz(),self.vw())}
fn permute_xyz(&self)->Self::V3 { Self::make_vec3(self.vx(),self.vy(),self.vz())}
fn permute_xyz0(&self)->Self::V4 { Self::make_vec4(self.vx(),self.vy(),self.vz(), Zero::zero())} // vec3 to homogeneous offset
fn permute_xyz1(&self)->Self::V4 { Self::make_vec4(self.vx(),self.vy(),self.vz(), One::one())} // vec3 to homogeneous point
fn permute_xyzw(&self)->Self::V4 { Self::make_vec4(self.vx(),self.vy(),self.vz(),self.vw())} // vec3 to homogeneous point
fn permute_wzyx(&self)->Self::V4 { Self::make_vec4(self.vw(),self.vz(),self.vy(),self.vx())} // vec3 to homogeneous point
fn permute_zyx(&self)->Self::V3 { Self::make_vec3(self.vz(),self.vy(),self.vx())} // when using as color components
fn permute_xzy(&self)->Self::V3 { Self::make_vec3(self.vx(),self.vz(),self.vy())} // changing which is up, y or z
fn to_vec4_pad0000(&self)->Self::V4 {Self::make_vec4(self.vx(),self.vy(),self.vz(),Zero::zero())}
fn to_vec4_pad0001(&self)->Self::V4 {Self::make_vec4(self.vx(),self.vy(),self.vz(),One::one())}
// permutes for cross-product eval
// i j k
// ax ay az
// bx by bz
//
// plus
// x'=ay*bz-az*by
// y'=az*bx-ax*bz
// z'=ax*by-ay*bx
fn permute_yzx(&self)->Self::V3 {Self::make_vec3(self.vy(),self.vz(),self.vx())}
fn permute_zxy(&self)->Self::V3 {Self::make_vec3(self.vz(),self.vx(),self.vy())}
// cros product =
// a.yzx* b.zxy - a.zxy * b.yzx
fn permute_yzxw(&self)->Self::V4 {Self::make_vec4(self.vy(),self.vz(),self.vx(), self.vw())}
fn permute_zxyw(&self)->Self::V4 {Self::make_vec4(self.vz(),self.vx(),self.vy(), self.vw())}
fn permute_yzx0(&self)->Self::V4 {Self::make_vec4(self.vy(),self.vz(),self.vx(), Zero::zero())}
fn permute_zxy0(&self)->Self::V4 {Self::make_vec4(self.vz(),self.vx(),self.vy(), Zero::zero())}
fn permute_xx(&self)->Self::V2 { Self::make_vec2(self.vx(),self.vx()) }
fn permute_yy(&self)->Self::V2 { Self::make_vec2(self.vy(),self.vy()) }
fn permute_xxx(&self)->Self::V3 { Self::make_vec3(self.vx(),self.vx(),self.vx()) }
fn permute_yyy(&self)->Self::V3 { Self::make_vec3(self.vy(),self.vy(),self.vy()) }
fn permute_zzz(&self)->Self::V3 { Self::make_vec3(self.vz(),self.vz(),self.vz()) }
fn permute_xxxx(&self)->Self::V4 { Self::make_vec4(self.vx(),self.vx(),self.vx(),self.vx()) }
fn permute_yyyy(&self)->Self::V4 { Self::make_vec4(self.vy(),self.vy(),self.vy(),self.vy()) }
fn permute_zzzz(&self)->Self::V4 { Self::make_vec4(self.vz(),self.vz(),self.vz(),self.vz()) }
fn permute_wwww(&self)->Self::V4 { Self::make_vec4(self.vw(),self.vw(),self.vw(),self.vw()) }
fn permute_0(&self)->Self::V1 { Self::make_vec1_splat(Zero::zero())}
fn permute_00(&self)->Self::V2 { Self::make_vec2_splat(Zero::zero())}
fn permute_000(&self)->Self::V3 { Self::make_vec3_splat(Zero::zero())}
fn permute_0000(&self)->Self::V4 { Self::make_vec4_splat(Zero::zero())}
fn permute_0001(&self)->Self::V4 { Self::make_vec4(Zero::zero(),Zero::zero(),Zero::zero(),One::one())}
fn permute_1000(&self)->Self::V4 { Self::make_vec4(One::one(), Zero::zero(),Zero::zero(),Zero::zero())}
fn permute_0100(&self)->Self::V4 { Self::make_vec4(Zero::zero(),One::one(), Zero::zero(),Zero::zero())}
fn permute_0010(&self)->Self::V4 { Self::make_vec4(Zero::zero(),Zero::zero(),One::one(), Zero::zero())}
fn permute_1(&self)->Self::V1 { Self::make_vec1_splat(One::one())}
fn permute_11(&self)->Self::V2 { Self::make_vec2_splat(One::one())}
fn permute_111(&self)->Self::V3 { Self::make_vec3_splat(One::one())}
fn permute_1111(&self)->Self::V4 { Self::make_vec4_splat(One::one())}
// transpose, pad with zeros most useful for 4 elements.
// verious ways to do this efficiently on SIMD machines..
fn transpose4x4(ax:&Self,ay:&Self,az:&Self,aw:&Self)->(
Self::V4,
Self::V4,
Self::V4,
Self::V4
)
{
( Self::make_vec4(ax.vx(),ay.vx(),az.vx(),aw.vx()),
Self::make_vec4(ax.vy(),ay.vy(),az.vy(),aw.vy()),
Self::make_vec4(ax.vz(),ay.vz(),az.vz(),aw.vz()),
Self::make_vec4(ax.vw(),ay.vw(),az.vw(),aw.vw())
)
}
}
// free function interface.
pub fn transpose4x4<V:Permute+VecAccessors>(a:&V,b:&V,c:&V,d:&V)->(
<V as Siblings>::V4,
<V as Siblings>::V4,
<V as Siblings>::V4,
<V as Siblings>::V4,
)
{ Permute::transpose4x4(a,b,c,d)
}
// assumptions - might not even have accessible component.
pub trait VecNumOps :Sized
{
fn vassign_add(&mut self, b:&Self){ *self=self.vadd(b);}
fn vassign_sub(&mut self, b:&Self){ *self=self.vsub(b);}
fn vadd(&self, b: &Self) -> Self;
fn vsub(&self, b: &Self) -> Self;
}
pub trait VecCmpOps :Sized+HasElem {
type CmpOutput;
fn vassign_min(&mut self,b:&Self){*self=self.vmin(b);}
fn vassign_max(&mut self,b:&Self){*self=self.vmax(b);}
fn vmin(&self,b:&Self)->Self;
fn vmax(&self,b:&Self)->Self;
fn gt(&self,b:&Self)->Self::CmpOutput;
fn lt(&self,b:&Self)->Self::CmpOutput;
fn vclamp(&self,a:&Self,b:&Self)->Self{
self.vmin(b).vmax(a)
}
//fn vclamp_s(&self,a:&Self)->Self{
// self.vclamp(a.vneg(),a)
// }
// fn vclamp_scalar(&self, a:Self::Elem)->Self{
// self.vclamp(Self::splat(-a),Self::splat(a))
// }
fn vclamp_scalar_range(&self, smin:Self::Elem,smax:Self::Elem)->Self{unimplemented!()}
fn vclamp_scalar(&self, s:Self::Elem)->Self{unimplemented!()}
}
// select masks.
trait Select<V>{
fn select(&self,iftrue:V,iffalse:V)->V;
}
impl<T:VElem> Select<Vec3<T>> for Vec3<bool> where bool:Select<T>{
fn select(&self,a:Vec3<T>,b:Vec3<T>)->Vec3<T> {
vec3( self.x .select(a.x,b.x), self.y .select(a.y,b.y), self.z .select(a.z,b.z) )
}
}
impl<T:VElem,BOOL:VElem> Select<Vec4<T>> for Vec4<BOOL> where BOOL:Select<T>{
fn select(&self,a:Vec4<T>,b:Vec4<T>)->Vec4<T> {
vec4( self.x .select(a.x,b.x), self.y .select(a.y,b.y), self.z .select(a.z,b.z) , self.w .select(a.w,b.w) )
}
}
impl<T:VElem,BOOL:VElem> Select<Vec8<T>> for Vec8<BOOL> where BOOL:Select<T>{
fn select(&self,a:Vec8<T>,b:Vec8<T>)->Vec8<T> {
Vec8( self.0 .select(a.0,b.0), self.1 .select(a.1,b.1), self.2 .select(a.2,b.2) , self.3 .select(a.3,b.3) ,
self.4 .select(a.4,b.4), self.5 .select(a.5,b.5), self.6 .select(a.6,b.6) , self.7 .select(a.7,b.7)
)
}
}
impl<T,BOOL> Select<Vec16<T>> for Vec16<BOOL> where BOOL:Select<T>{
fn select(&self,a:Vec16<T>,b:Vec16<T>)->Vec16<T> {
Vec16( self.0 .select(a.0,b.0), self.1 .select(a.1,b.1), self.2 .select(a.2,b.2) , self.3 .select(a.3,b.3) ,
self.4 .select(a.4,b.4), self.5 .select(a.5,b.5), self.6 .select(a.6,b.6) , self.7 .select(a.7,b.7),
self.8 .select(a.8,b.8), self.9 .select(a.9,b.9), self.10 .select(a.10,b.10) , self.11 .select(a.11,b.11) ,
self.12 .select(a.12,b.12), self.13 .select(a.13,b.13), self.14 .select(a.14,b.14) , self.15 .select(a.15,b.15),
)
}
}
impl Select<f32> for bool {
fn select(&self,a:f32,b:f32)->f32{ if *self{a}else{b}}
}
impl Select<f64> for bool {
fn select(&self,a:f64,b:f64)->f64{ if *self{a}else{b}}
}
/// helper trait to extract inner type, if the vector was referenced generically without the component available. e.g. for Vec4<f32> 'Elem=f32'
/// allows bounding to assert that it's dealing with vectors.
/// Only valid for vector types with the same 'T' for each component.
/// TODO clean up confusion - HasElem vs HasElemFloat vs Permute vs VecOps
/// helper trait to say this has elements, only guarantees raw data (eg a number bits, doesn't say what operations it has..).
///
/// Only valid for types with the same 'T' per component.
/// TODO clean up confusion - HasElem vs HasElemFloat vs Permute vs VecOps
pub trait HasElem{
type Elem : Clone;
fn vget(&self,i:i32)->Self::Elem{
unimplemented!()
}
}
/// horizontal add = summing the elements, e.g. dot product can be = multiply elements and horizontal-add.
pub trait HorizAdd {
type Output;
fn horiz_add(&self)->Self::Output;
}
pub trait HorizMul {
type Output;
fn horiz_mul(&self)->Self::Output;
}
pub trait HorizOr {
type Output;
fn horiz_or(&self)->Self::Output;
}
pub trait HorizAnd {
type Output;
fn horiz_and(&self)->Self::Output;
}
macro_rules! impl_componentwise_reduction_vec_functions{
($FnTrait:ident::$fnname:ident using $TraitOp:ident::$op:ident)=>
{
impl<T:VElem> $FnTrait for Vec2<T> where for<'a,'b> &'a T:$TraitOp<&'b T,Output=T> {
type Output=T;
fn $fnname(&self)->T{self.x.$op(&self.y)}
}
impl<T:VElem> $FnTrait for Vec3<T> where for<'a,'b> &'a T:$TraitOp<&'b T,Output=T> {
type Output=T;
fn $fnname(&self)->T{(&self.x).$op(&self.y).$op(&self.z)}
}
impl<T:VElem> $FnTrait for Vec4<T> where for<'a,'b> &'a T:$TraitOp<&'b T,Output=T> {
type Output=T;
fn $fnname(&self)->T{(self.x.$op(&self.y)).$op(&self.z.$op(&self.w))}
}
}
}
impl_componentwise_reduction_vec_functions!(HorizAdd::horiz_add using Add::add);
impl_componentwise_reduction_vec_functions!(HorizMul::horiz_mul using Mul::mul);
impl_componentwise_reduction_vec_functions!(HorizOr::horiz_or using BitOr::bitor);
impl_componentwise_reduction_vec_functions!(HorizAnd::horiz_and using BitAnd::bitand);
/// wraps any vector type to imply that it is Normalized.
/// exposes only versions of operations that make sense for normalized vectors.
/// e.g. dont need '.normalize()' because it could only have been generated by that.
/// TODO: properly imply the dimensionless-ness of the inner float value
pub struct Normal<V=Vec3<f32>>(pub V);
impl<T:Float,V:VecOps<Elem=T>> Normal<V> {
pub fn as_vec(&self)->V{self.0.clone()}
pub fn vlerp_norm(&self,b:&Self,f:V::Elem)->Self { Normal(self.0.vlerp(&b.0, f).vnormalize()) }
pub fn vmadd_norm(&self,b:&Self,f:V::Elem )->Self { Normal(self.0.vmadd(&b.0,f).vnormalize()) }
pub fn vmadd2_norm(&self,b:&Self,fb:V::Elem,c:&Self,fc:V::Elem )->Self { Normal(self.0.vmadd(&b.0,fb).vmadd(&c.0,fc).vnormalize()) }
pub fn vcross_norm(&self,b:&Self)->Self{ Normal(self.0 .vcross(&b.0).vnormalize() )}
pub fn vscale(&self,f:V::Elem)->V{self.0.vscale(f)}
pub fn vsub(&self,b:&Self)->V{self.0.vsub(&b.0)}
pub fn vdot_with_normal(&self,b:&Self)->V::Elem { self.0 .vdot(&b.0)}
pub fn vdot_with_vec(&self,b:&V)->V::Elem { self.0 .vdot(&b)}
}
/// Wraps any vector type to imply that it is a Point
/// hides methods that are inapplicable to Points, etc.
pub struct Point<V=Vec3<f32>>(pub V);
impl<T:Float,V:VMath<Elem=T>> Point<V> {
pub fn vsub(&self,b:&Self)->Vector<V>{ Vector(self.0 .vsub(&b.0)) }
pub fn vadd(&self,b:&Vector<V>)->Point<V>{ Point(self.0 .vadd(&b.0)) }
pub fn vsub_norm(&self,b:&Self)->Normal<V>{ Normal(self.0 .vsub_norm(&b.0)) }
pub fn vmadd(&self,b:&Vector<V>, f:V::Elem)->Point<V>{ Point(self.0 .vmadd(&b.0, f)) }
pub fn vlerp(&self,b:&Point<V>, f:V::Elem)->Point<V>{ Point(self.0 .vlerp(&b.0, f)) }
pub fn vtriangle_norm(&self,b:&Self,c:&Self)->Normal<V> { Normal(self.0 .vsub(&b.0) .vcross_norm(&self.0 .vsub(&c.0)))}
pub fn vdist(&self,b:&Self)->V::Elem{ (self.0.vsub(&b.0)).vlength() }
pub fn vmax(&self,b:&Self)->Point<V>{ Point(self.0.vmax(&b.0)) }
pub fn vmin(&self,b:&Self)->Point<V>{ Point(self.0.vmin(&b.0)) }
}
/// Wraps any vector type to imply that it is a Vector
/// hides methods that are specific to points, normals, ..
pub struct Vector<V>(pub V);
impl<T:Float,V:VMath<Elem=T>> Vector<V> {
pub fn vdot(&self,b:&Self)->V::Elem { self.0 .vdot(&b.0) }
pub fn vdot_normal(&self,b:&Normal<V>)->V::Elem { self.0 .vdot(&b.0) }
pub fn vsub(&self,b:&Self)->V { self.0 .vsub(&b.0) }
pub fn vsub_norm(&self,b:&Self)->Normal<V>{ Normal(self.0 .vsub_norm(&b.0)) }
pub fn vcross(&self,b:&Self)->Vector<V>{ Vector(self.0.vcross(&b.0))}
pub fn vnormalize(&self)->Normal<V>{ Normal(self.0.vnormalize())}
pub fn vcross_norm(&self,b:&Self)->Normal<V>{ Normal(self.0.vcross(&b.0).vnormalize())}
pub fn vmadd(&self,b:&V, f:V::Elem)->Point<V>{ Point(self.0 .vmadd(b, f)) }
pub fn vlerp(&self,b:&Point<V>, f:V::Elem)->Point<V>{ Point(self.0 .vlerp(&b.0, f)) }
pub fn vlength(&self)->V::Elem { self.0 .vlength() }
pub fn vdist(&self,b:&Self)->V::Elem{ (self.0.vsub(&b.0)).vlength() }
pub fn vmax(&self,b:&Self)->Vector<V>{ Vector(self.0.vmax(&b.0)) }
pub fn vmin(&self,b:&Self)->Vector<V>{ Vector(self.0.vmin(&b.0)) }
}
//use super::vec_xyzw::conversions::IsNot;
macro_rules! impl_conversion_vecn{
($Wrapper:ident<V>,$VecN:ident<$T:ident>)=>{
impl<V:IsNot<$VecN<$T>>> From<$Wrapper<$VecN<$T>>> for $Wrapper<V> where $VecN<$T>:Into<V>{
fn from(src:$Wrapper<$VecN<$T>>)->$Wrapper<V>{
$Wrapper(src.0.into())
}
}
/*