console and mining tab visual improvements
This commit is contained in:
@@ -1021,43 +1021,49 @@ void RenderMiningTab(App* app)
|
||||
}
|
||||
|
||||
// Catmull-Rom spline interpolation for smooth curve
|
||||
// Subdivisions are adaptive: more when points are far apart,
|
||||
// none when points are already sub-2px apart.
|
||||
std::vector<ImVec2> points;
|
||||
if (n <= 2) {
|
||||
points = rawPts;
|
||||
} else {
|
||||
const int subdivs = 8; // segments between each pair of data points
|
||||
points.reserve((n - 1) * subdivs + 1);
|
||||
points.reserve(n * 4); // conservative estimate
|
||||
for (size_t i = 0; i + 1 < n; i++) {
|
||||
// Four control points: p0, p1, p2, p3
|
||||
ImVec2 p0 = rawPts[i > 0 ? i - 1 : 0];
|
||||
ImVec2 p1 = rawPts[i];
|
||||
ImVec2 p2 = rawPts[i + 1];
|
||||
ImVec2 p3 = rawPts[i + 2 < n ? i + 2 : n - 1];
|
||||
|
||||
// Adaptive subdivision: ~1 segment per 3px of distance
|
||||
float dx = p2.x - p1.x, dy = p2.y - p1.y;
|
||||
float dist = sqrtf(dx * dx + dy * dy);
|
||||
int subdivs = std::clamp((int)(dist / 3.0f), 1, 16);
|
||||
|
||||
for (int s = 0; s < subdivs; s++) {
|
||||
float t = (float)s / (float)subdivs;
|
||||
float t2 = t * t;
|
||||
float t3 = t2 * t;
|
||||
// Catmull-Rom basis
|
||||
float q0 = -t3 + 2.0f * t2 - t;
|
||||
float q1 = 3.0f * t3 - 5.0f * t2 + 2.0f;
|
||||
float q2 = -3.0f * t3 + 4.0f * t2 + t;
|
||||
float q3 = t3 - t2;
|
||||
float sx = 0.5f * (p0.x * q0 + p1.x * q1 + p2.x * q2 + p3.x * q3);
|
||||
float sy = 0.5f * (p0.y * q0 + p1.y * q1 + p2.y * q2 + p3.y * q3);
|
||||
// Clamp Y to plot bounds to prevent Catmull-Rom overshoot
|
||||
sy = std::clamp(sy, plotTop, plotBottom);
|
||||
points.push_back(ImVec2(sx, sy));
|
||||
}
|
||||
}
|
||||
points.push_back(rawPts[n - 1]); // final point
|
||||
}
|
||||
|
||||
// Fill under curve
|
||||
for (size_t i = 0; i + 1 < points.size(); i++) {
|
||||
ImVec2 quad[4] = {
|
||||
points[i], points[i + 1],
|
||||
ImVec2(points[i + 1].x, plotBottom),
|
||||
ImVec2(points[i].x, plotBottom)
|
||||
};
|
||||
dl->AddConvexPolyFilled(quad, 4, WithAlpha(Success(), 25));
|
||||
// Fill under curve (single concave polygon to avoid AA seam shimmer)
|
||||
if (points.size() >= 2) {
|
||||
for (size_t i = 0; i < points.size(); i++)
|
||||
dl->PathLineTo(points[i]);
|
||||
dl->PathLineTo(ImVec2(points.back().x, plotBottom));
|
||||
dl->PathLineTo(ImVec2(points.front().x, plotBottom));
|
||||
dl->PathFillConcave(WithAlpha(Success(), 25));
|
||||
}
|
||||
|
||||
// Green line
|
||||
|
||||
Reference in New Issue
Block a user