Skip to content

Commit 7c05bbc

Browse files
committed
Fix various array rendering issues
1 parent 778d8e7 commit 7c05bbc

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

Source/Objects/ArrayObject.h

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,15 @@ class GraphicalArray final : public Component
6767

6868
static Path createArrayPath(HeapArray<float> points, DrawType style, StackArray<float, 2> scale, float const width, float const height, float const lineWidth)
6969
{
70-
bool invert = false;
71-
if (scale[0] >= scale[1]) {
72-
invert = true;
73-
std::swap(scale[0], scale[1]);
74-
}
75-
7670
// Need at least 4 points to draw a bezier curve
7771
if (points.size() <= 4 && style == Curve)
7872
style = Polygon;
7973

80-
float const dh = (height - (lineWidth + 1)) / (scale[1] - scale[0]);
81-
float const invh = invert ? 0 : (height - (lineWidth + 1));
82-
float const yscale = invert ? -1.0f : 1.0f;
83-
84-
auto yToCoords = [dh, invh, scale, yscale](float y){
85-
return 1 + (invh - (std::clamp(y, scale[0], scale[1]) - scale[0]) * dh * yscale);
74+
float const pointOffset = style == Points;
75+
float const dh = (height - 2) / (scale[0] - scale[1]);
76+
77+
auto yToCoords = [scale, dh, pointOffset](float y){
78+
return ((((y - scale[1]) * dh) + 1) - pointOffset);
8679
};
8780

8881
auto const* pointPtr = points.data();
@@ -113,10 +106,10 @@ class GraphicalArray final : public Component
113106
float y = yToCoords(pointPtr[0]);
114107
minY = std::min(y, minY);
115108
maxY = std::max(y, maxY);
116-
109+
117110
if (i == 0 || i == numPoints-1 || std::abs(nextX - lastX) >= 1.0f)
118111
{
119-
result.addRectangle(lastX - 0.33f, minY, (nextX - lastX) + 0.33f, std::max((maxY - minY), lineWidth));
112+
result.addRectangle(lastX - 0.33f, minY, (nextX - lastX) + 0.33f, (maxY - minY) + lineWidth);
120113
lastX = nextX;
121114
minY = 1e20;
122115
maxY = -1e20;
@@ -291,9 +284,8 @@ class GraphicalArray final : public Component
291284
case hash("style"): {
292285
MessageManager::callAsync([_this = SafePointer(this), newDrawMode = static_cast<int>(atoms[0].getFloat())] {
293286
if (_this) {
294-
_this->drawMode = newDrawMode + 1;
295-
_this->updateSettings();
296-
_this->repaint();
287+
setValueExcludingListener(_this->drawMode, newDrawMode + 1, _this.getComponent());
288+
_this->updateArrayPath();
297289
}
298290
});
299291
break;

0 commit comments

Comments
 (0)