base: Add total() to Vector2D stat
This patch adds a total() function to the Vector2D stat type. Similar to other stats such as Scalar or Vector it is useful to be able to read the total for a given stat.
This commit is contained in:
parent
0020662459
commit
d25b58036a
3 changed files with 18 additions and 3 deletions
|
@ -159,6 +159,8 @@ class Vector2dInfoProxy : public InfoProxy<Stat, Vector2dInfo>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Vector2dInfoProxy(Stat &stat) : InfoProxy<Stat, Vector2dInfo>(stat) {}
|
Vector2dInfoProxy(Stat &stat) : InfoProxy<Stat, Vector2dInfo>(stat) {}
|
||||||
|
|
||||||
|
Result total() const { return this->s.total(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StorageParams
|
struct StorageParams
|
||||||
|
@ -1298,6 +1300,19 @@ class Vector2dBase : public DataWrapVec2d<Derived, Vector2dInfoProxy>
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a total of all entries in this vector.
|
||||||
|
* @return The total of all vector entries.
|
||||||
|
*/
|
||||||
|
Result
|
||||||
|
total() const
|
||||||
|
{
|
||||||
|
Result total = 0.0;
|
||||||
|
for (off_type i = 0; i < size(); ++i)
|
||||||
|
total += data(i)->result();
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
prepare()
|
prepare()
|
||||||
{
|
{
|
||||||
|
|
|
@ -229,6 +229,8 @@ class Vector2dInfo : public Info
|
||||||
mutable VCounter cvec;
|
mutable VCounter cvec;
|
||||||
|
|
||||||
void enable();
|
void enable();
|
||||||
|
|
||||||
|
virtual Result total() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FormulaInfo : public VectorInfo
|
class FormulaInfo : public VectorInfo
|
||||||
|
|
|
@ -588,7 +588,6 @@ Text::visit(const Vector2dInfo &info)
|
||||||
}
|
}
|
||||||
|
|
||||||
VResult tot_vec(info.y);
|
VResult tot_vec(info.y);
|
||||||
VResult super_total(1, 0.0);
|
|
||||||
for (off_type i = 0; i < info.x; ++i) {
|
for (off_type i = 0; i < info.x; ++i) {
|
||||||
if (havesub && (i >= info.subnames.size() || info.subnames[i].empty()))
|
if (havesub && (i >= info.subnames.size() || info.subnames[i].empty()))
|
||||||
continue;
|
continue;
|
||||||
|
@ -601,7 +600,6 @@ Text::visit(const Vector2dInfo &info)
|
||||||
yvec[j] = info.cvec[iy + j];
|
yvec[j] = info.cvec[iy + j];
|
||||||
tot_vec[j] += yvec[j];
|
tot_vec[j] += yvec[j];
|
||||||
total += yvec[j];
|
total += yvec[j];
|
||||||
super_total[0] += yvec[j];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print.name = info.name + "_" +
|
print.name = info.name + "_" +
|
||||||
|
@ -620,7 +618,7 @@ Text::visit(const Vector2dInfo &info)
|
||||||
print.name = info.name;
|
print.name = info.name;
|
||||||
print.subnames = total_subname;
|
print.subnames = total_subname;
|
||||||
print.desc = info.desc;
|
print.desc = info.desc;
|
||||||
print.vec = super_total;
|
print.vec = VResult(1, info.total());
|
||||||
print.flags = print.flags & ~total;
|
print.flags = print.flags & ~total;
|
||||||
print(*stream);
|
print(*stream);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue