naming-conventionsnaming

Need help naming a class which represents a value and its linear variation


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.


Solution

  • 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?