Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. -- some operations should be supported by bigger 'objects' e.g.
  2. -- vertices , valid to say 'whats the maximum of each component of 2 vertices', 'blend 2 vertices..'
  3. -- but vertices are not necaserily vectors?.. the data within is in different spaces (position, color, normal..)
  4.  
  5. class VertexOps v where
  6. vlerp::Num s=>v->s->v
  7. vmin::v->v->v
  8. vmax::v->v->v
  9.  
  10. -- TODO some of this might be monad malarky? (fmap? liftM2? )
  11. class VectorOps x where
  12. vbinop::(a->b->c) -> x a -> x b -> x c -- for binary operation between two vectors
  13. vreduce::(a->a->a) -> x a -> a -- for componentwise 'reduction' e.g. for sum-elements
  14. vscalarop::(a->b->c) -> x a -> b -> x c -- for binary operations between a vector and a scalar
  15. ????
  16.  
  17. // Rust..
  18. // trait VectorOps e.g. VecXYZ
  19. // trait AllOps : VectorOps+VertexOps
  20. // trait VertexOps e.g. PointColorNormal
  21. // 'T' = the scalar type inside..
  22.  
  23. trait VectorOps<T> {
  24. fn vbinop<F>(&self,b:&Self, f:F)->Self // use to roll add,sub,mul, ...
  25. where F:Fn(T,T)->T;
  26. ..
  27. }
  28. trait VertexOps<T> {
  29. fn vlerp(&self,b:&Self,f:T)->Self
  30. fn vmin(&self,:b:&Self)->Self
  31. fn vmax(&self,:b:&Self)->Self
  32. }
  33. // 'for any 'V' that supports Vector Ops, implement VertexOps trivially.
  34. impl<T:Num,V:VectorOps<T>> VertexOps<T> for V {
  35. fn vlerp(&self,b:&V,f:T)->V { a + (b-a)*f }
  36.  
  37. }
  38. trait AllOps<T> : VectorOps<T>,VertexOps<T>{} // just combines them
  39. impl<V:VectorOps<T>+VertexOps> AllOps for V{} // required to actually instantiate
  40. // now we can bound types with 'AllOps' for everthing, or just 'VertexOps' for 'vlerp,vmin,vmax'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement