Skip to content

Commit 49a0f88

Browse files
committed
fix(AttitudeDisplay): unduplicate position math code to fix inconsistencies
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
1 parent 688c636 commit 49a0f88

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

src/main/kotlin/ru/octol1ttle/flightassistant/impl/display/AttitudeDisplay.kt

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,17 @@ class AttitudeDisplay(computers: ComputerBus) : Display(computers) {
7171
ScreenSpace.getY(0.0f)?.let {
7272
val color = getPitchBarColor(0.0f)
7373

74-
val leftXEnd: Int = (centerX - halfWidth * 0.025f).toInt()
75-
val leftXStart: Int = (leftXEnd - halfWidth * 0.3f).toInt()
74+
val center = centerX.toInt()
75+
val fromCenter = (halfWidth * 0.025f).toInt()
76+
val width = (halfWidth * 0.3f).toInt()
77+
78+
val leftXEnd: Int = center - fromCenter
79+
val leftXStart: Int = leftXEnd - width
7680
drawRightAlignedString("0", leftXStart - 3, it - 3, color)
7781
hLine(leftXStart, leftXEnd, it, color)
7882

79-
val rightXStart: Int = (centerX + halfWidth * 0.025f).toInt()
80-
val rightXEnd: Int = (rightXStart + halfWidth * 0.3f).toInt()
83+
val rightXStart: Int = center + fromCenter
84+
val rightXEnd: Int = rightXStart + width
8185
hLine(rightXStart, rightXEnd, it, color)
8286
drawString("0", rightXEnd + 5, it - 3, color)
8387
}
@@ -87,12 +91,12 @@ class AttitudeDisplay(computers: ComputerBus) : Display(computers) {
8791
val step: Int = FAConfig.display.attitudeDegreeStep
8892
val nextUp: Int = Mth.roundToward(computers.data.pitch.toInt(), step)
8993
for (i: Int in nextUp..90 step step) {
90-
drawPitchBar(i, centerX, (ScreenSpace.getY(i.toFloat()) ?: break))
94+
drawPitchBar(i, centerX, ScreenSpace.getY(i.toFloat()) ?: break)
9195
}
9296

9397
val nextDown: Int = Mth.quantize(computers.data.pitch.toDouble(), step)
9498
for (i: Int in nextDown downTo -90 step step) {
95-
drawPitchBar(i, centerX, (ScreenSpace.getY(i.toFloat()) ?: break))
99+
drawPitchBar(i, centerX, ScreenSpace.getY(i.toFloat()) ?: break)
96100
}
97101
}
98102

@@ -133,12 +137,16 @@ class AttitudeDisplay(computers: ComputerBus) : Display(computers) {
133137
val y = ScreenSpace.getY(pitch) ?: return
134138

135139
val color: Int = getPitchBarColor(pitch)
136-
val leftXEnd: Int = (centerX - halfWidth * 0.025f).toInt()
137-
val leftXStart: Int = (leftXEnd - halfWidth * 0.05f).toInt()
140+
val center = centerX.toInt()
141+
val fromCenter = (halfWidth * 0.025f).toInt()
142+
val width = (halfWidth * 0.05f).toInt()
143+
144+
val leftXEnd: Int = center - fromCenter
145+
val leftXStart: Int = leftXEnd - width
138146
hLineDashed(leftXStart, leftXEnd, y, 2, color)
139147

140-
val rightXStart: Int = (centerX + halfWidth * 0.025f).toInt()
141-
val rightXEnd: Int = (rightXStart + halfWidth * 0.05f).toInt()
148+
val rightXStart: Int = center + fromCenter
149+
val rightXEnd: Int = rightXStart + width
142150
hLineDashed(rightXStart, rightXEnd, y, 2, color)
143151
}
144152

@@ -147,14 +155,18 @@ class AttitudeDisplay(computers: ComputerBus) : Display(computers) {
147155

148156
val color: Int = getPitchBarColor(pitch.toFloat())
149157

150-
val leftXEnd: Int = (centerX - halfWidth * 0.05f).toInt()
151-
val leftXStart: Int = (leftXEnd - halfWidth * 0.075f).toInt()
158+
val center = centerX.toInt()
159+
val fromCenter = (halfWidth * 0.05f).toInt()
160+
val width = (halfWidth * 0.075f).toInt()
161+
162+
val leftXEnd: Int = center - fromCenter
163+
val leftXStart: Int = leftXEnd - width
152164
drawRightAlignedString(pitch.toString(), leftXStart - 2, if (pitch > 0) y else y - 4, color)
153165
vLine(leftXStart, y, y + 5 * pitch.sign, color)
154166
hLineDashed(leftXStart, leftXEnd, y, if (pitch < 0) 3 else 1, color)
155167

156-
val rightXStart: Int = (centerX + halfWidth * 0.05f).toInt()
157-
val rightXEnd: Int = (rightXStart + halfWidth * 0.075f).toInt()
168+
val rightXStart: Int = center + fromCenter
169+
val rightXEnd: Int = rightXStart + width
158170
hLineDashed(rightXStart, rightXEnd, y, if (pitch < 0) 3 else 1, color)
159171
vLine(rightXEnd, y, y + 5 * pitch.sign, color)
160172
drawString(pitch.toString(), rightXEnd + 4, if (pitch > 0) y else y - 4, color)

0 commit comments

Comments
 (0)