FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Some minor suggestions

 
Post new topic   Reply to topic     Forum Index -> Helix
View previous topic :: View next topic  
Author Message
baxissimo



Joined: 23 Oct 2006
Posts: 241
Location: Tokyo, Japan

PostPosted: Tue Oct 24, 2006 11:42 pm    Post subject: Some minor suggestions Reply with quote

Hey Helix looks great. Just a few minor suggestions.


  1. normalize methods. I like to return the length comptuted. It's relatively expensive to calculate, so you might as well return it. I find I often need the length.
  2. ptr method - instead of casting 'this' to float* you can cast &x to float. x,y,z will probably always be contiguous, but offsetof x could potentially change due to members added to the struct, changing from struct to class, changes in how structs are handled by the compiler, etc. &x is incrementally more robust, and just as easy and fast, so why not.
  3. completeBasis function? - I have a function I use to take 1 vector create 2 more vectors that together form an orthonormal basis. I find it handy. And you have "isBasis" functions already, makes sense to have a "makeBasis".
  4. updateMinMax(boxMin,boxMax) - updates boxMin and boxMax by enlarging them to enclose the given point. Handy for computing axis-aligned bounding boxes. With that you just need something like
    Code:

    Vector3f m=float.inf;
    Vector3f M= -float.inf;
    foreach(p; points) { p.updateMinMax(m,M); }

    (code not tested)
  5. union for vector types to provide array access (like you have for matrix and quat). This is better than .ptr for some situations in that float_t[3] can be checked for access violations in debug mode.
  6. maybe slightly faster quaternion opMulAssign?:
    Code:

      // (quat mult in 12 mults) -- straightforward way gets you 16.
      // but does introduce more dependencies
      Type A, B, C, D, E, F, G, H;

      A = (s   + v.x)*(q.s   + q.v.x);
      B = (v.z - v.y)*(q.v.y - q.v.z);
      C = (s   - v.x)*(q.v.y + q.v.z);
      D = (v.y + v.z)*(q.s   - q.v.x);
      E = (v.x + v.z)*(q.v.x + q.v.y);
      F = (v.x - v.z)*(q.v.x - q.v.y);
      G = (s   + v.y)*(q.s   - q.v.z);
      H = (s   - v.y)*(q.s   + q.v.z);

      v.x = A - (E + F + G + H) * Type(0.5);
      v.y = C + (E - F + G - H) * Type(0.5);
      v.z = D + (E - F - G + H) * Type(0.5);
      s = B + (-E - F + G + H) * Type(0.5);

  7. Methods for element-wise multiplication & division of vectors (and especially colors). I like to just use opMul etc for this, but I can understand the meaning of v1*v2 is not intrinsically clear.
  8. Methods/aliases to make using Matrix33/Vector3 as a homogeneous Matrix22,Vector2 easier (useful for 2D vector graphics ala OpenVG/Cairo). I.e. x,y,w accessors, etc.


That's all I can think of for now. Great stuff though.

Polar decomposition built in --- love it!
Back to top
View user's profile Send private message
baxissimo



Joined: 23 Oct 2006
Posts: 241
Location: Tokyo, Japan

PostPosted: Sun Oct 29, 2006 7:45 pm    Post subject: One more Reply with quote

One more suggestion: add a Matrix22.

I'll probably go ahead and add it to my copy myself.

And another one: outer products:

Code:

    /** Returns: Outer product between passed vectors. */
    Matrix22 outer(Vector2 a, Vector2 b)
    {
        return Matrix22( a.x * b.x, a.x * b.y,
                         a.y * b.x, a.y * b.y);
    }

    /** Returns: Outer product between passed vectors. */
    Matrix33 outer(Vector3 a, Vector3 b)
    {
        return Matrix33( a.x * b.x,  a.x * b.y,  a.x * b.z,
                         a.y * b.x,  a.y * b.y,  a.y * b.z,
                         a.z * b.x,  a.z * b.y,  a.z * b.z);
    }
     
    /** Returns: Outer product between passed vectors. */
    Matrix44 outer(Vector4 a, Vector4 b)
    {
        return Matrix44( a.x * b.x,  a.x * b.y,  a.x * b.z, a.x * b.w,
                         a.y * b.x,  a.y * b.y,  a.y * b.z, a.y * b.w,
                         a.z * b.x,  a.z * b.y,  a.z * b.z, a.z * b.w,
                         a.w * b.x,  a.w * b.y,  a.w * b.z, a.w * b.w);
    }
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Helix All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group