"Fix" chart rendering winding when rendering straight lines
This commit is contained in:
parent
5ea1b5d004
commit
ac9095b58d
@ -63,16 +63,23 @@ fun renderGraph(
|
|||||||
val xDiff = x1 - x0
|
val xDiff = x1 - x0
|
||||||
val yDiff = y1 - y0
|
val yDiff = y1 - y0
|
||||||
|
|
||||||
val length = (xDiff.pow(2f) + yDiff.pow(2f)).pow(0.5f)
|
if (yDiff.sign == 0f) {
|
||||||
val angle = acos(xDiff / length) * yDiff.sign - PI / 2f // rotate 90 deg
|
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 xDisp = cos(angle).toFloat() * LINE_WIDTH / 2f
|
||||||
val yDisp = sin(angle).toFloat() * LINE_WIDTH / 2f
|
val yDisp = sin(angle).toFloat() * LINE_WIDTH / 2f
|
||||||
|
|
||||||
builder.vertex(pose, x1 - xDisp, y1 + yDisp, 0f)
|
builder.vertex(pose, x0 + xDisp, y0 + 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, x1 - xDisp, y1 - yDisp, 0f)
|
||||||
builder.vertex(pose, x0 - xDisp, y0 + yDisp, 0f)
|
builder.vertex(pose, x1 + xDisp, y1 + yDisp, 0f)
|
||||||
|
}
|
||||||
|
|
||||||
//graphics.renderRect(x0, y0, LINE_WIDTH, LINE_WIDTH)
|
//graphics.renderRect(x0, y0, LINE_WIDTH, LINE_WIDTH)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user