views:

78

answers:

7

While doing some refactoring I've found that I'm quite often using a pair or floats to represent an initial value and how much this value linearly varies over time. I want to create a struct to hold both fields but I just can't find the right name for it.

It should look something like this:

struct XXX
{
    float Value;
    float Slope; // or Delta? or Variation? 
}

Any suggestions will be much appreciated.

+1  A: 

I guess i would prefer this kind of naming:

struct ValueDeltaDuplet
{
    float Value;
    float Delta;    
}
Arnis L.
A: 
struct ValueSlopePair
{
    float Value;
    float Slope;    
}
Jayden
A: 
struct FloatPair
{
    float Value;
    float Slope;    
}
Jayden
+1  A: 

Initial value + constant slope : isn't this an affine function ?

siukurnin
+1  A: 

Feels like a "Scale" to me...

struct ValueScale
{
    float Value;
    float Slope;
}

or maybe

struct ScalableValue
{
    float Value;
    float Slope;
}
chakrit
+1  A: 

It's like Arithmetic progression (or arithmetic sequence)

struct sequence_num_t {
    float value;
    float delta;
};

or

struct SequencePoint
{
   float Value;
   float Delta;
};
Nick D
+1 I liked the link to the mathematical concept behind. I just need a 'cool' and easy name for it :)
Trap
Ok :) What about the 2nd name?
Nick D
Well, I don't want clients of this class to assume it's either a point or a sequence. I want it to have a more abstract name (but not as loose as FloatPair)
Trap
+1  A: 

Since you have an initial value, and a value indicating how 'something' evolves, you could go with something like "Linear Function".

I would also add the necessary member functions:

struct LinearFunction {
    float constant;
    float slope;
    float increment( float delta ) const { return constant + delta*slope; }
    void add( const LinearFunction& other ) { constant += other.constant; slope += other.slope; }
    LinearFunction invert() const { 
        LinearFunction inv = { -constant/slope, 1./slope; };
        return inv;
    }
};

Or am I to eager here?

xtofl
Sorry for the silly question but, why call it 'function' if it just represents the data that will be used by the function?
Trap
After thinking a bit about it I think this is the perfect solution for my needs, thanks.
Trap