Skip to content

Commit

Permalink
fix(UI): vehicles with different width (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
soodoshll authored and only-changer committed Oct 23, 2019
1 parent 9a4766a commit 2d4b997
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
5 changes: 4 additions & 1 deletion frontend/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,24 +705,27 @@ function drawStep(step) {

carContainer.removeChildren();
turnSignalContainer.removeChildren();
let carLog, position, length;
let carLog, position, length, width;
for (let i = 0, len = carLogs.length - 1;i < len;++i) {
carLog = carLogs[i].split(' ');
position = transCoord([parseFloat(carLog[0]), parseFloat(carLog[1])]);
length = parseFloat(carLog[5]);
width = parseFloat(carLog[6]);
carPool[i][0].position.set(position[0], position[1]);
carPool[i][0].rotation = 2*Math.PI - parseFloat(carLog[2]);
carPool[i][0].name = carLog[3];
let carColorId = stringHash(carLog[3]) % CAR_COLORS_NUM;
carPool[i][0].tint = CAR_COLORS[carColorId];
carPool[i][0].width = length;
carPool[i][0].height = width;
carContainer.addChild(carPool[i][0]);

let laneChange = parseInt(carLog[4]) + 1;
carPool[i][1].position.set(position[0], position[1]);
carPool[i][1].rotation = carPool[i][0].rotation;
carPool[i][1].texture = turnSignalTextures[laneChange];
carPool[i][1].width = length;
carPool[i][1].height = width;
turnSignalContainer.addChild(carPool[i][1]);
}
nodeCarNum.innerText = carLogs.length-1;
Expand Down
3 changes: 2 additions & 1 deletion src/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ namespace CityFlow {
int lc = vehicle->lastLaneChangeDirection();
result.append(
double2string(pos.x) + " " + double2string(pos.y) + " " + double2string(atan2(dir.y, dir.x)) + " "
+ vehicle->getId() + " " + std::to_string(lc) + " " + double2string(vehicle->getLen())+ ",");
+ vehicle->getId() + " " + std::to_string(lc) + " " + double2string(vehicle->getLen()) + " "
+ double2string(vehicle->getWidth()) + ",");
}
result.append(";");

Expand Down
4 changes: 2 additions & 2 deletions tests/azure-pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ stages:
python_version: '3.7'
cxx_standard: '14'
target: 'all test'
- script: cp build/cityflow* . && python3.7 -m unittest discover tests/python/
- script: python3.7 -m pip install pyproj folium && cp build/cityflow* . && git clone https://github.com/cityflow-project/data.git && python3.7 -m unittest discover tests/python/
displayName: Python tests

- job: "osx"
Expand All @@ -101,5 +101,5 @@ stages:
python_version: '3'
cxx_standard: '14'
target: 'all test'
- script: cp build/cityflow* . && python3 -m unittest discover tests/python/
- script: python3 -m pip install pyproj folium && cp build/cityflow* . && git clone https://github.com/cityflow-project/data.git && python3 -m unittest discover tests/python/
displayName: Python tests
23 changes: 23 additions & 0 deletions tests/python/test_osm_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import unittest
import os
import json
from tools.converter.osm2cityflow import extract, draw


class TestOsmConverter(unittest.TestCase):
dataPath = os.getcwd() + '/data/tools/Converter/examples/'
osmFile = dataPath + 'statecollege.osm'
CityFlowFile = dataPath + 'statecollege_roadnet.json'

def test_converter(self):
nodes = extract(osmFile=self.osmFile)
draw(nodes, self.CityFlowFile, True)
with open(self.CityFlowFile, 'r') as f:
roadnet = json.load(f)
intersectionsNum = len(roadnet["intersections"])
roadsNum = len(roadnet["roads"])
self.assertTrue(intersectionsNum <= roadsNum)


if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit 2d4b997

Please sign in to comment.