diff --git a/README.rst b/README.rst index d29f9142d0db8a726eb6196c3086afcae1b6a033..14708870b7f503cc14287ac6db5e6bbb465614a8 100644 --- a/README.rst +++ b/README.rst @@ -52,5 +52,6 @@ Authors * Sharada Mohanty <mohanty@aicrowd.com> * Giacomo Spigler <giacomo.spigler@gmail.com> * Mattias Ljungström <ml@mljx.io> +* Jeremy Watson <please fill yourself in> diff --git a/flatland/utils/rendertools.py b/flatland/utils/rendertools.py index 75f61507caa5dd76d6936c63cdf1fc0824ded0c2..dc29c434ddb4e164f710c83867b90f9a072b99e9 100644 --- a/flatland/utils/rendertools.py +++ b/flatland/utils/rendertools.py @@ -125,7 +125,7 @@ class RenderTool(object): else: return gTransRCAg - def plotAgent(self, rcPos, iDir, sColor): + def plotAgent(self, rcPos, iDir, sColor="r"): """ Plot a simple agent. Assumes a working matplotlib context. @@ -278,14 +278,22 @@ class RenderTool(object): visit = visitDest xyPrev = None while visit.prev is not None: - # rDist = np.linalg.norm(array(visit.xy) - array(xyTarg)) - # xLoc = rDist + visit.iDir / 4 - # print (visit.xy) xy = np.matmul(visit.rc, rt.grc2xy) + rt.xyHalf if xyPrev is not None: - plt.plot([xy[0], xyPrev[0]], - [xy[1], xyPrev[1]], - color="r", alpha=0.5, lw=3) + dx, dy = (xyPrev - xy) / 20 + xyLine = array([xy, xyPrev]) + array([dy, dx]) + + plt.plot(*xyLine.T, color="r", alpha=0.5, lw=1) + + xyMid = np.sum(xyLine * [[1/4], [3/4]], axis=0) + + xyArrow = array([ + xyMid + [-dx-dy, +dx-dy], + xyMid, + xyMid + [-dx+dy, -dx-dy] + ]) + plt.plot(*xyArrow.T, color="r") + visit = visit.prev xyPrev = xy @@ -411,10 +419,13 @@ class RenderTool(object): plt.xlim([0, env.width * cell_size]) plt.ylim([-env.height * cell_size, 0]) - plt.xticks(np.linspace(0, env.width * cell_size, env.width+1)) - plt.yticks(np.linspace(-env.height * cell_size, 0, env.height+1), - np.abs(np.linspace(-env.height * cell_size, - 0, env.height+1))) + gTicks = (np.arange(0, env.height) + 0.5) * cell_size + gLabels = np.arange(0, env.height) + plt.xticks(gTicks, gLabels) + + gTicks = np.arange(-env.height * cell_size, 0) + cell_size/2 + gLabels = np.arange(env.height, 0, -1) + plt.yticks(gTicks, gLabels) plt.xlim([0, env.width * cell_size]) plt.ylim([-env.height * cell_size, 0]) diff --git a/images/basic-env.png b/images/basic-env.png index 4799468af4b0d188874e3f0145103a1cb738f6dd..a2cda73e7425888066bf88409a94823c41806e1c 100644 Binary files a/images/basic-env.png and b/images/basic-env.png differ diff --git a/images/env-path.png b/images/env-path.png new file mode 100644 index 0000000000000000000000000000000000000000..9027b6da0b79b496afac10869c7713d3ee552d86 Binary files /dev/null and b/images/env-path.png differ diff --git a/images/env-tree-graph.png b/images/env-tree-graph.png new file mode 100644 index 0000000000000000000000000000000000000000..9b2a2d6a9cc4792c962e0fdbdd87f233aaac7d7d Binary files /dev/null and b/images/env-tree-graph.png differ diff --git a/images/env-tree-spatial.png b/images/env-tree-spatial.png new file mode 100644 index 0000000000000000000000000000000000000000..16eff313d318fa1aaa4f0a8a3f7866aba98a3568 Binary files /dev/null and b/images/env-tree-spatial.png differ diff --git a/images/test/basic-env.png b/images/test/basic-env.png deleted file mode 100644 index 4799468af4b0d188874e3f0145103a1cb738f6dd..0000000000000000000000000000000000000000 Binary files a/images/test/basic-env.png and /dev/null differ diff --git a/tests/test_rendertools.py b/tests/test_rendertools.py index 3153434eb96ac6af388bec8d1611bf1fa8d61f89..e9296095e220b7555cf7af076d706dfaf0db305d 100644 --- a/tests/test_rendertools.py +++ b/tests/test_rendertools.py @@ -58,5 +58,27 @@ def test_render_env(): checkFrozenImage("basic-env.png") + plt.figure(figsize=(10,10)) + oRT.renderEnv() + lVisits = oRT.plotTreeOnRail( + oEnv.agents_position[0], + oEnv.agents_direction[0], + nDepth=17) + + checkFrozenImage("env-tree-spatial.png") + + plt.figure(figsize=(8,8)) + xyTarg = oRT.env.agents_target[0] + visitDest = oRT.plotTree(lVisits, xyTarg) + + checkFrozenImage("env-tree-graph.png") + + + oFig = plt.figure(figsize=(10,10)) + oRT.renderEnv() + oRT.plotPath(visitDest) + + checkFrozenImage("env-path.png") + \ No newline at end of file