Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonnet-Songbird committed May 8, 2024
1 parent afaf660 commit 5992c8c
Show file tree
Hide file tree
Showing 7 changed files with 403 additions and 40 deletions.
Binary file added data/images/cruise-deck.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/cruise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 46 additions & 13 deletions data/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Path {
this.name = name;
this.posA = posA;
this.posB = posB;
this.restrict = restrict;
this.restrict = restrict; // 0 : 양방향 가능; 1: A to B; 2: B to A; 3 어느 쪽도 불가
}

pathLength() {
Expand All @@ -19,8 +19,8 @@ function addRandomPos(count) {
const pos = {
"id": id,
"name": `random ${count}`,
"x": Math.floor(Math.random() * 201 - 100) / 20,
"y": Math.floor(Math.random() * 201 - 100) / 20,
"x": (Math.floor(Math.random() * 201 - 100) / 20) * 50,
"y": (Math.floor(Math.random() * 201 - 100) / 20) * 50,
"z": 0,
"restrict": 0
}
Expand All @@ -46,34 +46,36 @@ const navRepo = {

, posRepo: [
{"id": 1, "name": "기준점", "x": 0, "y": 0, "z": 0}
, {"id": 2, "name": "x2", "x": 2, "y": 0, "z": 0}
, {"id": 3, "name": "x-2", "x": -2, "y": 0, "z": 0}
, {"id": 4, "name": "y2", "x": 0, "y": 2, "z": 0}
, {"id": 5, "name": "y-2", "x": 0, "y": -2, "z": 0}
, {"id": 2, "name": "x100", "x": 100, "y": 0, "z": 0}
, {"id": 3, "name": "x-100", "x": -100, "y": 0, "z": 0}
, {"id": 4, "name": "y100", "x": 0, "y": 100, "z": 0}
, {"id": 5, "name": "y-100", "x": 0, "y": -100, "z": 0}
, {"id": 6, "name": "z2", "x": 0, "y": 0, "z": 2}
, {"id": 7, "name": "rand1", "x": 0, "y": 0, "z": 0}
, {"id": 8, "name": "rand2", "x": 0, "y": 0, "z": 0}
, {"id": 9, "name": "rand3", "x": 0, "y": 0, "z": 0}
]
, markerRepo: [
{"id": 1, "name": "바코드1", "posId": 1},
{"id": 2, "name": "바코드2", "posId": 2},
{"id": 3, "name": "바코드3", "posId": 3},
{"id": 4, "name": "바코드4", "posId": 4}
]
, pathRepo: [ // restrict 0 : 양방향 가능; 1: A to B; 2: B to A; 3 어느 쪽도 불가
, pathRepo: [
new Path(1, "test", 2, 3, 0),
new Path(2, "test", 3, 4, 0),
new Path(3, "test", 4, 5, 0),
new Path(4, "test", 5, 6, 0),
new Path(5, "test", 3, 6, 0),
new Path(6, "test", 2, 5, 0)
]
, findPosByMarkerId: (markerId) => {

//함수부
, findPosByMarkerId: function (markerId) {
const foundMarker = navRepo.markerRepo.find(marker => marker.id === markerId);
if (!foundMarker) return null; // 마커가 없으면 null 반환
return navRepo.posRepo.find(pos => pos.id === foundMarker.posId);
}
, findPosById: function (Id) {
return navRepo.posRepo.find(pos => pos.id === Id);
}
, pathfinding: function (startPosId, endPosId) {
const graph = new DijkstraGraph();
this.posRepo.forEach(pos => {
Expand All @@ -84,7 +86,38 @@ const navRepo = {
});
return graph.pathfinding(startPosId, endPosId)
// return this.routeToPath(route);

}
, empty: function () {
this.posRepo = []
this.markerRepo = []
this.pathRepo = []
}
, pushPos: function (name, x, y, z) {
const id = this.posRepo.length + 1
const pos = {
"id": id
, "name": `${name}`
, "x": x
, "y": y
, "z": z
}
this.posRepo.push(pos)
return id;
}
, pushPath: function (name, posA, posB) {
// if (typeof posA == "number"){
// posA = this.findPosById(posA);
// }
// if (typeof posB == "number"){
// posB = this.findPosById(posB);
// }
// if (posA === posB) {
// return;
// }
const id = this.pathRepo.length + 1
const path = new Path(id, `${name}`, posA, posB, 0);
this.pathRepo.push(path);
return path;
}
// , routeToPath: function (route) {
// const path = []
Expand Down
74 changes: 48 additions & 26 deletions data/pathfinding.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,62 @@
const findShortestPath = (function() {
return function(startPosId, endPosId) {
// const canvas = document.getElementById("canvasView");
// const ctx = canvas.getContext("2d"); 필요.
// const canvasPostprocessing
// 클로저 어느 쪽 방식으로 할까

const clearCanvas = function (canvas) {
console.log(canvas)
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (typeof canvasPostprocessing !== 'undefined') {
canvasPostprocessing(canvas);
console.log(canvasPostprocessing)
}
}

const findShortestPath = (function () {
return function (startPosId, endPosId) {
return navRepo.pathfinding(startPosId, endPosId);
};
})();

const drawShortestPath = (function() {
return function(startPosId, endPosId) {
const drawShortestPath = (function () {
return function (startPosId, endPosId) {
const path = findShortestPath(startPosId, endPosId);
if (path.length === 0) {
return false;
}

ctx.clearRect(0, 0, canvas.width, canvas.height);
drawRouteAnimated(path, "red", 3, 2000);
return true;
};
})();

const drawAllRoutes = (function() {
return function() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
navRepo.pathRepo.forEach(function(route) {
const drawAllRoutes = (function () {
return function () {
clearCanvas(canvas);
navRepo.pathRepo.forEach(function (route) {
drawRoute([route.posA, route.posB], "black", 1);
});
};
})();

const toCoordinate = (function() {
return function(posId) {
const position = navRepo.posRepo.find(function(pos) {
return pos.id === posId;
});
return position ? { x: position.x * 50 + 400, y: position.y * 50 + 300 } : null;
const toCoordinate = (function () {
return function (posId) {
const position = navRepo.posRepo.find(pos => pos.id === posId)
let offsetX = 0;
let offsetY = 0;
if (canvas.dataset.offsetX) {
offsetX = canvas.dataset.offsetX;
}
if (canvas.dataset.offsetY) {
offsetY = canvas.dataset.offsetY;
}
return position ? {x: position.x + offsetX, y: position.y + offsetY} : null;
};
})();

const drawRoute = (function() {
return function(path, color, width) {
const drawRoute = (function () {
return function (path, color, width) {
ctx.strokeStyle = color;
ctx.lineWidth = width;

Expand All @@ -53,8 +73,8 @@ const drawRoute = (function() {
};
})();

const drawPartialRoute = (function() {
return function(startPos, endPos, color, width, partialLength) {
const drawPartialRoute = (function () {
return function (startPos, endPos, color, width, partialLength) {
const segmentLength = Math.sqrt((endPos.x - startPos.x) ** 2 + (endPos.y - startPos.y) ** 2);
const ratio = partialLength / segmentLength;
const partialEndX = startPos.x + (endPos.x - startPos.x) * ratio;
Expand All @@ -68,17 +88,19 @@ const drawPartialRoute = (function() {
};
})();

const drawRouteAnimated = (function() {
return function(path, color, width, duration) {
const drawRouteAnimated = (function () {
return function (path, color, width, duration) {
let startTime = null;
const totalLength = calcLength(path);
const animateDraw = function(currentTime) {
const animateDraw = function (currentTime) {
if (!startTime) startTime = currentTime;
let progress = Math.min(1, (currentTime - startTime) / duration);
const partialLength = progress * totalLength;

ctx.clearRect(0, 0, canvas.width, canvas.height);
drawAllRoutes();
clearCanvas(canvas);
if (!canvas.dataset.noAllRoutes) {
drawAllRoutes();
}
let remainingLength = partialLength;
for (let i = 0; i < path.length - 1; i++) {
const startPos = toCoordinate(path[i]);
Expand All @@ -105,8 +127,8 @@ const drawRouteAnimated = (function() {
};
})();

const calcLength = (function() {
return function(path) {
const calcLength = (function () {
return function (path) {
let totalLength = 0;
for (let i = 0; i < path.length - 1; i++) {
const startPos = toCoordinate(path[i]);
Expand Down
126 changes: 126 additions & 0 deletions data/repository/cruise2DRepo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//2d 데모 하나 더 만들 일 생기면 이것도 간단히 쓸 수 있게 인터페이스화 하자.
const cruise2DPos = function () {
//PoI
const P1 = navRepo.pushPos("북측 계단", 164, 414, 0)
const P2 = navRepo.pushPos("삼사라 스파", 140, 500, 0)
const P3 = navRepo.pushPos("비너스 뷰티 살롱", 256, 561, 0)
const P4 = navRepo.pushPos("좌현 객실", 93, 725, 0)
const P5 = navRepo.pushPos("우현 객실", 232, 725, 0)
const P6 = navRepo.pushPos("아이리스 데크", 162, 937, 0)
const P7 = navRepo.pushPos("중앙 좌현 북측 계단", 75, 1380, 0)
const P8 = navRepo.pushPos("중앙 우현 북측 계단", 250, 1380, 0)
const P9 = navRepo.pushPos("중앙 좌현 남측 계단", 75, 1640, 0)
const P10 = navRepo.pushPos("중앙 우현 남측 계단", 250, 1640, 0)
const P11 = navRepo.pushPos("남측 계단", 163, 1875, 0)
const P12 = navRepo.pushPos("클럽 바코", 225, 1865, 0)
const P13 = navRepo.pushPos("스쿽 도크", 163, 1425, 0)

//relay
const R1 = navRepo.pushPos("R1: R2, P1, P2", 165, 490, 0)
const R2 = navRepo.pushPos("R2: R1, R3", 170, 563, 0)
const R3 = navRepo.pushPos("R3: R2, R4, R5", 173, 593, 0)
const R4 = navRepo.pushPos("R4: R3, R8", 168, 650, 0)
const R5 = navRepo.pushPos("R5: R3, R18, P3", 211, 600, 0)
const R6 = navRepo.pushPos("R6: R3, R7, P2", 110, 560, 0)
const R7 = navRepo.pushPos("R7: R6, R8, R12", 110, 690, 0)
const R8 = navRepo.pushPos("R8: R4, R7, R9, R12, R14, R18", 162, 694, 0)
const R9 = navRepo.pushPos("R9: R8, R10, R11, R13, R15", 162, 784, 0)
const R10 = navRepo.pushPos("R10: R9, R13, R16", 113, 790, 0)
const R11 = navRepo.pushPos("R11: R9, R15, R17", 212, 790, 0)
const R12 = navRepo.pushPos("R12: R7, R8, R13, P4", 95, 695, 0)
const R13 = navRepo.pushPos("R13: R9, R10, R12, P4", 95, 782, 0)
const R14 = navRepo.pushPos("R14: R8, R15, R18, P5", 230, 695, 0)
const R15 = navRepo.pushPos("R15: R9, R11, R14, P5", 230, 782, 0)
const R16 = navRepo.pushPos("R16: R10, R19, P6", 113, 870, 0)
const R17 = navRepo.pushPos("R17: R11, R20, P6", 212, 870, 0)
const R18 = navRepo.pushPos("R18: R5, R8, R14", 215, 690, 0) // 비너스 뷰티살롱 앞
const R19 = navRepo.pushPos("R19: R16, R20, R21, P6", 60, 1015, 0)
const R20 = navRepo.pushPos("R20: R17, R19, P22, P6", 260, 1015, 0)
const R21 = navRepo.pushPos("R21: R19, R23, P7", 75, 1320, 0)
const R22 = navRepo.pushPos("R22: R20, R24, P8", 250, 1320, 0)
const R23 = navRepo.pushPos("R23: R21, R25, P7, P13", 75, 1425, 0)
const R24 = navRepo.pushPos("R24: R22, R26, P8, P13", 250, 1425, 0)
const R25 = navRepo.pushPos("R25: R23, R27, P9", 75, 1645, 0)
const R26 = navRepo.pushPos("R26: R24, R28, P10", 250, 1645, 0)
const R27 = navRepo.pushPos("R27: R25, R29, P9", 55, 1670, 0)
const R28 = navRepo.pushPos("R28: R26, R30, P10", 270, 1670, 0)
const R29 = navRepo.pushPos("R29: R27, R31", 55, 1920, 0)
const R30 = navRepo.pushPos("R30: R28, R32", 270, 1920, 0)
const R31 = navRepo.pushPos("R31: R28, R32", 100, 1960, 0)
const R32 = navRepo.pushPos("R32: R28, R33", 230, 1960, 0)
const R33 = navRepo.pushPos("R33: R31, R32, R34", 163, 1960, 0)
const R34 = navRepo.pushPos("R34: R33, P11", 163, 1905, 0)
const R35 = navRepo.pushPos("R35: P11, P12", 190, 1872, 0)

//path
navRepo.pushPath("R1R2", R1, R2)
navRepo.pushPath("R1P1", R1, P1)
navRepo.pushPath("R1P2", R1, P2)
navRepo.pushPath("R2R3", R2, R3)
navRepo.pushPath("R3R4", R3, R4)
navRepo.pushPath("R3R5", R3, R5)
navRepo.pushPath("R4R8", R4, R8)
navRepo.pushPath("R5P3", R5, P3)
navRepo.pushPath("R5R18", R5, R18)
navRepo.pushPath("R6P3", R6, P2)
navRepo.pushPath("R6R7", R6, R7)
navRepo.pushPath("R7R8", R7, R8)
navRepo.pushPath("R7R12", R7, R12)
navRepo.pushPath("R8R9", R8, R9)
navRepo.pushPath("R8R12", R8, R12)
navRepo.pushPath("R8R14", R8, R14)
navRepo.pushPath("R8R18", R8, R18)
navRepo.pushPath("R9R10", R9, R10)
navRepo.pushPath("R9R11", R9, R11)
navRepo.pushPath("R9R13", R9, R13)
navRepo.pushPath("R9R15", R9, R15)
navRepo.pushPath("R10R13", R10, R13)
navRepo.pushPath("R10R16", R10, R16)
navRepo.pushPath("R11R15", R11, R15)
navRepo.pushPath("R11R17", R11, R17)
navRepo.pushPath("R12R13", R12, R13)
navRepo.pushPath("R12P4", R12, P4)
navRepo.pushPath("R13P4", R13, P4)
navRepo.pushPath("R14R15", R14, R15)
navRepo.pushPath("R14R18", R14, R18)
navRepo.pushPath("R14P5", R14, P5)
navRepo.pushPath("R15P5", R15, P5)
navRepo.pushPath("R16R19", R16, R19)
navRepo.pushPath("R16P6", R16, P6)
navRepo.pushPath("R17R20", R17, R20)
navRepo.pushPath("R17P6", R17, P6)
navRepo.pushPath("R19R20", R19, R20)
navRepo.pushPath("R19R21", R19, R21)
navRepo.pushPath("R19P6", R19, P6)
navRepo.pushPath("R20R22", R20, R22)
navRepo.pushPath("R20P6", R20, P6)
navRepo.pushPath("R21R23", R21, R23)
navRepo.pushPath("R21P7", R21, P7)
navRepo.pushPath("R22R24", R22, R24)
navRepo.pushPath("R22P8", R22, P8)
navRepo.pushPath("R23R25", R23, R25)
navRepo.pushPath("R23P7", R23, P7)
navRepo.pushPath("R23P13", R23, P13)
navRepo.pushPath("R24R26", R24, R26)
navRepo.pushPath("R24P8", R24, P8)
navRepo.pushPath("R24P13", R24, P13)
navRepo.pushPath("R25R27", R25, R27)
navRepo.pushPath("R25P9", R25, P9)
navRepo.pushPath("R26R27", R26, R28)
navRepo.pushPath("R26P10", R26, P10)
navRepo.pushPath("R27R29", R27, R29)
navRepo.pushPath("R27P9", R27, P9)
navRepo.pushPath("R28R30", R28, R30)
navRepo.pushPath("R28P10", R28, P10)
navRepo.pushPath("R29R31", R29, R31)
navRepo.pushPath("R30R32", R30, R32)
navRepo.pushPath("R31R32", R31, R32)
navRepo.pushPath("R32R33", R32, R33)
navRepo.pushPath("R33R34", R33, R34)
navRepo.pushPath("R34P11", R34, P11)
navRepo.pushPath("R35P11", R35, P11)
navRepo.pushPath("R35P12", R35, P12)


const poi = [P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13]
}
Loading

0 comments on commit 5992c8c

Please sign in to comment.