floorplan

This commit is contained in:
Kseninia Mikhaylova 2024-05-20 09:36:01 +03:00
parent 8e48b92f42
commit 4587407811
3 changed files with 55 additions and 256 deletions

View File

@ -1,39 +1,4 @@
[ [
{
"label": "annotations",
"importPath": "__future__",
"description": "__future__",
"isExtraImport": true,
"detail": "__future__",
"documentation": {}
},
{
"label": "os",
"kind": 6,
"isExtraImport": true,
"importPath": "os",
"description": "os",
"detail": "os",
"documentation": {}
},
{
"label": "site",
"kind": 6,
"isExtraImport": true,
"importPath": "site",
"description": "site",
"detail": "site",
"documentation": {}
},
{
"label": "sys",
"kind": 6,
"isExtraImport": true,
"importPath": "sys",
"description": "sys",
"detail": "sys",
"documentation": {}
},
{ {
"label": "json", "label": "json",
"kind": 6, "kind": 6,
@ -132,6 +97,15 @@
"detail": "gyp.common", "detail": "gyp.common",
"documentation": {} "documentation": {}
}, },
{
"label": "os",
"kind": 6,
"isExtraImport": true,
"importPath": "os",
"description": "os",
"detail": "os",
"documentation": {}
},
{ {
"label": "posixpath", "label": "posixpath",
"kind": 6, "kind": 6,
@ -275,6 +249,15 @@
"detail": "code", "detail": "code",
"documentation": {} "documentation": {}
}, },
{
"label": "sys",
"kind": 6,
"isExtraImport": true,
"importPath": "sys",
"description": "sys",
"detail": "sys",
"documentation": {}
},
{ {
"label": "hashlib", "label": "hashlib",
"kind": 6, "kind": 6,
@ -1550,78 +1533,6 @@
"detail": "django.db", "detail": "django.db",
"documentation": {} "documentation": {}
}, },
{
"label": "migrations",
"importPath": "django.db",
"description": "django.db",
"isExtraImport": true,
"detail": "django.db",
"documentation": {}
},
{
"label": "migrations",
"importPath": "django.db",
"description": "django.db",
"isExtraImport": true,
"detail": "django.db",
"documentation": {}
},
{
"label": "models",
"importPath": "django.db",
"description": "django.db",
"isExtraImport": true,
"detail": "django.db",
"documentation": {}
},
{
"label": "migrations",
"importPath": "django.db",
"description": "django.db",
"isExtraImport": true,
"detail": "django.db",
"documentation": {}
},
{
"label": "models",
"importPath": "django.db",
"description": "django.db",
"isExtraImport": true,
"detail": "django.db",
"documentation": {}
},
{
"label": "migrations",
"importPath": "django.db",
"description": "django.db",
"isExtraImport": true,
"detail": "django.db",
"documentation": {}
},
{
"label": "models",
"importPath": "django.db",
"description": "django.db",
"isExtraImport": true,
"detail": "django.db",
"documentation": {}
},
{
"label": "migrations",
"importPath": "django.db",
"description": "django.db",
"isExtraImport": true,
"detail": "django.db",
"documentation": {}
},
{
"label": "models",
"importPath": "django.db",
"description": "django.db",
"isExtraImport": true,
"detail": "django.db",
"documentation": {}
},
{ {
"label": "models", "label": "models",
"importPath": "django.db", "importPath": "django.db",
@ -1833,87 +1744,6 @@
"detail": "django.core.wsgi", "detail": "django.core.wsgi",
"documentation": {} "documentation": {}
}, },
{
"label": "bin_dir",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "bin_dir = os.path.dirname(abs_file)\nbase = bin_dir[: -len(\"bin\") - 1] # strip away the bin part from the __file__, plus the path separator\n# prepend bin to PATH (this file is inside the bin directory)\nos.environ[\"PATH\"] = os.pathsep.join([bin_dir, *os.environ.get(\"PATH\", \"\").split(os.pathsep)])\nos.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"interactive-table-py3.10\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.10/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))",
"detail": ".venv.bin.activate_this",
"documentation": {}
},
{
"label": "base",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "base = bin_dir[: -len(\"bin\") - 1] # strip away the bin part from the __file__, plus the path separator\n# prepend bin to PATH (this file is inside the bin directory)\nos.environ[\"PATH\"] = os.pathsep.join([bin_dir, *os.environ.get(\"PATH\", \"\").split(os.pathsep)])\nos.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"interactive-table-py3.10\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.10/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path.decode(\"utf-8\") if \"\" else path)",
"detail": ".venv.bin.activate_this",
"documentation": {}
},
{
"label": "os.environ[\"PATH\"]",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "os.environ[\"PATH\"] = os.pathsep.join([bin_dir, *os.environ.get(\"PATH\", \"\").split(os.pathsep)])\nos.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"interactive-table-py3.10\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.10/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path.decode(\"utf-8\") if \"\" else path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix",
"detail": ".venv.bin.activate_this",
"documentation": {}
},
{
"label": "os.environ[\"VIRTUAL_ENV\"]",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "os.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"interactive-table-py3.10\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.10/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path.decode(\"utf-8\") if \"\" else path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base",
"detail": ".venv.bin.activate_this",
"documentation": {}
},
{
"label": "os.environ[\"VIRTUAL_ENV_PROMPT\"]",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "os.environ[\"VIRTUAL_ENV_PROMPT\"] = \"interactive-table-py3.10\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.10/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path.decode(\"utf-8\") if \"\" else path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base",
"detail": ".venv.bin.activate_this",
"documentation": {}
},
{
"label": "prev_length",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "prev_length = len(sys.path)\nfor lib in \"../lib/python3.10/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path.decode(\"utf-8\") if \"\" else path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base",
"detail": ".venv.bin.activate_this",
"documentation": {}
},
{
"label": "sys.path[:]",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base",
"detail": ".venv.bin.activate_this",
"documentation": {}
},
{
"label": "sys.real_prefix",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "sys.real_prefix = sys.prefix\nsys.prefix = base",
"detail": ".venv.bin.activate_this",
"documentation": {}
},
{
"label": "sys.prefix",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "sys.prefix = base",
"detail": ".venv.bin.activate_this",
"documentation": {}
},
{ {
"label": "_Known", "label": "_Known",
"kind": 6, "kind": 6,
@ -8408,55 +8238,10 @@
"kind": 6, "kind": 6,
"importPath": "back.api.migrations.0001_initial", "importPath": "back.api.migrations.0001_initial",
"description": "back.api.migrations.0001_initial", "description": "back.api.migrations.0001_initial",
"peekOfCode": "class Migration(migrations.Migration):\n initial = True\n dependencies = [\n ]\n operations = [\n migrations.CreateModel(\n name='Task',\n fields=[\n ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n ('title', models.CharField(max_length=100)),", "peekOfCode": "class Migration(migrations.Migration):\n initial = True\n dependencies = [\n ]\n operations = [\n migrations.CreateModel(\n name='Floorplan',\n fields=[\n ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n ('title', models.CharField(max_length=200)),",
"detail": "back.api.migrations.0001_initial", "detail": "back.api.migrations.0001_initial",
"documentation": {} "documentation": {}
}, },
{
"label": "Migration",
"kind": 6,
"importPath": "back.api.migrations.0002_rename_task_product",
"description": "back.api.migrations.0002_rename_task_product",
"peekOfCode": "class Migration(migrations.Migration):\n dependencies = [\n ('api', '0001_initial'),\n ]\n operations = [\n migrations.RenameModel(\n old_name='Task',\n new_name='Product',\n ),\n ]",
"detail": "back.api.migrations.0002_rename_task_product",
"documentation": {}
},
{
"label": "Migration",
"kind": 6,
"importPath": "back.api.migrations.0003_product_model3d",
"description": "back.api.migrations.0003_product_model3d",
"peekOfCode": "class Migration(migrations.Migration):\n dependencies = [\n ('api', '0002_rename_task_product'),\n ]\n operations = [\n migrations.AddField(\n model_name='product',\n name='model3d',\n field=models.FileField(default=None, null=True, upload_to=''),\n ),",
"detail": "back.api.migrations.0003_product_model3d",
"documentation": {}
},
{
"label": "Migration",
"kind": 6,
"importPath": "back.api.migrations.0004_product_description",
"description": "back.api.migrations.0004_product_description",
"peekOfCode": "class Migration(migrations.Migration):\n dependencies = [\n ('api', '0003_product_model3d'),\n ]\n operations = [\n migrations.AddField(\n model_name='product',\n name='description',\n field=models.TextField(default=None, null=True),\n ),",
"detail": "back.api.migrations.0004_product_description",
"documentation": {}
},
{
"label": "Migration",
"kind": 6,
"importPath": "back.api.migrations.0005_product_image1_alter_product_model3d",
"description": "back.api.migrations.0005_product_image1_alter_product_model3d",
"peekOfCode": "class Migration(migrations.Migration):\n dependencies = [\n ('api', '0004_product_description'),\n ]\n operations = [\n migrations.AddField(\n model_name='product',\n name='image1',\n field=models.ImageField(blank=True, default=None, null=True, upload_to='back/files'),\n ),",
"detail": "back.api.migrations.0005_product_image1_alter_product_model3d",
"documentation": {}
},
{
"label": "Migration",
"kind": 6,
"importPath": "back.api.migrations.0006_product_image2_product_image3",
"description": "back.api.migrations.0006_product_image2_product_image3",
"peekOfCode": "class Migration(migrations.Migration):\n dependencies = [\n ('api', '0005_product_image1_alter_product_model3d'),\n ]\n operations = [\n migrations.AddField(\n model_name='product',\n name='image2',\n field=models.ImageField(blank=True, default=None, null=True, upload_to='back/files'),\n ),",
"detail": "back.api.migrations.0006_product_image2_product_image3",
"documentation": {}
},
{ {
"label": "ApiConfig", "label": "ApiConfig",
"kind": 6, "kind": 6,

View File

@ -12,13 +12,16 @@ const canvasElement = ref();
const context = ref(); const context = ref();
const grid = ref<Grid>() const grid = ref<Grid>()
const startPoint = ref<{ x: number, y: number }>({ x: 13, y: 19 }) const startPoint = ref<{ x: number, y: number }>({ x: 27, y: 38 })
const endPoint = ref<{ x: number, y: number }>() const endPoint = ref<{ x: number, y: number }>()
const startToEndPath = ref() const startToEndPath = ref()
const plan = useFloorplanStore() const plan = useFloorplanStore()
const paths = ref<PathItem[]>([]) const paths = ref<PathItem[]>([])
const pathFinderProcess = ref(false)
const finder = new PF.DijkstraFinder();
const newDraw = () => { const newDraw = () => {
endPoint.value = undefined endPoint.value = undefined
startToEndPath.value = undefined startToEndPath.value = undefined
@ -52,37 +55,23 @@ const newDraw = () => {
} }
const findPath = async () => { const findPath = async () => {
const finder = new PF.DijkstraFinder(); if (!endPoint.value) return
const localPath = finder.findPath(
startToEndPath.value = finder.findPath(
Math.round(startPoint.value.x), Math.round(startPoint.value.x),
Math.round(startPoint.value.y), Math.round(startPoint.value.y),
Math.round(endPoint.value.x), Math.round(endPoint.value.x),
Math.round(endPoint.value.y), Math.round(endPoint.value.y),
(grid.value as Grid) (grid.value?.clone() as Grid)
); );
console.log({ path: startToEndPath.value.length }) startToEndPath.value = localPath
} }
const setPointSvg = (item: PathItem) => { const setPointSvg = (item: PathItem) => {
// startToEndPath.value = []
endPoint.value = { x: item.x, y: item.y } endPoint.value = { x: item.x, y: item.y }
findPath() findPath()
} }
const getFillStyle = (item: PathItem) => {
if (item.unwalkable) {
return 'rgba(0,0,0,0.5)'
} else if (item.x == startPoint.value.x && item.y == startPoint.value.y) {
return 'lawngreen'
} else if (endPoint.value && item.x == endPoint.value.x && item.y == endPoint.value.y) {
return 'blue'
} else if (startToEndPath.value && startToEndPath.value.find(el => el.x == item.x && el.y == item.y)) {
return 'gold'
} else {
return 'transparent'
}
}
onMounted(async () => { onMounted(async () => {
await floorplan.getData() await floorplan.getData()
newDraw() newDraw()
@ -92,13 +81,38 @@ onMounted(async () => {
<div class="container" style="display: flex; justify-content: center; align-items: center; flex-direction: column;"> <div class="container" style="display: flex; justify-content: center; align-items: center; flex-direction: column;">
<canvas ref="canvasElement" width="1200" height="600"></canvas> <canvas ref="canvasElement" width="1200" height="600"></canvas>
<svg ref="svgElement" width="1200" height="600" style="position: absolute;"> <svg ref="svgElement" width="1200" height="600" style="position: absolute;">
<path v-for="item in paths" :d="item.path" :fill="getFillStyle(item)" @click="setPointSvg(item)"> <path v-for="item in paths" :d="item.path" @click="setPointSvg(item)" :class="[
{ 'unwalkable': item.unwalkable },
{ 'endPoint': (endPoint && item.x == endPoint.x && item.y == endPoint.y) },
{ 'startPoint': (startPoint && item.x == startPoint.x && item.y == startPoint.y) },
{ 'pathPoint': (startToEndPath && startToEndPath.find((el: number[]) => el[0] == item.x && el[1] == item.y)) },
]">
</path> </path>
</svg> </svg>
</div> </div>
</template> </template>
<style scoped> <style scoped>
svg path {
fill: transparent
}
svg path:hover { svg path:hover {
fill: red fill: red
} }
svg path.unwalkable {
fill: rgba(0, 0, 0, 0.5);
}
svg path.endPoint {
fill: blue;
}
svg path.startPoint {
fill: lawngreen;
}
svg path.pathPoint {
fill: gold;
}
</style> </style>

View File

@ -6,7 +6,7 @@ export const useFloorplanStore = defineStore('floorplan', {
state: () => { state: () => {
return { return {
title: undefined, title: undefined,
chunkSize: 10, chunkSize: 5,
np_array: [] as number[][], np_array: [] as number[][],
prepared_array: [] as number[][] prepared_array: [] as number[][]
} }