diff --git a/flatland/utils/editor.py b/flatland/utils/editor.py index a1909bd20499bb2a52a1696ccf5ec6586fee10f2..5819b741731a58df5a133cfc60e2817fd481ee04 100644 --- a/flatland/utils/editor.py +++ b/flatland/utils/editor.py @@ -210,7 +210,11 @@ class View(object): self.writableData[(y - 2):(y + 2), (x - 2):(x + 2), :3] = 0 def xy_to_rc(self, x, y): - rcCell = ((array([y, x]) - self.yxBase) / self.nPixCell).astype(int) + rcCell = ((array([y, x]) - self.yxBase)) + nX = np.floor((self.yxSize[0] - self.yxBase[0])/ self.model.env.height) + nY = np.floor((self.yxSize[1] - self.yxBase[1])/ self.model.env.width) + rcCell[0] = max(0,min(np.floor(rcCell[0]/nY),self.model.env.height-1)) + rcCell[1] = max(0,min(np.floor(rcCell[1]/nX),self.model.env.width-1)) return rcCell def log(self, *args, **kwargs): diff --git a/notebooks/Editor2.ipynb b/notebooks/Editor2.ipynb index 4b99594cdde568e6e1df0456213da495c303db21..023d665c1f41f11a852e2607330a6311bda4c5f6 100644 --- a/notebooks/Editor2.ipynb +++ b/notebooks/Editor2.ipynb @@ -9,9 +9,18 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The autoreload extension is already loaded. To reload it, use:\n", + " %reload_ext autoreload\n" + ] + } + ], "source": [ "%load_ext autoreload\n", "%autoreload 2" @@ -19,7 +28,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -32,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -54,31 +63,23 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 12, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "cairo installed: OK\n" - ] - } - ], + "outputs": [], "source": [ "from flatland.utils.editor import EditorMVC, EditorModel, View, Controller" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "<flatland.utils.graphics_pil.PILSVG object at 0x000001E6748D1128> <class 'flatland.utils.graphics_pil.PILSVG'>\n", + "<flatland.utils.graphics_pil.PILSVG object at 0x0000020D4CDD2E10> <class 'flatland.utils.graphics_pil.PILSVG'>\n", "<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>\n", " 0000000000000000 Background_#91D1DD.svg\n", "WE 0000000000000100 Gleis_Deadend.svg\n", @@ -141,7 +142,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 14, "metadata": { "scrolled": false }, @@ -149,7 +150,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "0fd27ca20d9c411586c8ccae843f3950", + "model_id": "4c81e4d508834d7f93d104fd2642bc3a", "version_major": 2, "version_minor": 0 }, @@ -164,7 +165,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "<flatland.utils.graphics_pil.PILSVG object at 0x000001E674DEF048> <class 'flatland.utils.graphics_pil.PILSVG'>\n", + "<flatland.utils.graphics_pil.PILSVG object at 0x0000020D4CF49D30> <class 'flatland.utils.graphics_pil.PILSVG'>\n", "<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>\n", " 0000000000000000 Background_#91D1DD.svg\n", "WE 0000000000000100 Gleis_Deadend.svg\n", @@ -201,7 +202,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 15, "metadata": { "scrolled": false }, @@ -209,7 +210,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "e4c58e43c54847c7bc4ad0327ca506d8", + "model_id": "83b942888352481995b35116bb2237d9", "version_major": 2, "version_minor": 0 }, @@ -228,7 +229,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -237,7 +238,7 @@ "(0, 0)" ] }, - "execution_count": 8, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" }