Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- some operations should be supported by bigger 'objects' e.g.
- -- vertices , valid to say 'whats the maximum of each component of 2 vertices', 'blend 2 vertices..'
- -- but vertices are not necaserily vectors?.. the data within is in different spaces (position, color, normal..)
- class VertexOps v where
- vlerp::Num s=>v->s->v
- vmin::v->v->v
- vmax::v->v->v
- -- TODO some of this might be monad malarky? (fmap? liftM2? )
- class VectorOps x where
- vbinop::(a->b->c) -> x a -> x b -> x c -- for binary operation between two vectors
- vreduce::(a->a->a) -> x a -> a -- for componentwise 'reduction' e.g. for sum-elements
- vscalarop::(a->b->c) -> x a -> b -> x c -- for binary operations between a vector and a scalar
- ????
- // Rust..
- // trait VectorOps e.g. VecXYZ
- // trait AllOps : VectorOps+VertexOps
- // trait VertexOps e.g. PointColorNormal
- // 'T' = the scalar type inside..
- trait VectorOps<T> {
- fn vbinop<F>(&self,b:&Self, f:F)->Self // use to roll add,sub,mul, ...
- where F:Fn(T,T)->T;
- ..
- }
- trait VertexOps<T> {
- fn vlerp(&self,b:&Self,f:T)->Self
- fn vmin(&self,:b:&Self)->Self
- fn vmax(&self,:b:&Self)->Self
- }
- // 'for any 'V' that supports Vector Ops, implement VertexOps trivially.
- impl<T:Num,V:VectorOps<T>> VertexOps<T> for V {
- fn vlerp(&self,b:&V,f:T)->V { a + (b-a)*f }
- }
- trait AllOps<T> : VectorOps<T>,VertexOps<T>{} // just combines them
- impl<V:VectorOps<T>+VertexOps> AllOps for V{} // required to actually instantiate
- // 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