What Should I Name These Types?

BlitzMax Forums/BlitzMax Beginners Area/What Should I Name These Types?

lukehedman(Posted 2009) [#1]
So I'm setting up some raw, basic types. Right now I've working on vectors. I'm not having trouble implanting methods. What gets me is something more silly.

Originally each vector was to have four fields: X, Y, Angle, and Magnitude. When I started implanting the type into a game I realized how clunky it was. An instance's position and facing are stored as vectors. This leads to some extra fields lying around. A facing only needs an angle, not a set of cords.

So I've split the vector into two types. One uses X and Y, and the other uses Angle and Magnitude. They can easy interface with each other and I've added conversion methods too.

I know this seems kind of picky, but what should I name them? Both types are vectors right? Maybe the angle/mag one should be called a compass or something. I dunno.

Thoughts?


GaryV(Posted 2009) [#2]
Pancho and Lefty?


lukehedman(Posted 2009) [#3]
Wow. I laughed so hard.


Gabriel(Posted 2009) [#4]
I'm not really sure what you need the angle and magnitude object for at all. Both angle and magnitude can be derived from the x and y components of the vector. If you think you're going to need them much, why not just give your vector methods called GetAngle:Float() and GetMagnitude:Float()?


lukehedman(Posted 2009) [#5]
Hmm... I didn't think of that.

However, my worry is that calculating a drawing angle from a facing vector every frame might be too expensive. The point of the Angle/Mag vector is to reduce the number of needed calculations.

Who knows though. Maybe a little more sine and cosine wouldn't hurt.


Gabriel(Posted 2009) [#6]
Well if it proves expensive and you do this a lot of times each frame, then I would go back to your original combined type. You might be wasting a few bytes for each vector but memory is unlikely to be in such short supply that a few bytes here and there will matter. So if you need to optimize, it would be fairly simple to rewrite the GetAngle And GetMagnitude methods to return the fields and then change the Set methods so that they calculate the angle and magnitude when the x and y components are set and vice versa. By using methods you're ensuring that all other code in your game can remain unchanged and you'll be able to test your optimization with a few lines of code.


Brucey(Posted 2009) [#7]
A gold star to Gabriel for encouraging encapsulation :-)


lukehedman(Posted 2009) [#8]
Agreed. Good idea Gabriel. Adding two doubles for each vector wouldn't offset the benefits of merging the types.

Back to being a code monkey I go!