需要帮助命名一个代表值及其线性变化的类

发布于 2024-07-25 04:11:51 字数 226 浏览 5 评论 0原文

在进行一些重构时,我发现我经常使用一对或浮点数来表示初始值以及该值随时间线性变化的程度。 我想创建一个结构来保存这两个字段,但我找不到它的正确名称。

它应该看起来像这样:

struct XXX
{
    float Value;
    float Slope; // or Delta? or 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

没︽人懂的悲伤 2024-08-01 04:11:51

由于您有一个初始值和一个指示“某物”如何演变的值,因此您可以选择“线性函数”之类的值。

我还会添加必要的成员函数:

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

或者我是否渴望在这里?

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?

混浊又暗下来 2024-08-01 04:11:51

我想我更喜欢这种命名:

struct ValueDeltaDuplet
{
    float Value;
    float Delta;    
}

I guess i would prefer this kind of naming:

struct ValueDeltaDuplet
{
    float Value;
    float Delta;    
}
人事已非 2024-08-01 04:11:51

初始值+常数斜率:这不是仿射函数吗?

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

ゃ懵逼小萝莉 2024-08-01 04:11:51

对我来说感觉就像一个“秤”......

struct ValueScale
{
    float Value;
    float Slope;
}

或者也许

struct ScalableValue
{
    float Value;
    float Slope;
}

Feels like a "Scale" to me...

struct ValueScale
{
    float Value;
    float Slope;
}

or maybe

struct ScalableValue
{
    float Value;
    float Slope;
}
宁愿没拥抱 2024-08-01 04:11:51

就像算术级数(或算术序列)

struct sequence_num_t {
    float value;
    float delta;
};

struct SequencePoint
{
   float Value;
   float Delta;
};

It's like Arithmetic progression (or arithmetic sequence)

struct sequence_num_t {
    float value;
    float delta;
};

or

struct SequencePoint
{
   float Value;
   float Delta;
};
情话已封尘 2024-08-01 04:11:51
struct ValueSlopePair
{
    float Value;
    float Slope;    
}
struct ValueSlopePair
{
    float Value;
    float Slope;    
}
网白 2024-08-01 04:11:51
struct FloatPair
{
    float Value;
    float Slope;    
}
struct FloatPair
{
    float Value;
    float Slope;    
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文