Improve line rounding compensation

This commit is contained in:
Loch Christian (uib05376) 2020-11-14 21:47:48 +01:00
parent 771371ed06
commit 40f030276e
2 changed files with 12 additions and 8 deletions

View File

@ -15,6 +15,7 @@
</set> </set>
</option> </option>
<option name="resolveModulePerSourceSet" value="false" /> <option name="resolveModulePerSourceSet" value="false" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings> </GradleProjectSettings>
</option> </option>
</component> </component>

View File

@ -74,8 +74,10 @@ public class Renderer {
synchronized (holder) { synchronized (holder) {
int y = 0; int y = 0;
int left = 0; int left = 0;
int compensate = 0; int hCompensateStart = 0;
float vCompensate = 0; int hCompensateEnd = 0;
int vCompensateStart = 0;
int vCompensateEnd = 0;
canvas.drawColor(Color.BLACK); canvas.drawColor(Color.BLACK);
for (int curStepIdx = this.track.getVtrList().size()-1;curStepIdx >= 0; for (int curStepIdx = this.track.getVtrList().size()-1;curStepIdx >= 0;
curStepIdx--) { curStepIdx--) {
@ -85,17 +87,18 @@ public class Renderer {
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
return; return;
} }
vCompensate = Math.round(y * this.tooShortPerHeight); vCompensateStart = Math.round(y * this.tooShortPerHeight);
vCompensateEnd = Math.round((y+this.pixelPerLine) * this.tooShortPerHeight);
stepRecords = this.track.getVtrList().get(curStepIdx); stepRecords = this.track.getVtrList().get(curStepIdx);
int i = 0; int i = 0;
for (VehicleTimeRecord r : stepRecords) { for (VehicleTimeRecord r : stepRecords) {
left = (int) (this.pixelPerVehicle * r.getPosition()); left = (int) (this.pixelPerVehicle * r.getPosition());
compensate = Math.round(r.getPosition() * this.tooShortPerTrackLength); hCompensateStart = Math.round(r.getPosition() * this.tooShortPerTrackLength);
hCompensateEnd = Math.round((r.getPosition() + this.pixelPerVehicle) * this.tooShortPerTrackLength);
this.paint.setColor(getColor(r.getVelocity(), r.getMaxVelocity())); this.paint.setColor(getColor(r.getVelocity(), r.getMaxVelocity()));
canvas.drawRect(left + compensate, y+vCompensate, canvas.drawRect(left + hCompensateStart, y+vCompensateStart,
left + this.pixelPerVehicle + compensate, left + this.pixelPerVehicle + hCompensateEnd,
y + pixelPerLine + vCompensate, this.paint); y + pixelPerLine + vCompensateEnd, this.paint);
i++; i++;
} }
track.getListSemaphore().release(); track.getListSemaphore().release();