"Fix" chart rendering winding when rendering straight lines

This commit is contained in:
DBotThePony 2024-10-01 09:35:41 +07:00
parent 5ea1b5d004
commit ac9095b58d
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -63,16 +63,23 @@ fun renderGraph(
val xDiff = x1 - x0
val yDiff = y1 - y0
val length = (xDiff.pow(2f) + yDiff.pow(2f)).pow(0.5f)
val angle = acos(xDiff / length) * yDiff.sign - PI / 2f // rotate 90 deg
if (yDiff.sign == 0f) {
builder.vertex(pose, x0, y0 + LINE_WIDTH / 2f, 0f)
builder.vertex(pose, x0, y0 - LINE_WIDTH / 2f, 0f)
builder.vertex(pose, x1, y1 - LINE_WIDTH / 2f, 0f)
builder.vertex(pose, x1, y1 + LINE_WIDTH / 2f, 0f)
} else {
val length = (xDiff.pow(2f) + yDiff.pow(2f)).pow(0.5f)
val angle = acos(xDiff / length) * yDiff.sign - PI / 2f // rotate 90 deg
val xDisp = cos(angle).toFloat() * LINE_WIDTH / 2f
val yDisp = sin(angle).toFloat() * LINE_WIDTH / 2f
val xDisp = cos(angle).toFloat() * LINE_WIDTH / 2f
val yDisp = sin(angle).toFloat() * LINE_WIDTH / 2f
builder.vertex(pose, x1 - xDisp, y1 + yDisp, 0f)
builder.vertex(pose, x1 + xDisp, y1 - yDisp, 0f)
builder.vertex(pose, x0 + xDisp, y0 - yDisp, 0f)
builder.vertex(pose, x0 - xDisp, y0 + yDisp, 0f)
builder.vertex(pose, x0 + xDisp, y0 + yDisp, 0f)
builder.vertex(pose, x0 - xDisp, y0 - yDisp, 0f)
builder.vertex(pose, x1 - xDisp, y1 - yDisp, 0f)
builder.vertex(pose, x1 + xDisp, y1 + yDisp, 0f)
}
//graphics.renderRect(x0, y0, LINE_WIDTH, LINE_WIDTH)