Browse Source

Improve line rounding compensation

tags/Release_1
Loch Christian (uib05376) 3 years ago
parent
commit
40f030276e
2 changed files with 12 additions and 8 deletions
  1. +1
    -0
      .idea/gradle.xml
  2. +11
    -8
      app/src/main/java/de/hems/trafficsim/Renderer.java

+ 1
- 0
.idea/gradle.xml View File

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

+ 11
- 8
app/src/main/java/de/hems/trafficsim/Renderer.java View File

@@ -74,8 +74,10 @@ public class Renderer {
synchronized (holder) {
int y = 0;
int left = 0;
int compensate = 0;
float vCompensate = 0;
int hCompensateStart = 0;
int hCompensateEnd = 0;
int vCompensateStart = 0;
int vCompensateEnd = 0;
canvas.drawColor(Color.BLACK);
for (int curStepIdx = this.track.getVtrList().size()-1;curStepIdx >= 0;
curStepIdx--) {
@@ -85,17 +87,18 @@ public class Renderer {
} catch (InterruptedException ex) {
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);
int i = 0;
for (VehicleTimeRecord r : stepRecords) {
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()));
canvas.drawRect(left + compensate, y+vCompensate,
left + this.pixelPerVehicle + compensate,
y + pixelPerLine + vCompensate, this.paint);
canvas.drawRect(left + hCompensateStart, y+vCompensateStart,
left + this.pixelPerVehicle + hCompensateEnd,
y + pixelPerLine + vCompensateEnd, this.paint);
i++;
}
track.getListSemaphore().release();


Loading…
Cancel
Save