2009-06-27 46 views
3

在做一些重構時,我發現我經常使用一對或浮點數來表示一個初始值,以及這個值隨着時間的推移而線性變化。我想創建一個結構來保存這兩個字段,但我無法找到它的正確名稱。需要幫助命名代表值和它的線性變化的類

它應該是這個樣子:

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

任何建議將非常感激。

+0

好問題,我經常發現命名是最重要的。你可以被困在一個問題上,然後考慮命名,當你命名的權利,問題就會消失! – 2009-06-27 11:14:57

+0

同意。國際海事組織,正確的命名一般是程序員最困難的任務之一。找到正確的名字意味着對問題和解決方案的全面理解。 – Trap 2009-06-27 11:56:36

回答

1

既然你有一個初始值,並且有一個值表示'某事'如何演變,你可以使用類似「線性函數」的東西。

我還要補充必要的成員函數:

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; 
    } 
}; 

或者我在這裏給渴望?

1

我想我寧願這樣的命名:

struct ValueDeltaDuplet 
{ 
    float Value; 
    float Delta;  
} 
0
struct ValueSlopePair 
{ 
    float Value; 
    float Slope;  
} 
-1
struct FloatPair 
{ 
    float Value; 
    float Slope;  
} 
1

初始值+恆定的斜率。這不是一個仿射函數?

1

感覺像 「縮放」 我...

struct ValueScale 
{ 
    float Value; 
    float Slope; 
} 

也許

struct ScalableValue 
{ 
    float Value; 
    float Slope; 
} 
1

這就像Arithmetic progression(或等差數列)

struct sequence_num_t { 
    float value; 
    float delta; 
}; 

struct SequencePoint 
{ 
    float Value; 
    float Delta; 
}; 
+0

+1我喜歡背後數學概念的鏈接。我只需要一個'酷'和容易的名字:) – Trap 2009-06-27 10:35:01